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

Anonymous anon at ymous.net
Sun Mar 23 16:28:49 PDT 2014


dchar front(char[] s) {
     uint c = s[0];
     ubyte p = ~s[0];
     if (p>>7)
       return c;
     c = c<<8 | s[1];
     if (p>>5)
       return c;
     c = c<<8 | s[2];
     if (p>>4)
       return c;
     return c<<8 | s[3];
}


More information about the Digitalmars-d mailing list