Challenge: write a really really small front() for UTF8

anonymous anon at ymous.net
Tue Mar 25 11:57:03 PDT 2014


dchar front(char[] s) {
   dchar c = s[0];
   if (!(c & 0x80))
     return c;
   byte b = (c >> 4) & 3;
   b += !b;
   c &= 63 >> b;
   char *p = s.ptr;
   do {
     p++;
     c = c << 6 | *p & 63;
   } while(--b);
   return c;
}


More information about the Digitalmars-d mailing list