"Michael Giagnocavo" <[EMAIL PROTECTED]> writes:

> While the performance hit might not be large and the code for UTF-8 simple,
> relative to strncpy, which is a small, very tight, function, the additional
> code would be quite large.

Well maybe I should just show some code to make things clearer (untested):

    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;
    }

 - Kristian.

-- 
Kristian Nielsen   [EMAIL PROTECTED]
Development Manager, Sifira A/S

_______________________________________________
Asterisk-Dev mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-dev
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

Reply via email to