From 34dc1634418aded05b3b1e8230b39b297e1307ce Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 26 Jul 2020 20:59:22 -0400 Subject: [PATCH] CppLexer: Correctly highlight hex escapes in string and char literals \x consumes all hex digits following it. (If the resulting number then doesn't fit in the character type, the compiler emits an error.) \x would be much more convenient to use if it was always followed by exactly two hex digits (with \u and \U for higher codepoints), but that's sadly not the world we live in. --- Libraries/LibGUI/CppLexer.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Libraries/LibGUI/CppLexer.cpp b/Libraries/LibGUI/CppLexer.cpp index 74cc9bd245..e5918604bc 100644 --- a/Libraries/LibGUI/CppLexer.cpp +++ b/Libraries/LibGUI/CppLexer.cpp @@ -287,11 +287,8 @@ Vector CppLexer::lex() } case 'x': { size_t hex_digits = 0; - for (size_t i = 0; i < 2; ++i) { - if (!isxdigit(peek(2 + i))) - break; + while (isxdigit(peek(2 + hex_digits))) ++hex_digits; - } return 2 + hex_digits; } case 'u':