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