|
@@ -3974,24 +3974,22 @@ bool String::is_absolute_path() const {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static _FORCE_INLINE_ bool _is_valid_identifier_bit(int p_index, char32_t p_char) {
|
|
|
|
- if (p_index == 0 && is_digit(p_char)) {
|
|
|
|
- return false; // No start with number plz.
|
|
|
|
- }
|
|
|
|
- return is_ascii_identifier_char(p_char);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
String String::validate_identifier() const {
|
|
String String::validate_identifier() const {
|
|
if (is_empty()) {
|
|
if (is_empty()) {
|
|
return "_"; // Empty string is not a valid identifier;
|
|
return "_"; // Empty string is not a valid identifier;
|
|
}
|
|
}
|
|
|
|
|
|
- String result = *this;
|
|
|
|
|
|
+ String result;
|
|
|
|
+ if (is_digit(operator[](0))) {
|
|
|
|
+ result = "_" + *this;
|
|
|
|
+ } else {
|
|
|
|
+ result = *this;
|
|
|
|
+ }
|
|
|
|
+
|
|
int len = result.length();
|
|
int len = result.length();
|
|
char32_t *buffer = result.ptrw();
|
|
char32_t *buffer = result.ptrw();
|
|
-
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
for (int i = 0; i < len; i++) {
|
|
- if (!_is_valid_identifier_bit(i, buffer[i])) {
|
|
|
|
|
|
+ if (!is_ascii_identifier_char(buffer[i])) {
|
|
buffer[i] = '_';
|
|
buffer[i] = '_';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -4006,10 +4004,14 @@ bool String::is_valid_identifier() const {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (is_digit(operator[](0))) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
const char32_t *str = &operator[](0);
|
|
const char32_t *str = &operator[](0);
|
|
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
for (int i = 0; i < len; i++) {
|
|
- if (!_is_valid_identifier_bit(i, str[i])) {
|
|
|
|
|
|
+ if (!is_ascii_identifier_char(str[i])) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|