[Asterisk-Dev] IAX spec: Text formats and character sets
    Kevin P. Fleming 
    kpfleming at digium.com
       
    Fri Apr 29 14:34:46 MST 2005
    
    
  
Kristian Nielsen wrote:
>     int utf8cpy(char *dst, const char *src, int size)
>     {
>         int i;
> 
>         if(size <= 0)
>             return -1;
> 
>         for(i = 0; i < size && (dst[i] = src[i]); i++);
> 
>         if(src[i] >= 0x80 && src[i] < 0xc0) {
>             do
>                 i--;
>             while(i > 0 && dst[i] >= 0x80 && dst[i] < 0xc0);
>         }
>         else if(i == size)
>             i--;
> 
>         src[i] = '\0';
>         return i;
>     }
That looks pretty good to me. I'd probably change "int size" "size_t 
size", and eliminate the worry about it being unsigned at the same time.
    
    
More information about the asterisk-dev
mailing list