Re: Best Way to Append Bytes With Encoding To CFMutableString
Re: Best Way to Append Bytes With Encoding To CFMutableString
- Subject: Re: Best Way to Append Bytes With Encoding To CFMutableString
- From: Greg Parker <email@hidden>
- Date: Wed, 28 Mar 2012 12:24:36 -0700
On Mar 28, 2012, at 11:00 AM, Charles Srstka <email@hidden> wrote:
> Unicode NULL is the least of your problems. In UTF16, each character in the normal ASCII range is going to contain a zero as one of its two bytes (which one, of course, depending on whether the encoding is big- or little-endian). CFStringAppendCString(), along with the other functions that take C strings, stops at the first zero byte it hits, which means that unless your entire file is in a non-Western script, it’s going to get cut short.
>
> CFStringAppendCString() is not what you want if you might be using UTF16.
That's right. The first thing CFStringAppendCString() does is call strlen().
CoreFoundation does have a function internally that would do what you want. You could file a bug report asking for a new API to match. However, it requires almost as much work as using a temporary CFString object anyway, except in some ASCII and UTF-16 cases. I would not expect your CFStringCreateWithBytesNoCopy() solution to be much slower unless you're performing a large number of short appends with one of CFString's preferred encodings.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden