[Asterisk-Dev] IAX spec: Text formats and character sets
Kristian Nielsen
kn at sifira.dk
Fri Apr 29 14:06:37 MST 2005
"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
More information about the asterisk-dev
mailing list