char_utils.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**************************************************************************/
  2. /* char_utils.hpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. static _FORCE_INLINE_ bool is_ascii_upper_case(char32_t c) {
  32. return (c >= 'A' && c <= 'Z');
  33. }
  34. static _FORCE_INLINE_ bool is_ascii_lower_case(char32_t c) {
  35. return (c >= 'a' && c <= 'z');
  36. }
  37. static _FORCE_INLINE_ bool is_digit(char32_t c) {
  38. return (c >= '0' && c <= '9');
  39. }
  40. static _FORCE_INLINE_ bool is_hex_digit(char32_t c) {
  41. return (is_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
  42. }
  43. static _FORCE_INLINE_ bool is_binary_digit(char32_t c) {
  44. return (c == '0' || c == '1');
  45. }
  46. static _FORCE_INLINE_ bool is_ascii_char(char32_t c) {
  47. return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
  48. }
  49. static _FORCE_INLINE_ bool is_ascii_alphanumeric_char(char32_t c) {
  50. return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
  51. }
  52. static _FORCE_INLINE_ bool is_ascii_identifier_char(char32_t c) {
  53. return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
  54. }
  55. static _FORCE_INLINE_ bool is_symbol(char32_t c) {
  56. return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' ');
  57. }
  58. static _FORCE_INLINE_ bool is_control(char32_t p_char) {
  59. return (p_char <= 0x001f) || (p_char >= 0x007f && p_char <= 0x009f);
  60. }
  61. static _FORCE_INLINE_ bool is_whitespace(char32_t p_char) {
  62. return (p_char == ' ') || (p_char == 0x00a0) || (p_char == 0x1680) || (p_char >= 0x2000 && p_char <= 0x200a) || (p_char == 0x202f) || (p_char == 0x205f) || (p_char == 0x3000) || (p_char == 0x2028) || (p_char == 0x2029) || (p_char >= 0x0009 && p_char <= 0x000d) || (p_char == 0x0085);
  63. }
  64. static _FORCE_INLINE_ bool is_linebreak(char32_t p_char) {
  65. return (p_char >= 0x000a && p_char <= 0x000d) || (p_char == 0x0085) || (p_char == 0x2028) || (p_char == 0x2029);
  66. }
  67. static _FORCE_INLINE_ bool is_punct(char32_t p_char) {
  68. return (p_char >= ' ' && p_char <= '/') || (p_char >= ':' && p_char <= '@') || (p_char >= '[' && p_char <= '^') || (p_char == '`') || (p_char >= '{' && p_char <= '~') || (p_char >= 0x2000 && p_char <= 0x206f) || (p_char >= 0x3000 && p_char <= 0x303f);
  69. }
  70. static _FORCE_INLINE_ bool is_underscore(char32_t p_char) {
  71. return (p_char == '_');
  72. }