[Toybox] unicode.c question.

Rob Landley rob at landley.net
Sat May 15 10:37:31 PDT 2021


Elliott, is it worth testing for invalid unicode range in the display, ala:

--- a/toys/other/ascii.c
+++ b/toys/other/ascii.c
@@ -44,7 +44,8 @@ static void codepoint(unsigned wc)
   char *s = toybuf + sprintf(toybuf, "U+%04X : ", wc), *ss;
   unsigned n, i;

-  if (wc>31 && wc!=127) {
+  if ((wc>0xd7ff && wc<0xe000) || wc>0x10ffff) s += sprintf(s, "invalid");
+  else if (wc>31 && wc!=127) {
     s += n = wctoutf8(ss = s, wc);
     if (n>1) for (i = 0; i<n; i++) s += sprintf(s, " : %#02x"+2*!!i, *ss++);
   } else s = memcpy(s, (wc==127) ? "DEL" : low+wc*3, 3)+3;


Rob



More information about the Toybox mailing list