Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

strlen() for UTF-8 . . . . . . . . (was Re: Learn a Variety of Languages) [tlug]



Ian MacLean asked: 

> ... so how do you *easily* get a character count for a string of
> utf-8 bytes ?

Call a library function is the proper answer. 

NIH types can roll their own. 
>From the description on the Wikipedia page, 
I figured the following NIH code just for giggles: 

int utf8strlen(unsigned char *s)
{
   int n=0;

   for ( ;*s!='\0';s++)
      if ((*s&0xC0)!=0x80)
         n++;

   return n;
}



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links