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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Mar 23 17:01:27 PDT 2014


On 3/23/14, 4:28 PM, Anonymous wrote:
> 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];
> }

That's smaller but doesn't seem to do the same!

Andrei



More information about the Digitalmars-d mailing list