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

Kevin P. Fleming kpfleming at digium.com
Fri Apr 29 09:09:51 MST 2005


Kristian Nielsen wrote:

> Thus if you are about to truncate an utf-8 string, you should check the
> first byte that is dropped. If this is in the interval 0x80-0xBF, you
> must backtrack until you get past a byte in the interval 0xC0-0xFF.

OK, that is certainly much easier than I expected. Thanks for the UTF-8 
primer :-)

> There should be little performance hit, only loop over a couple of
> characters in the rare case where the string is truncated. In fact I
> would think we would see a big performance gain from using our own
> function instead of strncpy(), since we could use something that only
> copies as many bytes as are in the source string. strncpy() pads the
> destination with zeros, so strncpy(dest, "foo", 100) will copy 100
> bytes, not just the three characters in "foo".

Well, not really "copy" but zero-fill, but yes, I see your point. I've 
always wondered exactly what the point of that was supposed to be...



More information about the asterisk-dev mailing list