You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-15 13:51:40 +00:00
Add support for the escaped UTF-16 and UTF-32 Unicode characters in the scripts and expressions.
This commit is contained in:
@@ -217,6 +217,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
||||
}
|
||||
case '"': {
|
||||
String str;
|
||||
char32_t prev = 0;
|
||||
while (true) {
|
||||
char32_t ch = p_stream->get_char();
|
||||
|
||||
@@ -252,10 +253,13 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
||||
case 'r':
|
||||
res = 13;
|
||||
break;
|
||||
case 'U':
|
||||
case 'u': {
|
||||
//hex number
|
||||
for (int j = 0; j < 4; j++) {
|
||||
// Hexadecimal sequence.
|
||||
int hex_len = (next == 'U') ? 6 : 4;
|
||||
for (int j = 0; j < hex_len; j++) {
|
||||
char32_t c = p_stream->get_char();
|
||||
|
||||
if (c == 0) {
|
||||
r_err_str = "Unterminated String";
|
||||
r_token.type = TK_ERROR;
|
||||
@@ -290,15 +294,49 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
||||
} break;
|
||||
}
|
||||
|
||||
// Parse UTF-16 pair.
|
||||
if ((res & 0xfffffc00) == 0xd800) {
|
||||
if (prev == 0) {
|
||||
prev = res;
|
||||
continue;
|
||||
} else {
|
||||
r_err_str = "Invalid UTF-16 sequence in string, unpaired lead surrogate";
|
||||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
} else if ((res & 0xfffffc00) == 0xdc00) {
|
||||
if (prev == 0) {
|
||||
r_err_str = "Invalid UTF-16 sequence in string, unpaired trail surrogate";
|
||||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
} else {
|
||||
res = (prev << 10UL) + res - ((0xd800 << 10UL) + 0xdc00 - 0x10000);
|
||||
prev = 0;
|
||||
}
|
||||
}
|
||||
if (prev != 0) {
|
||||
r_err_str = "Invalid UTF-16 sequence in string, unpaired lead surrogate";
|
||||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
str += res;
|
||||
|
||||
} else {
|
||||
if (prev != 0) {
|
||||
r_err_str = "Invalid UTF-16 sequence in string, unpaired lead surrogate";
|
||||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
if (ch == '\n') {
|
||||
line++;
|
||||
}
|
||||
str += ch;
|
||||
}
|
||||
}
|
||||
if (prev != 0) {
|
||||
r_err_str = "Invalid UTF-16 sequence in string, unpaired lead surrogate";
|
||||
r_token.type = TK_ERROR;
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
if (p_stream->is_utf8()) {
|
||||
str.parse_utf8(str.ascii(true).get_data());
|
||||
|
||||
Reference in New Issue
Block a user