Skip to content

Commit d6ed964

Browse files
committed
Fix uppercase B and X parsing in the integer literals.
1 parent eee39f0 commit d6ed964

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

core/math/expression.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ Error Expression::_get_token(Token &r_token) {
350350
case READING_INT: {
351351
if (is_digit(c)) {
352352
if (is_first_char && c == '0') {
353-
if (next_char == 'b') {
353+
if (next_char == 'b' || next_char == 'B') {
354354
reading = READING_BIN;
355-
} else if (next_char == 'x') {
355+
} else if (next_char == 'x' || next_char == 'X') {
356356
reading = READING_HEX;
357357
}
358358
}
@@ -370,15 +370,15 @@ Error Expression::_get_token(Token &r_token) {
370370
case READING_BIN: {
371371
if (bin_beg && !is_binary_digit(c)) {
372372
reading = READING_DONE;
373-
} else if (c == 'b') {
373+
} else if (c == 'b' || c == 'B') {
374374
bin_beg = true;
375375
}
376376

377377
} break;
378378
case READING_HEX: {
379379
if (hex_beg && !is_hex_digit(c)) {
380380
reading = READING_DONE;
381-
} else if (c == 'x') {
381+
} else if (c == 'x' || c == 'X') {
382382
hex_beg = true;
383383
}
384384

editor/import/resource_importer_imagefont.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Error ResourceImporterImageFont::import(ResourceUID::ID p_source_id, const Strin
159159
c++; // Skip "+".
160160
continue;
161161
}
162-
} else if (range[c] == '0' && (c <= range.length() - 2) && range[c + 1] == 'x') {
162+
} else if (range[c] == '0' && (c <= range.length() - 2) && (range[c + 1] == 'x' || range[c + 1] == 'X')) {
163163
// Read hexadecimal value, start.
164164
token = String();
165165
if (step == STEP_START_BEGIN) {

modules/gdscript/editor/gdscript_highlighter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,12 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
351351

352352
// Special cases for numbers.
353353
if (in_number && !is_a_digit) {
354-
if (str[j] == 'b' && str[j - 1] == '0') {
354+
if ((str[j] == 'b' || str[j] == 'B') && str[j - 1] == '0') {
355355
is_bin_notation = true;
356-
} else if (str[j] == 'x' && str[j - 1] == '0') {
356+
} else if ((str[j] == 'x' || str[j] == 'X') && str[j - 1] == '0') {
357357
is_hex_notation = true;
358358
} else if (!((str[j] == '-' || str[j] == '+') && str[j - 1] == 'e' && !prev_is_digit) &&
359-
!(str[j] == '_' && (prev_is_digit || str[j - 1] == 'b' || str[j - 1] == 'x' || str[j - 1] == '.')) &&
359+
!(str[j] == '_' && (prev_is_digit || str[j - 1] == 'b' || str[j - 1] == 'B' || str[j - 1] == 'x' || str[j - 1] == 'X' || str[j - 1] == '.')) &&
360360
!(str[j] == 'e' && (prev_is_digit || str[j - 1] == '_')) &&
361361
!(str[j] == '.' && (prev_is_digit || (!prev_is_binary_op && (j > 0 && (str[j - 1] == '_' || str[j - 1] == '-' || str[j - 1] == '+' || str[j - 1] == '~'))))) &&
362362
!((str[j] == '-' || str[j] == '+' || str[j] == '~') && !is_binary_op && !prev_is_binary_op && str[j - 1] != 'e')) {

modules/gdscript/gdscript_tokenizer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -696,13 +696,13 @@ GDScriptTokenizer::Token GDScriptTokenizerText::number() {
696696
if (_peek(-1) == '.') {
697697
has_decimal = true;
698698
} else if (_peek(-1) == '0') {
699-
if (_peek() == 'x') {
699+
if (_peek() == 'x' || _peek() == 'X') {
700700
// Hexadecimal.
701701
base = 16;
702702
digit_check_func = is_hex_digit;
703703
need_digits = true;
704704
_advance();
705-
} else if (_peek() == 'b') {
705+
} else if (_peek() == 'b' || _peek() == 'B') {
706706
// Binary.
707707
base = 2;
708708
digit_check_func = is_binary_digit;

modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ public static bool IsValidHexNumber(this string instance, bool withPrefix = fals
979979
{
980980
if (instance.Length < 3)
981981
return false;
982-
if (instance[from] != '0' || instance[from + 1] != 'x')
982+
if (instance[from] != '0' || instance[from + 1] != 'x' || instance[from + 1] != 'X')
983983
return false;
984984
from += 2;
985985
}

scene/resources/syntax_highlighter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
302302
}
303303

304304
// Check for dot or underscore or 'x' for hex notation in floating point number or 'e' for scientific notation.
305-
if ((str[j] == '.' || str[j] == 'x' || str[j] == '_' || str[j] == 'f' || str[j] == 'e' || (uint_suffix_enabled && str[j] == 'u')) && !in_word && prev_is_number && !is_number) {
305+
if ((str[j] == '.' || str[j] == 'x' || str[j] == 'X' || str[j] == '_' || str[j] == 'f' || str[j] == 'e' || (uint_suffix_enabled && str[j] == 'u')) && !in_word && prev_is_number && !is_number) {
306306
is_number = true;
307307
is_a_symbol = false;
308308
is_char = false;
309309

310-
if (str[j] == 'x' && str[j - 1] == '0') {
310+
if ((str[j] == 'x' || str[j] == 'X') && str[j - 1] == '0') {
311311
is_hex_notation = true;
312312
}
313313
}

0 commit comments

Comments
 (0)