char_utils.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**************************************************************************/
  2. /* char_utils.h */
  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. #ifndef CHAR_UTILS_H
  31. #define CHAR_UTILS_H
  32. #include "core/typedefs.h"
  33. #include "char_range.inc"
  34. static _FORCE_INLINE_ bool is_unicode_identifier_start(char32_t c) {
  35. for (int i = 0; xid_start[i].start != 0; i++) {
  36. if (c >= xid_start[i].start && c <= xid_start[i].end) {
  37. return true;
  38. }
  39. }
  40. return false;
  41. }
  42. static _FORCE_INLINE_ bool is_unicode_identifier_continue(char32_t c) {
  43. for (int i = 0; xid_continue[i].start != 0; i++) {
  44. if (c >= xid_continue[i].start && c <= xid_continue[i].end) {
  45. return true;
  46. }
  47. }
  48. return false;
  49. }
  50. static _FORCE_INLINE_ bool is_ascii_upper_case(char32_t c) {
  51. return (c >= 'A' && c <= 'Z');
  52. }
  53. static _FORCE_INLINE_ bool is_ascii_lower_case(char32_t c) {
  54. return (c >= 'a' && c <= 'z');
  55. }
  56. static _FORCE_INLINE_ bool is_digit(char32_t c) {
  57. return (c >= '0' && c <= '9');
  58. }
  59. static _FORCE_INLINE_ bool is_hex_digit(char32_t c) {
  60. return (is_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
  61. }
  62. static _FORCE_INLINE_ bool is_binary_digit(char32_t c) {
  63. return (c == '0' || c == '1');
  64. }
  65. static _FORCE_INLINE_ bool is_ascii_char(char32_t c) {
  66. return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
  67. }
  68. static _FORCE_INLINE_ bool is_ascii_alphanumeric_char(char32_t c) {
  69. return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
  70. }
  71. static _FORCE_INLINE_ bool is_ascii_identifier_char(char32_t c) {
  72. return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
  73. }
  74. static _FORCE_INLINE_ bool is_symbol(char32_t c) {
  75. return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' ');
  76. }
  77. static _FORCE_INLINE_ bool is_control(char32_t p_char) {
  78. return (p_char <= 0x001f) || (p_char >= 0x007f && p_char <= 0x009f);
  79. }
  80. static _FORCE_INLINE_ bool is_whitespace(char32_t p_char) {
  81. 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);
  82. }
  83. static _FORCE_INLINE_ bool is_linebreak(char32_t p_char) {
  84. return (p_char >= 0x000a && p_char <= 0x000d) || (p_char == 0x0085) || (p_char == 0x2028) || (p_char == 0x2029);
  85. }
  86. static _FORCE_INLINE_ bool is_punct(char32_t p_char) {
  87. 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);
  88. }
  89. static _FORCE_INLINE_ bool is_underscore(char32_t p_char) {
  90. return (p_char == '_');
  91. }
  92. #endif // CHAR_UTILS_H