[Asterisk-Dev] IAX spec: Text formats and character sets

Michael Giagnocavo mgg-digium at atrevido.net
Fri Apr 29 14:43:02 MST 2005


Hmm, you're right. That's doesn't look bad at all.

But... what about for comparisons and other Unicode operations? Do the
libraries available support some UTF-8 version of strcmp, strchr,
strcasecmp, etc.?

-Michael

-----Original Message-----
From: asterisk-dev-bounces at lists.digium.com
[mailto:asterisk-dev-bounces at lists.digium.com] On Behalf Of Kristian Nielsen
Sent: Friday, April 29, 2005 3:07 PM
To: Asterisk Developers Mailing List
Subject: Re: [Asterisk-Dev] IAX spec: Text formats and character sets

"Michael Giagnocavo" <mgg-digium at atrevido.net> 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   kn at sifira.dk
Development Manager, Sifira A/S

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





More information about the asterisk-dev mailing list