Cleanup and move char functions to the `char_utils.h` header.
This commit is contained in:
parent
2a3c4f00c8
commit
244db37508
|
@ -614,7 +614,7 @@ PackedByteArray HTTPClientTCP::read_response_body_chunk() {
|
|||
for (int i = 0; i < chunk.size() - 2; i++) {
|
||||
char c = chunk[i];
|
||||
int v = 0;
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
v = c - '0';
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
v = c - 'a' + 10;
|
||||
|
|
|
@ -2056,7 +2056,7 @@ void Image::create(const char **p_xpm) {
|
|||
for (int i = 0; i < 6; i++) {
|
||||
char v = line_ptr[i];
|
||||
|
||||
if (v >= '0' && v <= '9') {
|
||||
if (is_digit(v)) {
|
||||
v -= '0';
|
||||
} else if (v >= 'A' && v <= 'F') {
|
||||
v = (v - 'A') + 10;
|
||||
|
|
|
@ -71,7 +71,7 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) {
|
|||
|
||||
int n = 0;
|
||||
char32_t c = p_string[i];
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
n = c - '0';
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
n = 10 + (c - 'a');
|
||||
|
@ -113,7 +113,7 @@ void IPAddress::_parse_ipv6(const String &p_string) {
|
|||
} else if (c == '.') {
|
||||
part_ipv4 = true;
|
||||
|
||||
} else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
|
||||
} else if (is_hex_digit(c)) {
|
||||
if (!part_found) {
|
||||
parts[parts_idx++] = i;
|
||||
part_found = true;
|
||||
|
|
|
@ -229,12 +229,12 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
|
|||
r_err_str = "Unterminated String";
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
|
||||
if (!is_hex_digit(c)) {
|
||||
r_err_str = "Malformed hex constant in string";
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
char32_t v;
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
v = c - '0';
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
v = c - 'a';
|
||||
|
@ -265,12 +265,12 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
|
|||
r_err_str = "Unterminated String";
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
|
||||
if (!is_hex_digit(c)) {
|
||||
r_err_str = "Malformed hex constant in string";
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
char32_t v;
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
v = c - '0';
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
v = c - 'a';
|
||||
|
@ -326,7 +326,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
|
|||
break;
|
||||
}
|
||||
|
||||
if (p_str[index] == '-' || (p_str[index] >= '0' && p_str[index] <= '9')) {
|
||||
if (p_str[index] == '-' || is_digit(p_str[index])) {
|
||||
//a number
|
||||
const char32_t *rptr;
|
||||
double number = String::to_float(&p_str[index], &rptr);
|
||||
|
@ -335,10 +335,10 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
|
|||
r_token.value = number;
|
||||
return OK;
|
||||
|
||||
} else if ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) {
|
||||
} else if (is_ascii_char(p_str[index])) {
|
||||
String id;
|
||||
|
||||
while ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) {
|
||||
while (is_ascii_char(p_str[index])) {
|
||||
id += p_str[index];
|
||||
index++;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment, const String &
|
|||
int v = 0;
|
||||
if (i * 2 < _key.length()) {
|
||||
char32_t ct = _key[i * 2];
|
||||
if (ct >= '0' && ct <= '9') {
|
||||
if (is_digit(ct)) {
|
||||
ct = ct - '0';
|
||||
} else if (ct >= 'a' && ct <= 'f') {
|
||||
ct = 10 + ct - 'a';
|
||||
|
@ -72,7 +72,7 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment, const String &
|
|||
|
||||
if (i * 2 + 1 < _key.length()) {
|
||||
char32_t ct = _key[i * 2 + 1];
|
||||
if (ct >= '0' && ct <= '9') {
|
||||
if (is_digit(ct)) {
|
||||
ct = ct - '0';
|
||||
} else if (ct >= 'a' && ct <= 'f') {
|
||||
ct = 10 + ct - 'a';
|
||||
|
|
|
@ -71,9 +71,9 @@ ResourceUID::ID ResourceUID::text_to_id(const String &p_text) const {
|
|||
for (uint32_t i = 6; i < l; i++) {
|
||||
uid *= base;
|
||||
uint32_t c = p_text[i];
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
if (is_ascii_lower_case(c)) {
|
||||
uid += c - 'a';
|
||||
} else if (c >= '0' && c <= '9') {
|
||||
} else if (is_digit(c)) {
|
||||
uid += c - '0' + char_count;
|
||||
} else {
|
||||
return INVALID_ID;
|
||||
|
|
|
@ -37,18 +37,6 @@
|
|||
#include "core/os/os.h"
|
||||
#include "core/variant/variant_parser.h"
|
||||
|
||||
static bool _is_number(char32_t c) {
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
static bool _is_hex_digit(char32_t c) {
|
||||
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
||||
}
|
||||
|
||||
static bool _is_binary_digit(char32_t c) {
|
||||
return (c == '0' || c == '1');
|
||||
}
|
||||
|
||||
Error Expression::_get_token(Token &r_token) {
|
||||
while (true) {
|
||||
#define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++])
|
||||
|
@ -96,7 +84,7 @@ Error Expression::_get_token(Token &r_token) {
|
|||
r_token.type = TK_INPUT;
|
||||
int index = 0;
|
||||
do {
|
||||
if (!_is_number(expression[str_ofs])) {
|
||||
if (!is_digit(expression[str_ofs])) {
|
||||
_set_error("Expected number after '$'");
|
||||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
|
@ -105,7 +93,7 @@ Error Expression::_get_token(Token &r_token) {
|
|||
index += expression[str_ofs] - '0';
|
||||
str_ofs++;
|
||||
|
||||
} while (_is_number(expression[str_ofs]));
|
||||
} while (is_digit(expression[str_ofs]));
|
||||
|
||||
r_token.value = index;
|
||||
return OK;
|
||||
|
@ -255,13 +243,13 @@ Error Expression::_get_token(Token &r_token) {
|
|||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
if (!(_is_number(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
|
||||
if (!is_hex_digit(c)) {
|
||||
_set_error("Malformed hex constant in string");
|
||||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
char32_t v;
|
||||
if (_is_number(c)) {
|
||||
if (is_digit(c)) {
|
||||
v = c - '0';
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
v = c - 'a';
|
||||
|
@ -336,7 +324,7 @@ Error Expression::_get_token(Token &r_token) {
|
|||
}
|
||||
|
||||
char32_t next_char = (str_ofs >= expression.length()) ? 0 : expression[str_ofs];
|
||||
if (_is_number(cchar) || (cchar == '.' && _is_number(next_char))) {
|
||||
if (is_digit(cchar) || (cchar == '.' && is_digit(next_char))) {
|
||||
//a number
|
||||
|
||||
String num;
|
||||
|
@ -360,7 +348,7 @@ Error Expression::_get_token(Token &r_token) {
|
|||
while (true) {
|
||||
switch (reading) {
|
||||
case READING_INT: {
|
||||
if (_is_number(c)) {
|
||||
if (is_digit(c)) {
|
||||
if (is_first_char && c == '0') {
|
||||
if (next_char == 'b') {
|
||||
reading = READING_BIN;
|
||||
|
@ -379,7 +367,7 @@ Error Expression::_get_token(Token &r_token) {
|
|||
|
||||
} break;
|
||||
case READING_BIN: {
|
||||
if (bin_beg && !_is_binary_digit(c)) {
|
||||
if (bin_beg && !is_binary_digit(c)) {
|
||||
reading = READING_DONE;
|
||||
} else if (c == 'b') {
|
||||
bin_beg = true;
|
||||
|
@ -387,7 +375,7 @@ Error Expression::_get_token(Token &r_token) {
|
|||
|
||||
} break;
|
||||
case READING_HEX: {
|
||||
if (hex_beg && !_is_hex_digit(c)) {
|
||||
if (hex_beg && !is_hex_digit(c)) {
|
||||
reading = READING_DONE;
|
||||
} else if (c == 'x') {
|
||||
hex_beg = true;
|
||||
|
@ -395,7 +383,7 @@ Error Expression::_get_token(Token &r_token) {
|
|||
|
||||
} break;
|
||||
case READING_DEC: {
|
||||
if (_is_number(c)) {
|
||||
if (is_digit(c)) {
|
||||
} else if (c == 'e') {
|
||||
reading = READING_EXP;
|
||||
|
||||
|
@ -405,7 +393,7 @@ Error Expression::_get_token(Token &r_token) {
|
|||
|
||||
} break;
|
||||
case READING_EXP: {
|
||||
if (_is_number(c)) {
|
||||
if (is_digit(c)) {
|
||||
exp_beg = true;
|
||||
|
||||
} else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
|
||||
|
@ -443,11 +431,11 @@ Error Expression::_get_token(Token &r_token) {
|
|||
}
|
||||
return OK;
|
||||
|
||||
} else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {
|
||||
} else if (is_ascii_char(cchar) || is_underscore(cchar)) {
|
||||
String id;
|
||||
bool first = true;
|
||||
|
||||
while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && _is_number(cchar))) {
|
||||
while (is_ascii_char(cchar) || is_underscore(cchar) || (!first && is_digit(cchar))) {
|
||||
id += String::chr(cchar);
|
||||
cchar = GET_CHAR();
|
||||
first = false;
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/*************************************************************************/
|
||||
/* char_utils.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef CHAR_UTILS_H
|
||||
#define CHAR_UTILS_H
|
||||
|
||||
#include "core/typedefs.h"
|
||||
|
||||
static _FORCE_INLINE_ bool is_ascii_upper_case(char32_t c) {
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_ascii_lower_case(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_digit(char32_t c) {
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_hex_digit(char32_t c) {
|
||||
return (is_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_binary_digit(char32_t c) {
|
||||
return (c == '0' || c == '1');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_ascii_char(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_ascii_alphanumeric_char(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_ascii_identifier_char(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_symbol(char32_t c) {
|
||||
return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' ');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_control(char32_t p_char) {
|
||||
return (p_char <= 0x001f) || (p_char >= 0x007f && p_char <= 0x009f);
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_whitespace(char32_t p_char) {
|
||||
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);
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_linebreak(char32_t p_char) {
|
||||
return (p_char >= 0x000a && p_char <= 0x000d) || (p_char == 0x0085) || (p_char == 0x2028) || (p_char == 0x2029);
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_punct(char32_t p_char) {
|
||||
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);
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_underscore(char32_t p_char) {
|
||||
return (p_char == '_');
|
||||
}
|
||||
|
||||
#endif // CHAR_UTILS_H
|
|
@ -213,14 +213,6 @@ static _character_accent_pair _character_to_accented[] = {
|
|||
{ 'z', U"ź" },
|
||||
};
|
||||
|
||||
static _FORCE_INLINE_ bool is_upper_case(char32_t c) {
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_lower_case(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z');
|
||||
}
|
||||
|
||||
Vector<TranslationServer::LocaleScriptInfo> TranslationServer::locale_script_info;
|
||||
|
||||
Map<String, String> TranslationServer::language_map;
|
||||
|
@ -309,15 +301,15 @@ String TranslationServer::standardize_locale(const String &p_locale) const {
|
|||
Vector<String> locale_elements = univ_locale.get_slice("@", 0).split("_");
|
||||
lang = locale_elements[0];
|
||||
if (locale_elements.size() >= 2) {
|
||||
if (locale_elements[1].length() == 4 && is_upper_case(locale_elements[1][0]) && is_lower_case(locale_elements[1][1]) && is_lower_case(locale_elements[1][2]) && is_lower_case(locale_elements[1][3])) {
|
||||
if (locale_elements[1].length() == 4 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_lower_case(locale_elements[1][1]) && is_ascii_lower_case(locale_elements[1][2]) && is_ascii_lower_case(locale_elements[1][3])) {
|
||||
script = locale_elements[1];
|
||||
}
|
||||
if (locale_elements[1].length() == 2 && is_upper_case(locale_elements[1][0]) && is_upper_case(locale_elements[1][1])) {
|
||||
if (locale_elements[1].length() == 2 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_upper_case(locale_elements[1][1])) {
|
||||
country = locale_elements[1];
|
||||
}
|
||||
}
|
||||
if (locale_elements.size() >= 3) {
|
||||
if (locale_elements[2].length() == 2 && is_upper_case(locale_elements[2][0]) && is_upper_case(locale_elements[2][1])) {
|
||||
if (locale_elements[2].length() == 2 && is_ascii_upper_case(locale_elements[2][0]) && is_ascii_upper_case(locale_elements[2][1])) {
|
||||
country = locale_elements[2];
|
||||
} else if (variant_map.has(locale_elements[2].to_lower()) && variant_map[locale_elements[2].to_lower()] == lang) {
|
||||
variant = locale_elements[2].to_lower();
|
||||
|
@ -434,15 +426,15 @@ String TranslationServer::get_locale_name(const String &p_locale) const {
|
|||
Vector<String> locale_elements = locale.split("_");
|
||||
lang = locale_elements[0];
|
||||
if (locale_elements.size() >= 2) {
|
||||
if (locale_elements[1].length() == 4 && is_upper_case(locale_elements[1][0]) && is_lower_case(locale_elements[1][1]) && is_lower_case(locale_elements[1][2]) && is_lower_case(locale_elements[1][3])) {
|
||||
if (locale_elements[1].length() == 4 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_lower_case(locale_elements[1][1]) && is_ascii_lower_case(locale_elements[1][2]) && is_ascii_lower_case(locale_elements[1][3])) {
|
||||
script = locale_elements[1];
|
||||
}
|
||||
if (locale_elements[1].length() == 2 && is_upper_case(locale_elements[1][0]) && is_upper_case(locale_elements[1][1])) {
|
||||
if (locale_elements[1].length() == 2 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_upper_case(locale_elements[1][1])) {
|
||||
country = locale_elements[1];
|
||||
}
|
||||
}
|
||||
if (locale_elements.size() >= 3) {
|
||||
if (locale_elements[2].length() == 2 && is_upper_case(locale_elements[2][0]) && is_upper_case(locale_elements[2][1])) {
|
||||
if (locale_elements[2].length() == 2 && is_ascii_upper_case(locale_elements[2][0]) && is_ascii_upper_case(locale_elements[2][1])) {
|
||||
country = locale_elements[2];
|
||||
}
|
||||
}
|
||||
|
@ -911,7 +903,7 @@ String TranslationServer::add_padding(String &p_message, int p_length) const {
|
|||
}
|
||||
|
||||
const char32_t *TranslationServer::get_accented_version(char32_t p_character) const {
|
||||
if (!((p_character >= 'a' && p_character <= 'z') || (p_character >= 'A' && p_character <= 'Z'))) {
|
||||
if (!is_ascii_char(p_character)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,34 +54,14 @@
|
|||
|
||||
static const int MAX_DECIMALS = 32;
|
||||
|
||||
static _FORCE_INLINE_ bool is_digit(char32_t c) {
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_hex_digit(char32_t c) {
|
||||
return (is_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_upper_case(char32_t c) {
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_lower_case(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ char32_t lower_case(char32_t c) {
|
||||
return (is_upper_case(c) ? (c + ('a' - 'A')) : c);
|
||||
return (is_ascii_upper_case(c) ? (c + ('a' - 'A')) : c);
|
||||
}
|
||||
|
||||
const char CharString::_null = 0;
|
||||
const char16_t Char16String::_null = 0;
|
||||
const char32_t String::_null = 0;
|
||||
|
||||
bool is_symbol(char32_t c) {
|
||||
return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' ');
|
||||
}
|
||||
|
||||
bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) {
|
||||
const String &s = p_s;
|
||||
int beg = CLAMP(p_col, 0, s.length());
|
||||
|
@ -974,21 +954,21 @@ String String::camelcase_to_underscore(bool lowercase) const {
|
|||
int start_index = 0;
|
||||
|
||||
for (int i = 1; i < this->size(); i++) {
|
||||
bool is_upper = is_upper_case(cstr[i]);
|
||||
bool is_upper = is_ascii_upper_case(cstr[i]);
|
||||
bool is_number = is_digit(cstr[i]);
|
||||
|
||||
bool are_next_2_lower = false;
|
||||
bool is_next_lower = false;
|
||||
bool is_next_number = false;
|
||||
bool was_precedent_upper = is_upper_case(cstr[i - 1]);
|
||||
bool was_precedent_upper = is_ascii_upper_case(cstr[i - 1]);
|
||||
bool was_precedent_number = is_digit(cstr[i - 1]);
|
||||
|
||||
if (i + 2 < this->size()) {
|
||||
are_next_2_lower = is_lower_case(cstr[i + 1]) && is_lower_case(cstr[i + 2]);
|
||||
are_next_2_lower = is_ascii_lower_case(cstr[i + 1]) && is_ascii_lower_case(cstr[i + 2]);
|
||||
}
|
||||
|
||||
if (i + 1 < this->size()) {
|
||||
is_next_lower = is_lower_case(cstr[i + 1]);
|
||||
is_next_lower = is_ascii_lower_case(cstr[i + 1]);
|
||||
is_next_number = is_digit(cstr[i + 1]);
|
||||
}
|
||||
|
||||
|
@ -2212,7 +2192,7 @@ bool String::is_numeric() const {
|
|||
return false;
|
||||
}
|
||||
dot = true;
|
||||
} else if (c < '0' || c > '9') {
|
||||
} else if (!is_digit(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -3691,7 +3671,7 @@ bool String::is_valid_identifier() const {
|
|||
}
|
||||
}
|
||||
|
||||
bool valid_char = is_digit(str[i]) || is_lower_case(str[i]) || is_upper_case(str[i]) || str[i] == '_';
|
||||
bool valid_char = is_ascii_identifier_char(str[i]);
|
||||
|
||||
if (!valid_char) {
|
||||
return false;
|
||||
|
@ -3716,7 +3696,7 @@ String String::uri_encode() const {
|
|||
String res;
|
||||
for (int i = 0; i < temp.length(); ++i) {
|
||||
char ord = temp[i];
|
||||
if (ord == '.' || ord == '-' || ord == '_' || ord == '~' || is_lower_case(ord) || is_upper_case(ord) || is_digit(ord)) {
|
||||
if (ord == '.' || ord == '-' || ord == '~' || is_ascii_identifier_char(ord)) {
|
||||
res += ord;
|
||||
} else {
|
||||
char h_Val[3];
|
||||
|
@ -3738,9 +3718,9 @@ String String::uri_decode() const {
|
|||
for (int i = 0; i < src.length(); ++i) {
|
||||
if (src[i] == '%' && i + 2 < src.length()) {
|
||||
char ord1 = src[i + 1];
|
||||
if (is_digit(ord1) || is_upper_case(ord1)) {
|
||||
if (is_digit(ord1) || is_ascii_upper_case(ord1)) {
|
||||
char ord2 = src[i + 2];
|
||||
if (is_digit(ord2) || is_upper_case(ord2)) {
|
||||
if (is_digit(ord2) || is_ascii_upper_case(ord2)) {
|
||||
char bytes[3] = { (char)ord1, (char)ord2, 0 };
|
||||
res += (char)strtol(bytes, nullptr, 16);
|
||||
i += 2;
|
||||
|
@ -3867,7 +3847,7 @@ static _FORCE_INLINE_ int _xml_unescape(const char32_t *p_src, int p_src_len, ch
|
|||
for (int i = 2; i < p_src_len; i++) {
|
||||
eat = i + 1;
|
||||
char32_t ct = p_src[i];
|
||||
if (ct == ';' || ct < '0' || ct > '9') {
|
||||
if (ct == ';' || !is_digit(ct)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3997,7 +3977,7 @@ String String::pad_zeros(int p_digits) const {
|
|||
|
||||
int begin = 0;
|
||||
|
||||
while (begin < end && (s[begin] < '0' || s[begin] > '9')) {
|
||||
while (begin < end && !is_digit(s[begin])) {
|
||||
begin++;
|
||||
}
|
||||
|
||||
|
@ -4042,7 +4022,7 @@ bool String::is_valid_int() const {
|
|||
}
|
||||
|
||||
for (int i = from; i < len; i++) {
|
||||
if (operator[](i) < '0' || operator[](i) > '9') {
|
||||
if (!is_digit(operator[](i))) {
|
||||
return false; // no start with number plz
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#define USTRING_GODOT_H
|
||||
// Note: Renamed to avoid conflict with ICU header with the same name.
|
||||
|
||||
#include "core/string/char_utils.h"
|
||||
#include "core/templates/cowdata.h"
|
||||
#include "core/templates/vector.h"
|
||||
#include "core/typedefs.h"
|
||||
|
@ -533,7 +534,6 @@ String DTRN(const String &p_text, const String &p_text_plural, int p_n, const St
|
|||
String RTR(const String &p_text, const String &p_context = "");
|
||||
String RTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context = "");
|
||||
|
||||
bool is_symbol(char32_t c);
|
||||
bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end);
|
||||
|
||||
_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr) {
|
||||
|
|
|
@ -188,7 +188,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
if (p_stream->is_eof()) {
|
||||
r_token.type = TK_EOF;
|
||||
return OK;
|
||||
} else if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) {
|
||||
} else if (is_hex_digit(ch)) {
|
||||
color_str += ch;
|
||||
|
||||
} else {
|
||||
|
@ -265,13 +265,13 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
|
||||
if (!is_hex_digit(c)) {
|
||||
r_err_str = "Malformed hex constant in string";
|
||||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
char32_t v;
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
v = c - '0';
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
v = c - 'a';
|
||||
|
@ -381,7 +381,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
while (true) {
|
||||
switch (reading) {
|
||||
case READING_INT: {
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
//pass
|
||||
} else if (c == '.') {
|
||||
reading = READING_DEC;
|
||||
|
@ -395,7 +395,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
|
||||
} break;
|
||||
case READING_DEC: {
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
} else if (c == 'e') {
|
||||
reading = READING_EXP;
|
||||
} else {
|
||||
|
@ -404,7 +404,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
|
||||
} break;
|
||||
case READING_EXP: {
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
exp_beg = true;
|
||||
|
||||
} else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
|
||||
|
@ -433,11 +433,11 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
r_token.value = num.as_int();
|
||||
}
|
||||
return OK;
|
||||
} else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {
|
||||
} else if (is_ascii_char(cchar) || is_underscore(cchar)) {
|
||||
StringBuffer<> id;
|
||||
bool first = true;
|
||||
|
||||
while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) {
|
||||
while (is_ascii_char(cchar) || is_underscore(cchar) || (!first && is_digit(cchar))) {
|
||||
id += cchar;
|
||||
cchar = p_stream->get_char();
|
||||
first = false;
|
||||
|
|
|
@ -764,7 +764,7 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &p_item) {
|
|||
String node_name = selected_node->get_name();
|
||||
for (int i = 0; i < node_name.length(); i++) { // TODO: Regex filter may be cleaner.
|
||||
char32_t c = node_name[i];
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) {
|
||||
if (!is_ascii_identifier_char(c)) {
|
||||
if (c == ' ') {
|
||||
// Replace spaces with underlines.
|
||||
c = '_';
|
||||
|
|
|
@ -818,7 +818,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
|
|||
int v = 0;
|
||||
if (i * 2 < script_key.length()) {
|
||||
char32_t ct = script_key[i * 2];
|
||||
if (ct >= '0' && ct <= '9') {
|
||||
if (is_digit(ct)) {
|
||||
ct = ct - '0';
|
||||
} else if (ct >= 'a' && ct <= 'f') {
|
||||
ct = 10 + ct - 'a';
|
||||
|
@ -828,7 +828,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
|
|||
|
||||
if (i * 2 + 1 < script_key.length()) {
|
||||
char32_t ct = script_key[i * 2 + 1];
|
||||
if (ct >= '0' && ct <= '9') {
|
||||
if (is_digit(ct)) {
|
||||
ct = ct - '0';
|
||||
} else if (ct >= 'a' && ct <= 'f') {
|
||||
ct = 10 + ct - 'a';
|
||||
|
@ -1215,7 +1215,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c
|
|||
int v = 0;
|
||||
if (i * 2 < script_key.length()) {
|
||||
char32_t ct = script_key[i * 2];
|
||||
if (ct >= '0' && ct <= '9') {
|
||||
if (is_digit(ct)) {
|
||||
ct = ct - '0';
|
||||
} else if (ct >= 'a' && ct <= 'f') {
|
||||
ct = 10 + ct - 'a';
|
||||
|
@ -1225,7 +1225,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c
|
|||
|
||||
if (i * 2 + 1 < script_key.length()) {
|
||||
char32_t ct = script_key[i * 2 + 1];
|
||||
if (ct >= '0' && ct <= '9') {
|
||||
if (is_digit(ct)) {
|
||||
ct = ct - '0';
|
||||
} else if (ct >= 'a' && ct <= 'f') {
|
||||
ct = 10 + ct - 'a';
|
||||
|
|
|
@ -1780,7 +1780,7 @@ Array EditorInspectorArray::_extract_properties_as_array(const List<PropertyInfo
|
|||
|
||||
int to_char_index = 0;
|
||||
while (to_char_index < str.length()) {
|
||||
if (str[to_char_index] < '0' || str[to_char_index] > '9') {
|
||||
if (!is_digit(str[to_char_index])) {
|
||||
break;
|
||||
}
|
||||
to_char_index++;
|
||||
|
@ -2512,7 +2512,7 @@ void EditorInspector::update_tree() {
|
|||
String str = p.name.trim_prefix(array_prefix);
|
||||
int to_char_index = 0;
|
||||
while (to_char_index < str.length()) {
|
||||
if (str[to_char_index] < '0' || str[to_char_index] > '9') {
|
||||
if (!is_digit(str[to_char_index])) {
|
||||
break;
|
||||
}
|
||||
to_char_index++;
|
||||
|
|
|
@ -37,14 +37,6 @@
|
|||
#include "scene/gui/option_button.h"
|
||||
#include "scene/gui/tree.h"
|
||||
|
||||
static _FORCE_INLINE_ bool is_upper_case(char32_t c) {
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_lower_case(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z');
|
||||
}
|
||||
|
||||
void EditorLocaleDialog::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("locale_selected", PropertyInfo(Variant::STRING, "locale")));
|
||||
}
|
||||
|
@ -363,16 +355,16 @@ void EditorLocaleDialog::set_locale(const String &p_locale) {
|
|||
Vector<String> locale_elements = p_locale.split("_");
|
||||
lang_code->set_text(locale_elements[0]);
|
||||
if (locale_elements.size() >= 2) {
|
||||
if (locale_elements[1].length() == 4 && is_upper_case(locale_elements[1][0]) && is_lower_case(locale_elements[1][1]) && is_lower_case(locale_elements[1][2]) && is_lower_case(locale_elements[1][3])) {
|
||||
if (locale_elements[1].length() == 4 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_lower_case(locale_elements[1][1]) && is_ascii_lower_case(locale_elements[1][2]) && is_ascii_lower_case(locale_elements[1][3])) {
|
||||
script_code->set_text(locale_elements[1]);
|
||||
advanced->set_pressed(true);
|
||||
}
|
||||
if (locale_elements[1].length() == 2 && is_upper_case(locale_elements[1][0]) && is_upper_case(locale_elements[1][1])) {
|
||||
if (locale_elements[1].length() == 2 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_upper_case(locale_elements[1][1])) {
|
||||
country_code->set_text(locale_elements[1]);
|
||||
}
|
||||
}
|
||||
if (locale_elements.size() >= 3) {
|
||||
if (locale_elements[2].length() == 2 && is_upper_case(locale_elements[2][0]) && is_upper_case(locale_elements[2][1])) {
|
||||
if (locale_elements[2].length() == 2 && is_ascii_upper_case(locale_elements[2][0]) && is_ascii_upper_case(locale_elements[2][1])) {
|
||||
country_code->set_text(locale_elements[2]);
|
||||
} else {
|
||||
variant_code->set_text(locale_elements[2].to_lower());
|
||||
|
|
|
@ -53,11 +53,6 @@ inline void pop_back(T &container) {
|
|||
container.resize(container.size() - 1);
|
||||
}
|
||||
|
||||
// TODO: Copied from TextEdit private, would be nice to extract it in a single place.
|
||||
static bool is_text_char(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
||||
}
|
||||
|
||||
static bool find_next(const String &line, String pattern, int from, bool match_case, bool whole_words, int &out_begin, int &out_end) {
|
||||
int end = from;
|
||||
|
||||
|
@ -73,10 +68,10 @@ static bool find_next(const String &line, String pattern, int from, bool match_c
|
|||
out_end = end;
|
||||
|
||||
if (whole_words) {
|
||||
if (begin > 0 && is_text_char(line[begin - 1])) {
|
||||
if (begin > 0 && (is_ascii_identifier_char(line[begin - 1]))) {
|
||||
continue;
|
||||
}
|
||||
if (end < line.size() && is_text_char(line[end])) {
|
||||
if (end < line.size() && (is_ascii_identifier_char(line[end]))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -316,7 +316,7 @@ static bool _teststr(const String &p_what, const String &p_str) {
|
|||
String what = p_what;
|
||||
|
||||
//remove trailing spaces and numbers, some apps like blender add ".number" to duplicates so also compensate for this
|
||||
while (what.length() && ((what[what.length() - 1] >= '0' && what[what.length() - 1] <= '9') || what[what.length() - 1] <= 32 || what[what.length() - 1] == '.')) {
|
||||
while (what.length() && (is_digit(what[what.length() - 1]) || what[what.length() - 1] <= 32 || what[what.length() - 1] == '.')) {
|
||||
what = what.substr(0, what.length() - 1);
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,7 @@ static String _fixstr(const String &p_what, const String &p_str) {
|
|||
String what = p_what;
|
||||
|
||||
//remove trailing spaces and numbers, some apps like blender add ".number" to duplicates so also compensate for this
|
||||
while (what.length() && ((what[what.length() - 1] >= '0' && what[what.length() - 1] <= '9') || what[what.length() - 1] <= 32 || what[what.length() - 1] == '.')) {
|
||||
while (what.length() && (is_digit(what[what.length() - 1]) || what[what.length() - 1] <= 32 || what[what.length() - 1] == '.')) {
|
||||
what = what.substr(0, what.length() - 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -462,10 +462,6 @@ EditorMaterialPreviewPlugin::~EditorMaterialPreviewPlugin() {
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool _is_text_char(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
||||
}
|
||||
|
||||
bool EditorScriptPreviewPlugin::handles(const String &p_type) const {
|
||||
return ClassDB::is_parent_class(p_type, "Script");
|
||||
}
|
||||
|
@ -538,15 +534,15 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size
|
|||
if (in_comment) {
|
||||
color = comment_color;
|
||||
} else {
|
||||
if (c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t')) {
|
||||
if (is_symbol(c)) {
|
||||
//make symbol a little visible
|
||||
color = symbol_color;
|
||||
in_control_flow_keyword = false;
|
||||
in_keyword = false;
|
||||
} else if (!prev_is_text && _is_text_char(c)) {
|
||||
} else if (!prev_is_text && is_ascii_identifier_char(c)) {
|
||||
int pos = i;
|
||||
|
||||
while (_is_text_char(code[pos])) {
|
||||
while (is_ascii_identifier_char(code[pos])) {
|
||||
pos++;
|
||||
}
|
||||
String word = code.substr(i, pos - i);
|
||||
|
@ -556,7 +552,7 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size
|
|||
in_keyword = true;
|
||||
}
|
||||
|
||||
} else if (!_is_text_char(c)) {
|
||||
} else if (!is_ascii_identifier_char(c)) {
|
||||
in_keyword = false;
|
||||
}
|
||||
|
||||
|
@ -571,7 +567,7 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size
|
|||
img->set_pixel(col, y0 + line * 2, bg_color.blend(ul));
|
||||
img->set_pixel(col, y0 + line * 2 + 1, color);
|
||||
|
||||
prev_is_text = _is_text_char(c);
|
||||
prev_is_text = is_ascii_identifier_char(c);
|
||||
}
|
||||
col++;
|
||||
} else {
|
||||
|
|
|
@ -3735,7 +3735,7 @@ void TileMapEditor::_move_tile_map_array_element(Object *p_undo_redo, Object *p_
|
|||
String str = pi.name.trim_prefix(p_array_prefix);
|
||||
int to_char_index = 0;
|
||||
while (to_char_index < str.length()) {
|
||||
if (str[to_char_index] < '0' || str[to_char_index] > '9') {
|
||||
if (!is_digit(str[to_char_index])) {
|
||||
break;
|
||||
}
|
||||
to_char_index++;
|
||||
|
|
|
@ -458,7 +458,7 @@ void TileSetEditor::_move_tile_set_array_element(Object *p_undo_redo, Object *p_
|
|||
String str = pi.name.trim_prefix(p_array_prefix);
|
||||
int to_char_index = 0;
|
||||
while (to_char_index < str.length()) {
|
||||
if (str[to_char_index] < '0' || str[to_char_index] > '9') {
|
||||
if (!is_digit(str[to_char_index])) {
|
||||
break;
|
||||
}
|
||||
to_char_index++;
|
||||
|
|
|
@ -153,7 +153,7 @@ bool ScriptCreateDialog::_validate_class(const String &p_string) {
|
|||
}
|
||||
}
|
||||
|
||||
bool valid_char = (p_string[i] >= '0' && p_string[i] <= '9') || (p_string[i] >= 'a' && p_string[i] <= 'z') || (p_string[i] >= 'A' && p_string[i] <= 'Z') || p_string[i] == '_' || p_string[i] == '.';
|
||||
bool valid_char = is_ascii_identifier_char(p_string[i]) || p_string[i] == '.';
|
||||
|
||||
if (!valid_char) {
|
||||
return false;
|
||||
|
|
|
@ -33,18 +33,6 @@
|
|||
#include "../gdscript_tokenizer.h"
|
||||
#include "editor/editor_settings.h"
|
||||
|
||||
static bool _is_char(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
|
||||
}
|
||||
|
||||
static bool _is_hex_symbol(char32_t c) {
|
||||
return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
|
||||
}
|
||||
|
||||
static bool _is_bin_symbol(char32_t c) {
|
||||
return (c == '0' || c == '1');
|
||||
}
|
||||
|
||||
Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
|
||||
Dictionary color_map;
|
||||
|
||||
|
@ -102,7 +90,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||
color = font_color;
|
||||
bool is_char = !is_symbol(str[j]);
|
||||
bool is_a_symbol = is_symbol(str[j]);
|
||||
bool is_number = (str[j] >= '0' && str[j] <= '9');
|
||||
bool is_number = is_digit(str[j]);
|
||||
|
||||
/* color regions */
|
||||
if (is_a_symbol || in_region != -1) {
|
||||
|
@ -241,14 +229,14 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||
}
|
||||
|
||||
// allow ABCDEF in hex notation
|
||||
if (is_hex_notation && (_is_hex_symbol(str[j]) || is_number)) {
|
||||
if (is_hex_notation && (is_hex_digit(str[j]) || is_number)) {
|
||||
is_number = true;
|
||||
} else {
|
||||
is_hex_notation = false;
|
||||
}
|
||||
|
||||
// disallow anything not a 0 or 1
|
||||
if (is_bin_notation && (_is_bin_symbol(str[j]))) {
|
||||
if (is_bin_notation && (is_binary_digit(str[j]))) {
|
||||
is_number = true;
|
||||
} else if (is_bin_notation) {
|
||||
is_bin_notation = false;
|
||||
|
@ -270,7 +258,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||
}
|
||||
}
|
||||
|
||||
if (!in_word && _is_char(str[j]) && !is_number) {
|
||||
if (!in_word && (is_ascii_char(str[j]) || is_underscore(str[j])) && !is_number) {
|
||||
in_word = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -312,22 +312,6 @@ GDScriptTokenizer::Token GDScriptTokenizer::pop_error() {
|
|||
return error;
|
||||
}
|
||||
|
||||
static bool _is_alphanumeric(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
||||
}
|
||||
|
||||
static bool _is_digit(char32_t c) {
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
static bool _is_hex_digit(char32_t c) {
|
||||
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
||||
}
|
||||
|
||||
static bool _is_binary_digit(char32_t c) {
|
||||
return (c == '0' || c == '1');
|
||||
}
|
||||
|
||||
GDScriptTokenizer::Token GDScriptTokenizer::make_token(Token::Type p_type) {
|
||||
Token token(p_type);
|
||||
token.start_line = start_line;
|
||||
|
@ -448,10 +432,10 @@ GDScriptTokenizer::Token GDScriptTokenizer::check_vcs_marker(char32_t p_test, To
|
|||
}
|
||||
|
||||
GDScriptTokenizer::Token GDScriptTokenizer::annotation() {
|
||||
if (!_is_alphanumeric(_peek())) {
|
||||
if (!is_ascii_identifier_char(_peek())) {
|
||||
push_error("Expected annotation identifier after \"@\".");
|
||||
}
|
||||
while (_is_alphanumeric(_peek())) {
|
||||
while (is_ascii_identifier_char(_peek())) {
|
||||
// Consume all identifier characters.
|
||||
_advance();
|
||||
}
|
||||
|
@ -526,7 +510,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::potential_identifier() {
|
|||
#define MAX_KEYWORD_LENGTH 10
|
||||
|
||||
// Consume all alphanumeric characters.
|
||||
while (_is_alphanumeric(_peek())) {
|
||||
while (is_ascii_identifier_char(_peek())) {
|
||||
_advance();
|
||||
}
|
||||
|
||||
|
@ -612,7 +596,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::number() {
|
|||
bool has_decimal = false;
|
||||
bool has_exponent = false;
|
||||
bool has_error = false;
|
||||
bool (*digit_check_func)(char32_t) = _is_digit;
|
||||
bool (*digit_check_func)(char32_t) = is_digit;
|
||||
|
||||
if (_peek(-1) == '.') {
|
||||
has_decimal = true;
|
||||
|
@ -620,20 +604,20 @@ GDScriptTokenizer::Token GDScriptTokenizer::number() {
|
|||
if (_peek() == 'x') {
|
||||
// Hexadecimal.
|
||||
base = 16;
|
||||
digit_check_func = _is_hex_digit;
|
||||
digit_check_func = is_hex_digit;
|
||||
_advance();
|
||||
} else if (_peek() == 'b') {
|
||||
// Binary.
|
||||
base = 2;
|
||||
digit_check_func = _is_binary_digit;
|
||||
digit_check_func = is_binary_digit;
|
||||
_advance();
|
||||
}
|
||||
}
|
||||
|
||||
// Allow '_' to be used in a number, for readability.
|
||||
bool previous_was_underscore = false;
|
||||
while (digit_check_func(_peek()) || _peek() == '_') {
|
||||
if (_peek() == '_') {
|
||||
while (digit_check_func(_peek()) || is_underscore(_peek())) {
|
||||
if (is_underscore(_peek())) {
|
||||
if (previous_was_underscore) {
|
||||
Token error = make_error(R"(Only one underscore can be used as a numeric separator.)");
|
||||
error.start_column = column;
|
||||
|
@ -682,7 +666,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::number() {
|
|||
_advance();
|
||||
|
||||
// Consume decimal digits.
|
||||
while (_is_digit(_peek()) || _peek() == '_') {
|
||||
while (is_digit(_peek()) || is_underscore(_peek())) {
|
||||
_advance();
|
||||
}
|
||||
}
|
||||
|
@ -696,7 +680,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::number() {
|
|||
_advance();
|
||||
}
|
||||
// Consume exponent digits.
|
||||
if (!_is_digit(_peek())) {
|
||||
if (!is_digit(_peek())) {
|
||||
Token error = make_error(R"(Expected exponent value after "e".)");
|
||||
error.start_column = column;
|
||||
error.leftmost_column = column;
|
||||
|
@ -705,8 +689,8 @@ GDScriptTokenizer::Token GDScriptTokenizer::number() {
|
|||
push_error(error);
|
||||
}
|
||||
previous_was_underscore = false;
|
||||
while (_is_digit(_peek()) || _peek() == '_') {
|
||||
if (_peek() == '_') {
|
||||
while (is_digit(_peek()) || is_underscore(_peek())) {
|
||||
if (is_underscore(_peek())) {
|
||||
if (previous_was_underscore) {
|
||||
Token error = make_error(R"(Only one underscore can be used as a numeric separator.)");
|
||||
error.start_column = column;
|
||||
|
@ -733,7 +717,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::number() {
|
|||
error.rightmost_column = column + 1;
|
||||
push_error(error);
|
||||
has_error = true;
|
||||
} else if (_is_alphanumeric(_peek())) {
|
||||
} else if (is_ascii_identifier_char(_peek())) {
|
||||
// Letter at the end of the number.
|
||||
push_error("Invalid numeric notation.");
|
||||
}
|
||||
|
@ -865,7 +849,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::string() {
|
|||
|
||||
char32_t digit = _peek();
|
||||
char32_t value = 0;
|
||||
if (digit >= '0' && digit <= '9') {
|
||||
if (is_digit(digit)) {
|
||||
value = digit - '0';
|
||||
} else if (digit >= 'a' && digit <= 'f') {
|
||||
value = digit - 'a';
|
||||
|
@ -1322,9 +1306,9 @@ GDScriptTokenizer::Token GDScriptTokenizer::scan() {
|
|||
|
||||
line_continuation = false;
|
||||
|
||||
if (_is_digit(c)) {
|
||||
if (is_digit(c)) {
|
||||
return number();
|
||||
} else if (_is_alphanumeric(c)) {
|
||||
} else if (is_ascii_identifier_char(c)) {
|
||||
return potential_identifier();
|
||||
}
|
||||
|
||||
|
@ -1392,7 +1376,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::scan() {
|
|||
if (_peek() == '.') {
|
||||
_advance();
|
||||
return make_token(Token::PERIOD_PERIOD);
|
||||
} else if (_is_digit(_peek())) {
|
||||
} else if (is_digit(_peek())) {
|
||||
// Number starting with '.'.
|
||||
return number();
|
||||
} else {
|
||||
|
|
|
@ -541,7 +541,7 @@ String ExtendGDScriptParser::get_identifier_under_position(const lsp::Position &
|
|||
for (int c = p_position.character; c >= 0; c--) {
|
||||
start_pos = c;
|
||||
char32_t ch = line[c];
|
||||
bool valid_char = (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_';
|
||||
bool valid_char = is_ascii_identifier_char(ch);
|
||||
if (!valid_char) {
|
||||
break;
|
||||
}
|
||||
|
@ -550,7 +550,7 @@ String ExtendGDScriptParser::get_identifier_under_position(const lsp::Position &
|
|||
int end_pos = p_position.character;
|
||||
for (int c = p_position.character; c < line.length(); c++) {
|
||||
char32_t ch = line[c];
|
||||
bool valid_char = (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_';
|
||||
bool valid_char = is_ascii_identifier_char(ch);
|
||||
if (!valid_char) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -690,11 +690,11 @@ void BindingsGenerator::_apply_prefix_to_enum_constants(BindingsGenerator::EnumI
|
|||
continue;
|
||||
}
|
||||
|
||||
if (parts[curr_prefix_length][0] >= '0' && parts[curr_prefix_length][0] <= '9') {
|
||||
if (is_digit(parts[curr_prefix_length][0])) {
|
||||
// The name of enum constants may begin with a numeric digit when strip from the enum prefix,
|
||||
// so we make the prefix for this constant one word shorter in those cases.
|
||||
for (curr_prefix_length = curr_prefix_length - 1; curr_prefix_length > 0; curr_prefix_length--) {
|
||||
if (parts[curr_prefix_length][0] < '0' || parts[curr_prefix_length][0] > '9') {
|
||||
if (!is_digit(parts[curr_prefix_length][0])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -303,22 +303,6 @@ _FORCE_INLINE_ bool is_connected_to_prev(char32_t p_chr, char32_t p_pchr) {
|
|||
return (prop != U_JT_RIGHT_JOINING) && (prop != U_JT_NON_JOINING) ? !is_ligature(p_pchr, p_chr) : false;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool is_control(char32_t p_char) {
|
||||
return (p_char <= 0x001f) || (p_char >= 0x007f && p_char <= 0x009F);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool is_whitespace(char32_t p_char) {
|
||||
return (p_char == 0x0020) || (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);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool is_linebreak(char32_t p_char) {
|
||||
return (p_char >= 0x000a && p_char <= 0x000d) || (p_char == 0x0085) || (p_char == 0x2028) || (p_char == 0x2029);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool is_underscore(char32_t p_char) {
|
||||
return (p_char == 0x005F);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
String TextServerAdvanced::interface_name = "ICU / HarfBuzz / Graphite";
|
||||
|
|
|
@ -43,30 +43,6 @@
|
|||
#include "msdfgen.h"
|
||||
#endif
|
||||
|
||||
/*************************************************************************/
|
||||
/* Character properties. */
|
||||
/*************************************************************************/
|
||||
|
||||
_FORCE_INLINE_ bool is_control(char32_t p_char) {
|
||||
return (p_char <= 0x001f) || (p_char >= 0x007f && p_char <= 0x009F);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool is_whitespace(char32_t p_char) {
|
||||
return (p_char == 0x0020) || (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);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool is_linebreak(char32_t p_char) {
|
||||
return (p_char >= 0x000a && p_char <= 0x000d) || (p_char == 0x0085) || (p_char == 0x2028) || (p_char == 0x2029);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool is_punct(char32_t p_char) {
|
||||
return (p_char >= 0x0020 && p_char <= 0x002F) || (p_char >= 0x003A && p_char <= 0x0040) || (p_char >= 0x005B && p_char <= 0x005E) || (p_char == 0x0060) || (p_char >= 0x007B && p_char <= 0x007E) || (p_char >= 0x2000 && p_char <= 0x206F) || (p_char >= 0x3000 && p_char <= 0x303F);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool is_underscore(char32_t p_char) {
|
||||
return (p_char == 0x005F);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
String TextServerFallback::interface_name = "Fallback";
|
||||
|
|
|
@ -377,13 +377,13 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
|
|||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
|
||||
if (!is_hex_digit(c)) {
|
||||
_set_error("Malformed hex constant in string");
|
||||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
char32_t v;
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
v = c - '0';
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
v = c - 'a';
|
||||
|
@ -457,7 +457,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (cchar >= '0' && cchar <= '9') {
|
||||
if (is_digit(cchar)) {
|
||||
//a number
|
||||
|
||||
String num;
|
||||
|
@ -476,7 +476,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
|
|||
while (true) {
|
||||
switch (reading) {
|
||||
case READING_INT: {
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
//pass
|
||||
} else if (c == '.') {
|
||||
reading = READING_DEC;
|
||||
|
@ -489,7 +489,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
|
|||
|
||||
} break;
|
||||
case READING_DEC: {
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
} else if (c == 'e') {
|
||||
reading = READING_EXP;
|
||||
|
||||
|
@ -499,7 +499,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
|
|||
|
||||
} break;
|
||||
case READING_EXP: {
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (is_digit(c)) {
|
||||
exp_beg = true;
|
||||
|
||||
} else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
|
||||
|
@ -532,11 +532,11 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
|
|||
}
|
||||
return OK;
|
||||
|
||||
} else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {
|
||||
} else if (is_ascii_char(cchar) || cchar == '_') {
|
||||
String id;
|
||||
bool first = true;
|
||||
|
||||
while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) {
|
||||
while (is_ascii_char(cchar) || cchar == '_' || (!first && is_digit(cchar))) {
|
||||
id += String::chr(cchar);
|
||||
cchar = GET_CHAR();
|
||||
first = false;
|
||||
|
|
|
@ -416,10 +416,10 @@ String EditorExportPlatformAndroid::get_package_name(const String &p_package) co
|
|||
bool first = true;
|
||||
for (int i = 0; i < basename.length(); i++) {
|
||||
char32_t c = basename[i];
|
||||
if (c >= '0' && c <= '9' && first) {
|
||||
if (is_digit(c) && first) {
|
||||
continue;
|
||||
}
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
|
||||
if (is_ascii_alphanumeric_char(c)) {
|
||||
name += String::chr(c);
|
||||
first = false;
|
||||
}
|
||||
|
@ -462,19 +462,19 @@ bool EditorExportPlatformAndroid::is_package_name_valid(const String &p_package,
|
|||
first = true;
|
||||
continue;
|
||||
}
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) {
|
||||
if (!is_ascii_identifier_char(c)) {
|
||||
if (r_error) {
|
||||
*r_error = vformat(TTR("The character '%s' is not allowed in Android application package names."), String::chr(c));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (first && (c >= '0' && c <= '9')) {
|
||||
if (first && is_digit(c)) {
|
||||
if (r_error) {
|
||||
*r_error = TTR("A digit cannot be the first character in a package segment.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (first && c == '_') {
|
||||
if (first && is_underscore(c)) {
|
||||
if (r_error) {
|
||||
*r_error = vformat(TTR("The character '%s' cannot be the first character in a package segment."), String::chr(c));
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform {
|
|||
|
||||
for (int i = 0; i < pname.length(); i++) {
|
||||
char32_t c = pname[i];
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '.')) {
|
||||
if (!(is_ascii_alphanumeric_char(c) || c == '-' || c == '.')) {
|
||||
if (r_error) {
|
||||
*r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
|
||||
}
|
||||
|
|
|
@ -2417,7 +2417,7 @@ Key DisplayServerX11::keyboard_get_keycode_from_physical(Key p_keycode) const {
|
|||
Key keycode_no_mod = p_keycode & KeyModifierMask::CODE_MASK;
|
||||
unsigned int xkeycode = KeyMappingX11::get_xlibcode(keycode_no_mod);
|
||||
KeySym xkeysym = XkbKeycodeToKeysym(x11_display, xkeycode, 0, 0);
|
||||
if (xkeysym >= 'a' && xkeysym <= 'z') {
|
||||
if (is_ascii_lower_case(xkeysym)) {
|
||||
xkeysym -= ('a' - 'A');
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ class EditorExportPlatformOSX : public EditorExportPlatform {
|
|||
|
||||
for (int i = 0; i < pname.length(); i++) {
|
||||
char32_t c = pname[i];
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '.')) {
|
||||
if (!(is_ascii_alphanumeric_char(c) || c == '-' || c == '.')) {
|
||||
if (r_error) {
|
||||
*r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
|
||||
}
|
||||
|
|
|
@ -34,14 +34,6 @@
|
|||
#include "core/string/string_builder.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
static bool _is_whitespace(char32_t c) {
|
||||
return c == '\t' || c == ' ';
|
||||
}
|
||||
|
||||
static bool _is_char(char32_t c) {
|
||||
return !is_symbol(c);
|
||||
}
|
||||
|
||||
void CodeEdit::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_THEME_CHANGED:
|
||||
|
@ -607,9 +599,9 @@ void CodeEdit::_handle_unicode_input_internal(const uint32_t p_unicode) {
|
|||
|
||||
int post_brace_pair = cc < get_line(cl).length() ? _get_auto_brace_pair_close_at_pos(cl, cc) : -1;
|
||||
|
||||
if (has_string_delimiter(chr) && cc > 0 && _is_char(get_line(cl)[cc - 1]) && post_brace_pair == -1) {
|
||||
if (has_string_delimiter(chr) && cc > 0 && !is_symbol(get_line(cl)[cc - 1]) && post_brace_pair == -1) {
|
||||
insert_text_at_caret(chr);
|
||||
} else if (cc < get_line(cl).length() && _is_char(get_line(cl)[cc])) {
|
||||
} else if (cc < get_line(cl).length() && !is_symbol(get_line(cl)[cc])) {
|
||||
insert_text_at_caret(chr);
|
||||
} else if (post_brace_pair != -1 && auto_brace_completion_pairs[post_brace_pair].close_key[0] == chr[0]) {
|
||||
caret_move_offset = auto_brace_completion_pairs[post_brace_pair].close_key.length();
|
||||
|
@ -1001,7 +993,7 @@ void CodeEdit::_new_line(bool p_split_current_line, bool p_above) {
|
|||
}
|
||||
|
||||
/* Make sure this is the last char, trailing whitespace or comments are okay. */
|
||||
if (should_indent && (!_is_whitespace(c) && is_in_comment(cl, cc) == -1)) {
|
||||
if (should_indent && (!is_whitespace(c) && is_in_comment(cl, cc) == -1)) {
|
||||
should_indent = false;
|
||||
}
|
||||
}
|
||||
|
@ -1817,7 +1809,7 @@ void CodeEdit::request_code_completion(bool p_force) {
|
|||
String line = get_line(get_caret_line());
|
||||
int ofs = CLAMP(get_caret_column(), 0, line.length());
|
||||
|
||||
if (ofs > 0 && (is_in_string(get_caret_line(), ofs) != -1 || _is_char(line[ofs - 1]) || code_completion_prefixes.has(line[ofs - 1]))) {
|
||||
if (ofs > 0 && (is_in_string(get_caret_line(), ofs) != -1 || !is_symbol(line[ofs - 1]) || code_completion_prefixes.has(line[ofs - 1]))) {
|
||||
emit_signal(SNAME("code_completion_requested"));
|
||||
} else if (ofs > 1 && line[ofs - 1] == ' ' && code_completion_prefixes.has(line[ofs - 2])) {
|
||||
emit_signal(SNAME("code_completion_requested"));
|
||||
|
@ -1926,7 +1918,7 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
|
|||
|
||||
if (merge_text) {
|
||||
for (; caret_col < line.length(); caret_col++) {
|
||||
if (!_is_char(line[caret_col])) {
|
||||
if (is_symbol(line[caret_col])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2562,7 +2554,7 @@ int CodeEdit::_is_in_delimiter(int p_line, int p_column, DelimiterType p_type) c
|
|||
region = E->value();
|
||||
in_region = true;
|
||||
for (int i = E->key() - 2; i >= 0; i--) {
|
||||
if (!_is_whitespace(line[i])) {
|
||||
if (!is_whitespace(line[i])) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -2581,7 +2573,7 @@ int CodeEdit::_is_in_delimiter(int p_line, int p_column, DelimiterType p_type) c
|
|||
}
|
||||
|
||||
for (int i = end_col; i < line.length(); i++) {
|
||||
if (!_is_whitespace(line[i])) {
|
||||
if (!is_whitespace(line[i])) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -2797,11 +2789,11 @@ void CodeEdit::_filter_code_completion_candidates_impl() {
|
|||
while (ofs > 0 && line[ofs] == ' ') {
|
||||
ofs--;
|
||||
}
|
||||
prev_is_word = _is_char(line[ofs]);
|
||||
prev_is_word = !is_symbol(line[ofs]);
|
||||
/* Otherwise get current word and set cofs to the start. */
|
||||
} else {
|
||||
int start_cofs = cofs;
|
||||
while (cofs > 0 && line[cofs - 1] > 32 && (line[cofs - 1] == '/' || _is_char(line[cofs - 1]))) {
|
||||
while (cofs > 0 && line[cofs - 1] > 32 && (line[cofs - 1] == '/' || !is_symbol(line[cofs - 1]))) {
|
||||
cofs--;
|
||||
}
|
||||
string_to_complete = line.substr(cofs, start_cofs - cofs);
|
||||
|
|
|
@ -43,18 +43,6 @@
|
|||
|
||||
#include "scene/main/window.h"
|
||||
|
||||
static bool _is_text_char(char32_t c) {
|
||||
return !is_symbol(c);
|
||||
}
|
||||
|
||||
static bool _is_whitespace(char32_t c) {
|
||||
return c == '\t' || c == ' ';
|
||||
}
|
||||
|
||||
static bool _is_char(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// TEXT ///
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -820,8 +808,8 @@ void TextEdit::_notification(int p_what) {
|
|||
int xpos = indent_px + ((xmargin_end + minimap_char_size.x) + (minimap_char_size.x * j)) + tabs;
|
||||
bool out_of_bounds = (xpos >= xmargin_end + minimap_width);
|
||||
|
||||
bool is_whitespace = _is_whitespace(str[j]);
|
||||
if (!is_whitespace) {
|
||||
bool whitespace = is_whitespace(str[j]);
|
||||
if (!whitespace) {
|
||||
characters++;
|
||||
|
||||
if (j < str.length() - 1 && color == previous_color && !out_of_bounds) {
|
||||
|
@ -843,7 +831,7 @@ void TextEdit::_notification(int p_what) {
|
|||
if (characters > 0) {
|
||||
previous_color.a *= 0.6;
|
||||
// take one for zero indexing, and if we hit whitespace / the end of a word.
|
||||
int chars = MAX(0, (j - (characters - 1)) - (is_whitespace ? 1 : 0)) + 1;
|
||||
int chars = MAX(0, (j - (characters - 1)) - (whitespace ? 1 : 0)) + 1;
|
||||
int char_x_ofs = indent_px + ((xmargin_end + minimap_char_size.x) + (minimap_char_size.x * chars)) + tabs;
|
||||
if (rtl) {
|
||||
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(size.width - char_x_ofs - minimap_char_size.x * characters, minimap_line_height * i), Point2(minimap_char_size.x * characters, minimap_char_size.y)), previous_color);
|
||||
|
@ -1144,7 +1132,7 @@ void TextEdit::_notification(int p_what) {
|
|||
}
|
||||
|
||||
if (!clipped && lookup_symbol_word.length() != 0) { // Highlight word
|
||||
if (_is_char(lookup_symbol_word[0]) || lookup_symbol_word[0] == '.') {
|
||||
if (is_ascii_char(lookup_symbol_word[0]) || lookup_symbol_word[0] == '_' || lookup_symbol_word[0] == '.') {
|
||||
int highlighted_word_col = _get_column_pos_of_word(lookup_symbol_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0);
|
||||
while (highlighted_word_col != -1) {
|
||||
Vector<Vector2> sel = TS->shaped_text_get_selection(rid, highlighted_word_col + start, highlighted_word_col + lookup_symbol_word.length() + start);
|
||||
|
@ -3037,7 +3025,7 @@ int TextEdit::get_first_non_whitespace_column(int p_line) const {
|
|||
ERR_FAIL_INDEX_V(p_line, text.size(), 0);
|
||||
|
||||
int col = 0;
|
||||
while (col < text[p_line].length() && _is_whitespace(text[p_line][col])) {
|
||||
while (col < text[p_line].length() && is_whitespace(text[p_line][col])) {
|
||||
col++;
|
||||
}
|
||||
return col;
|
||||
|
@ -3622,9 +3610,9 @@ Point2i TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_fro
|
|||
|
||||
if (pos != -1 && (p_search_flags & SEARCH_WHOLE_WORDS)) {
|
||||
// Validate for whole words.
|
||||
if (pos > 0 && _is_text_char(text_line[pos - 1])) {
|
||||
if (pos > 0 && !is_symbol(text_line[pos - 1])) {
|
||||
is_match = false;
|
||||
} else if (pos + p_key.length() < text_line.length() && _is_text_char(text_line[pos + p_key.length()])) {
|
||||
} else if (pos + p_key.length() < text_line.length() && !is_symbol(text_line[pos + p_key.length()])) {
|
||||
is_match = false;
|
||||
}
|
||||
}
|
||||
|
@ -5779,9 +5767,9 @@ int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_searc
|
|||
if (col != -1 && p_search_flags & SEARCH_WHOLE_WORDS) {
|
||||
p_from_column = col;
|
||||
|
||||
if (col > 0 && _is_text_char(p_search[col - 1])) {
|
||||
if (col > 0 && !is_symbol(p_search[col - 1])) {
|
||||
col = -1;
|
||||
} else if ((col + p_key.length()) < p_search.length() && _is_text_char(p_search[col + p_key.length()])) {
|
||||
} else if ((col + p_key.length()) < p_search.length() && !is_symbol(p_search[col + p_key.length()])) {
|
||||
col = -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1061,7 +1061,7 @@ void Node::_generate_serial_child_name(const Node *p_child, StringName &name) co
|
|||
String nums;
|
||||
for (int i = name_string.length() - 1; i >= 0; i--) {
|
||||
char32_t n = name_string[i];
|
||||
if (n >= '0' && n <= '9') {
|
||||
if (is_digit(n)) {
|
||||
nums = String::chr(name_string[i]) + nums;
|
||||
} else {
|
||||
break;
|
||||
|
|
|
@ -130,7 +130,7 @@ Variant PropertyUtils::get_property_default_value(const Object *p_object, const
|
|||
if (p != -1 && p < prop_str.length() - 1) {
|
||||
bool all_digits = true;
|
||||
for (int i = p + 1; i < prop_str.length(); i++) {
|
||||
if (prop_str[i] < '0' || prop_str[i] > '9') {
|
||||
if (!is_digit(prop_str[i])) {
|
||||
all_digits = false;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -116,14 +116,6 @@ void SyntaxHighlighter::_bind_methods() {
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool _is_char(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
|
||||
}
|
||||
|
||||
static bool _is_hex_symbol(char32_t c) {
|
||||
return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
|
||||
}
|
||||
|
||||
Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
|
||||
Dictionary color_map;
|
||||
|
||||
|
@ -166,7 +158,7 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
|
|||
color = font_color;
|
||||
bool is_char = !is_symbol(str[j]);
|
||||
bool is_a_symbol = is_symbol(str[j]);
|
||||
bool is_number = (str[j] >= '0' && str[j] <= '9');
|
||||
bool is_number = is_digit(str[j]);
|
||||
|
||||
/* color regions */
|
||||
if (is_a_symbol || in_region != -1) {
|
||||
|
@ -304,7 +296,7 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
|
|||
}
|
||||
|
||||
// Allow ABCDEF in hex notation.
|
||||
if (is_hex_notation && (_is_hex_symbol(str[j]) || is_number)) {
|
||||
if (is_hex_notation && (is_hex_digit(str[j]) || is_number)) {
|
||||
is_number = true;
|
||||
} else {
|
||||
is_hex_notation = false;
|
||||
|
@ -321,7 +313,7 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!in_word && _is_char(str[j]) && !is_number) {
|
||||
if (!in_word && (is_ascii_char(str[j]) || is_underscore(str[j])) && !is_number) {
|
||||
in_word = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1106,10 +1106,6 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
|
|||
return final_code;
|
||||
}
|
||||
|
||||
#define IS_INITIAL_CHAR(m_d) (((m_d) >= 'a' && (m_d) <= 'z') || ((m_d) >= 'A' && (m_d) <= 'Z'))
|
||||
|
||||
#define IS_SYMBOL_CHAR(m_d) (((m_d) >= 'a' && (m_d) <= 'z') || ((m_d) >= 'A' && (m_d) <= 'Z') || ((m_d) >= '0' && (m_d) <= '9') || (m_d) == '_')
|
||||
|
||||
String VisualShader::validate_port_name(const String &p_port_name, VisualShaderNode *p_node, int p_port_id, bool p_output) const {
|
||||
String name = p_port_name;
|
||||
|
||||
|
@ -1117,7 +1113,7 @@ String VisualShader::validate_port_name(const String &p_port_name, VisualShaderN
|
|||
return String();
|
||||
}
|
||||
|
||||
while (name.length() && !IS_INITIAL_CHAR(name[0])) {
|
||||
while (name.length() && !is_ascii_char(name[0])) {
|
||||
name = name.substr(1, name.length() - 1);
|
||||
}
|
||||
|
||||
|
@ -1125,7 +1121,7 @@ String VisualShader::validate_port_name(const String &p_port_name, VisualShaderN
|
|||
String valid_name;
|
||||
|
||||
for (int i = 0; i < name.length(); i++) {
|
||||
if (IS_SYMBOL_CHAR(name[i])) {
|
||||
if (is_ascii_identifier_char(name[i])) {
|
||||
valid_name += String::chr(name[i]);
|
||||
} else if (name[i] == ' ') {
|
||||
valid_name += "_";
|
||||
|
@ -1162,14 +1158,14 @@ String VisualShader::validate_port_name(const String &p_port_name, VisualShaderN
|
|||
|
||||
String VisualShader::validate_uniform_name(const String &p_name, const Ref<VisualShaderNodeUniform> &p_uniform) const {
|
||||
String name = p_name; //validate name first
|
||||
while (name.length() && !IS_INITIAL_CHAR(name[0])) {
|
||||
while (name.length() && !is_ascii_char(name[0])) {
|
||||
name = name.substr(1, name.length() - 1);
|
||||
}
|
||||
if (!name.is_empty()) {
|
||||
String valid_name;
|
||||
|
||||
for (int i = 0; i < name.length(); i++) {
|
||||
if (IS_SYMBOL_CHAR(name[i])) {
|
||||
if (is_ascii_identifier_char(name[i])) {
|
||||
valid_name += String::chr(name[i]);
|
||||
} else if (name[i] == ' ') {
|
||||
valid_name += "_";
|
||||
|
@ -1206,7 +1202,7 @@ String VisualShader::validate_uniform_name(const String &p_name, const Ref<Visua
|
|||
if (exists) {
|
||||
//remove numbers, put new and try again
|
||||
attempt++;
|
||||
while (name.length() && name[name.length() - 1] >= '0' && name[name.length() - 1] <= '9') {
|
||||
while (name.length() && is_digit(name[name.length() - 1])) {
|
||||
name = name.substr(0, name.length() - 1);
|
||||
}
|
||||
ERR_FAIL_COND_V(name.is_empty(), String());
|
||||
|
|
|
@ -35,18 +35,6 @@
|
|||
|
||||
#define HAS_WARNING(flag) (warning_flags & flag)
|
||||
|
||||
static bool _is_text_char(char32_t c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
||||
}
|
||||
|
||||
static bool _is_number(char32_t c) {
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
static bool _is_hex(char32_t c) {
|
||||
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
||||
}
|
||||
|
||||
String ShaderLanguage::get_operator_text(Operator p_op) {
|
||||
static const char *op_names[OP_MAX] = { "==",
|
||||
"!=",
|
||||
|
@ -543,7 +531,7 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
|
|||
default: {
|
||||
char_idx--; //go back one, since we have no idea what this is
|
||||
|
||||
if (_is_number(GETCHAR(0)) || (GETCHAR(0) == '.' && _is_number(GETCHAR(1)))) {
|
||||
if (is_digit(GETCHAR(0)) || (GETCHAR(0) == '.' && is_digit(GETCHAR(1)))) {
|
||||
// parse number
|
||||
bool hexa_found = false;
|
||||
bool period_found = false;
|
||||
|
@ -584,7 +572,7 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
|
|||
const char32_t symbol = String::char_lowercase(GETCHAR(i));
|
||||
bool error = false;
|
||||
|
||||
if (_is_number(symbol)) {
|
||||
if (is_digit(symbol)) {
|
||||
if (end_suffix_found) {
|
||||
error = true;
|
||||
}
|
||||
|
@ -617,8 +605,8 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else if (!hexa_found || !_is_hex(symbol)) {
|
||||
if (_is_text_char(symbol)) {
|
||||
} else if (!hexa_found || !is_hex_digit(symbol)) {
|
||||
if (is_ascii_identifier_char(symbol)) {
|
||||
error = true;
|
||||
} else {
|
||||
break;
|
||||
|
@ -649,7 +637,7 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
|
|||
return _make_token(TK_ERROR, "Invalid (hexadecimal) numeric constant");
|
||||
}
|
||||
} else if (period_found || exponent_found || float_suffix_found) { // Float
|
||||
if (exponent_found && (!_is_number(last_char) && last_char != 'f')) { // checks for eg: "2E", "2E-", "2E+"
|
||||
if (exponent_found && (!is_digit(last_char) && last_char != 'f')) { // checks for eg: "2E", "2E-", "2E+"
|
||||
return _make_token(TK_ERROR, "Invalid (float) numeric constant");
|
||||
}
|
||||
if (period_found) {
|
||||
|
@ -660,7 +648,7 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
|
|||
}
|
||||
} else {
|
||||
//checks for eg. "1." or "1.99" notations
|
||||
if (last_char != '.' && !_is_number(last_char)) {
|
||||
if (last_char != '.' && !is_digit(last_char)) {
|
||||
return _make_token(TK_ERROR, "Invalid (float) numeric constant");
|
||||
}
|
||||
}
|
||||
|
@ -723,11 +711,11 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
|
|||
return _make_token(TK_PERIOD);
|
||||
}
|
||||
|
||||
if (_is_text_char(GETCHAR(0))) {
|
||||
if (is_ascii_identifier_char(GETCHAR(0))) {
|
||||
// parse identifier
|
||||
String str;
|
||||
|
||||
while (_is_text_char(GETCHAR(0))) {
|
||||
while (is_ascii_identifier_char(GETCHAR(0))) {
|
||||
str += char32_t(GETCHAR(0));
|
||||
char_idx++;
|
||||
}
|
||||
|
|
|
@ -227,7 +227,7 @@ class GetClassAndNamespace {
|
|||
return TK_SYMBOL;
|
||||
}
|
||||
|
||||
if (code[idx] == '-' || (code[idx] >= '0' && code[idx] <= '9')) {
|
||||
if (code[idx] == '-' || is_digit(code[idx])) {
|
||||
//a number
|
||||
const char32_t *rptr;
|
||||
double number = String::to_float(&code[idx], &rptr);
|
||||
|
@ -235,10 +235,10 @@ class GetClassAndNamespace {
|
|||
value = number;
|
||||
return TK_NUMBER;
|
||||
|
||||
} else if ((code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) {
|
||||
} else if (is_ascii_char(code[idx]) || code[idx] > 127) {
|
||||
String id;
|
||||
|
||||
while ((code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) {
|
||||
while (is_ascii_char(code[idx]) || code[idx] > 127) {
|
||||
id += code[idx];
|
||||
idx++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue