toUTFz and WinAPI GetTextExtentPoint32W

zeljkog zeljkog at private.com
Wed Sep 21 09:49:09 PDT 2011


On 21.09.2011 01:57, Christophe wrote:
>
> size_t myCount(string text)
> {
>    size_t n = text.length;
>    for (uint i=0; i<text.length; ++i)
>      {
>        auto s = text[i]>>6;
>        n -= (s>>1) - ((s+1)>>2);
>      }
>    return n;
> }
>

Here is a more readable and a bit faster version on dmd windows:

size_t utfCount(string text)
{
     size_t n = 0;
     for (uint i=0; i<text.length; ++i)
          n += ((text[i]>>6)^0b10)? 1: 0;
     return n;
}


More information about the Digitalmars-d-learn mailing list