feat: add 8-digit Unicode escape support with \U prefix in string literals

Extend the string parser to handle `\U` escape sequences for 8-hex-digit Unicode code points (e.g., `\U0001F603`), enabling encoding of characters beyond the Basic Multilingual Plane. Refactor `readUnicodeEscape` to accept a configurable digit length, allowing both `\u` (4 digits) and `\U` (8 digits) to share the same parsing logic. Add test cases for valid long escapes, equality with byte-encoded surrogates, and an error test for incomplete long escapes.
This commit is contained in:
Bob Nystrom
2015-10-18 03:07:52 +00:00
4 changed files with 17 additions and 6 deletions
@@ -0,0 +1,2 @@
// expect error line 2
"\U01F603"
+8 -1
View File
@@ -14,4 +14,11 @@ System.print("\u0b83") // expect: ஃ
System.print("\u00B6") // expect: ¶
System.print("\u00DE") // expect: Þ
// TODO: Syntax for Unicode escapes > 0xffff?
// Big escapes:
var smile = "\U0001F603"
var byteSmile = "\xf0\x9f\x98\x83"
System.print(byteSmile == smile) // expect: true
System.print("<\U0001F64A>") // expect: <🙊>
System.print("<\U0001F680>") // expect: <🚀>
System.print("<\U00010318>") // expect: <𐌘>
@@ -0,0 +1,2 @@
// expect error line 2
"\U0060"