diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-23 16:14:08 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-23 16:14:08 +0200 |
commit | 4254946de93bab0cc1fb36a7b9039c9ec43be924 (patch) | |
tree | 7c20e9d89ccfdd1e48c50a969b9ea828e562f3cf /core/string/ustring.cpp | |
parent | 2017006879833d346a967dc8fcce4b846a8ed1c6 (diff) | |
parent | a751c05b15e75904cc949934f95061f1c0ee40e4 (diff) | |
download | redot-engine-4254946de93bab0cc1fb36a7b9039c9ec43be924.tar.gz |
Merge pull request #97323 from timothyqiu/drop-unicode-identifier
Fix script editor wrongly replaces and quotes non-ASCII letters
Diffstat (limited to 'core/string/ustring.cpp')
-rw-r--r-- | core/string/ustring.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 2683addd4b..391a203d5b 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -4626,7 +4626,7 @@ bool String::is_absolute_path() const { String String::validate_ascii_identifier() const { if (is_empty()) { - return "_"; // Empty string is not a valid identifier; + return "_"; // Empty string is not a valid identifier. } String result; @@ -4647,6 +4647,29 @@ String String::validate_ascii_identifier() const { return result; } +String String::validate_unicode_identifier() const { + if (is_empty()) { + return "_"; // Empty string is not a valid identifier. + } + + String result; + if (is_unicode_identifier_start(operator[](0))) { + result = *this; + } else { + result = "_" + *this; + } + + int len = result.length(); + char32_t *buffer = result.ptrw(); + for (int i = 0; i < len; i++) { + if (!is_unicode_identifier_continue(buffer[i])) { + buffer[i] = '_'; + } + } + + return result; +} + bool String::is_valid_ascii_identifier() const { int len = length(); |