diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/text/text_server_extension.cpp | 9 | ||||
-rw-r--r-- | servers/text/text_server_extension.h | 3 | ||||
-rw-r--r-- | servers/text_server.cpp | 22 | ||||
-rw-r--r-- | servers/text_server.h | 2 |
4 files changed, 36 insertions, 0 deletions
diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp index 47598abce7..c2387be80d 100644 --- a/servers/text/text_server_extension.cpp +++ b/servers/text/text_server_extension.cpp @@ -297,6 +297,7 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(percent_sign, "language"); GDVIRTUAL_BIND(strip_diacritics, "string"); + GDVIRTUAL_BIND(is_valid_identifier, "string"); GDVIRTUAL_BIND(string_get_word_breaks, "string", "language"); @@ -1498,6 +1499,14 @@ String TextServerExtension::percent_sign(const String &p_language) const { return "%"; } +bool TextServerExtension::is_valid_identifier(const String &p_string) const { + bool ret; + if (GDVIRTUAL_CALL(is_valid_identifier, p_string, ret)) { + return ret; + } + return TextServer::is_valid_identifier(p_string); +} + String TextServerExtension::strip_diacritics(const String &p_string) const { String ret; if (GDVIRTUAL_CALL(strip_diacritics, p_string, ret)) { diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h index 571753ea67..3814e2ad88 100644 --- a/servers/text/text_server_extension.h +++ b/servers/text/text_server_extension.h @@ -496,6 +496,9 @@ public: virtual PackedInt32Array string_get_word_breaks(const String &p_string, const String &p_language = "") const override; GDVIRTUAL2RC(PackedInt32Array, string_get_word_breaks, const String &, const String &); + virtual bool is_valid_identifier(const String &p_string) const override; + GDVIRTUAL1RC(bool, is_valid_identifier, const String &); + virtual String string_to_upper(const String &p_string, const String &p_language = "") const override; virtual String string_to_lower(const String &p_string, const String &p_language = "") const override; GDVIRTUAL2RC(String, string_to_upper, const String &, const String &); diff --git a/servers/text_server.cpp b/servers/text_server.cpp index 4a6b03d943..1ea05795f1 100644 --- a/servers/text_server.cpp +++ b/servers/text_server.cpp @@ -447,6 +447,7 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("string_get_word_breaks", "string", "language"), &TextServer::string_get_word_breaks, DEFVAL("")); ClassDB::bind_method(D_METHOD("strip_diacritics", "string"), &TextServer::strip_diacritics); + ClassDB::bind_method(D_METHOD("is_valid_identifier", "string"), &TextServer::is_valid_identifier); ClassDB::bind_method(D_METHOD("string_to_upper", "string", "language"), &TextServer::string_to_upper, DEFVAL("")); ClassDB::bind_method(D_METHOD("string_to_lower", "string", "language"), &TextServer::string_to_lower, DEFVAL("")); @@ -545,6 +546,7 @@ void TextServer::_bind_methods() { BIND_ENUM_CONSTANT(FEATURE_FONT_VARIABLE); BIND_ENUM_CONSTANT(FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION); BIND_ENUM_CONSTANT(FEATURE_USE_SUPPORT_DATA); + BIND_ENUM_CONSTANT(FEATURE_UNICODE_IDENTIFIERS); /* FT Contour Point Types */ BIND_ENUM_CONSTANT(CONTOUR_CURVE_TAG_ON); @@ -1730,6 +1732,26 @@ Array TextServer::_shaped_text_get_ellipsis_glyphs_wrapper(const RID &p_shaped) return ret; } +bool TextServer::is_valid_identifier(const String &p_string) const { + const char32_t *str = p_string.ptr(); + int len = p_string.length(); + + if (len == 0) { + return false; // Empty string. + } + + if (!is_unicode_identifier_start(str[0])) { + return false; + } + + for (int i = 1; i < len; i++) { + if (!is_unicode_identifier_continue(str[i])) { + return false; + } + } + return true; +} + TextServer::TextServer() { _init_diacritics_map(); } diff --git a/servers/text_server.h b/servers/text_server.h index f6ab165bfc..0e57bcbb6c 100644 --- a/servers/text_server.h +++ b/servers/text_server.h @@ -148,6 +148,7 @@ public: FEATURE_FONT_VARIABLE = 1 << 10, FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION = 1 << 11, FEATURE_USE_SUPPORT_DATA = 1 << 12, + FEATURE_UNICODE_IDENTIFIERS = 1 << 13, }; enum ContourPointTag { @@ -464,6 +465,7 @@ public: virtual PackedInt32Array string_get_word_breaks(const String &p_string, const String &p_language = "") const = 0; virtual String strip_diacritics(const String &p_string) const; + virtual bool is_valid_identifier(const String &p_string) const; // Other string operations. virtual String string_to_upper(const String &p_string, const String &p_language = "") const = 0; |