summaryrefslogtreecommitdiffstats
path: root/core/string
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2024-09-22 19:31:58 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2024-09-23 00:05:16 +0800
commita751c05b15e75904cc949934f95061f1c0ee40e4 (patch)
treeaff1c399f313ccc8a37c4e524146b2e3fac6dde0 /core/string
parente4e024ab88efe74677769395886bc1b09eccbac7 (diff)
downloadredot-engine-a751c05b15e75904cc949934f95061f1c0ee40e4.tar.gz
Fix script editor wrongly replaces and quotes non-ASCII letters
Diffstat (limited to 'core/string')
-rw-r--r--core/string/ustring.cpp25
-rw-r--r--core/string/ustring.h1
2 files changed, 25 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();
diff --git a/core/string/ustring.h b/core/string/ustring.h
index 11f15031f9..5d4b209c25 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -460,6 +460,7 @@ public:
static String get_invalid_node_name_characters(bool p_allow_internal = false);
String validate_node_name() const;
String validate_ascii_identifier() const;
+ String validate_unicode_identifier() const;
String validate_filename() const;
bool is_valid_ascii_identifier() const;