Add String.is_valid_unicode_identifier()
- Adds `is_valid_unicode_identifier()` - Adds `is_valid_ascii_identifier()` - Deprecates `is_valid_identifier()` - Renames `validate_identifier()` to `validate_ascii_identifier()`
This commit is contained in:
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user