summaryrefslogtreecommitdiffstats
path: root/core/string
diff options
context:
space:
mode:
Diffstat (limited to 'core/string')
-rw-r--r--core/string/ustring.cpp24
-rw-r--r--core/string/ustring.h8
2 files changed, 28 insertions, 4 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 303998ab50..2683addd4b 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -4624,7 +4624,7 @@ bool String::is_absolute_path() const {
}
}
-String String::validate_identifier() const {
+String String::validate_ascii_identifier() const {
if (is_empty()) {
return "_"; // Empty string is not a valid identifier;
}
@@ -4647,7 +4647,7 @@ String String::validate_identifier() const {
return result;
}
-bool String::is_valid_identifier() const {
+bool String::is_valid_ascii_identifier() const {
int len = length();
if (len == 0) {
@@ -4669,6 +4669,26 @@ bool String::is_valid_identifier() const {
return true;
}
+bool String::is_valid_unicode_identifier() const {
+ const char32_t *str = ptr();
+ int len = 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;
+}
+
bool String::is_valid_string() const {
int l = length();
const char32_t *src = get_data();
diff --git a/core/string/ustring.h b/core/string/ustring.h
index 9df2d56e80..11f15031f9 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -459,10 +459,11 @@ public:
// node functions
static String get_invalid_node_name_characters(bool p_allow_internal = false);
String validate_node_name() const;
- String validate_identifier() const;
+ String validate_ascii_identifier() const;
String validate_filename() const;
- bool is_valid_identifier() const;
+ bool is_valid_ascii_identifier() const;
+ bool is_valid_unicode_identifier() const;
bool is_valid_int() const;
bool is_valid_float() const;
bool is_valid_hex_number(bool p_with_prefix) const;
@@ -470,6 +471,9 @@ public:
bool is_valid_ip_address() const;
bool is_valid_filename() const;
+ // Use `is_valid_ascii_identifier()` instead. Kept for compatibility.
+ bool is_valid_identifier() const { return is_valid_ascii_identifier(); }
+
/**
* The constructors must not depend on other overloads
*/