commit 0143efaaea792ce6a6d078fd5cf5fa4ec427565b
parent bc83768eb33352af1631bcefcab9762993be982f
Author: xplshn <anto@xplshn.com.ar>
Date: Thu, 26 Nov 2026 11:46:40 -0300
cc reads \u and \U escapes
Diffstat:
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/cmd/dev/cc/expr.c b/cmd/dev/cc/expr.c
@@ -644,6 +644,21 @@ decodechar(
c = '\v';
++s;
break;
+ case 'u':
+ case 'U':
+ /* a universal character name names a code point, written as a
+ * character of the literal's encoding would be */
+ n = *s == 'u' ? 4 : 8;
+ ++s;
+ c = 0;
+ while (n-- > 0) {
+ v = hexval(*s++);
+ assert(v >= 0);
+ c = c * 16 + v;
+ }
+ if (c > 0x10ffff || (c >= 0xd800 && c <= 0xdfff))
+ error(loc, "%s names %#lx, which is no character", desc, (unsigned long)c);
+ break;
case 'x':
++s;
c = 0;
diff --git a/cmd/dev/cc/scan.c b/cmd/dev/cc/scan.c
@@ -194,6 +194,16 @@ escape(struct scanner *s)
if (isodigit(s->chr))
nextchar(s);
}
+ } else if (s->chr == 'u' || s->chr == 'U') {
+ /* a universal character name: four or eight hexadecimal digits */
+ int n = s->chr == 'u' ? 4 : 8;
+
+ nextchar(s);
+ while (n-- > 0) {
+ if (!isxdigit(s->chr))
+ error(&s->loc, "invalid universal character name");
+ nextchar(s);
+ }
} else if (strchr("'\"?\\abfnrtv", s->chr)) {
nextchar(s);
} else {