• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Best Way to Append Bytes With Encoding To CFMutableString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best Way to Append Bytes With Encoding To CFMutableString


  • Subject: Re: Best Way to Append Bytes With Encoding To CFMutableString
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Wed, 28 Mar 2012 21:52:11 +0200

Le 28 mars 2012 à 20:00, Charles Srstka a écrit :

> On Mar 28, 2012, at 9:55 AM, email@hidden wrote:
>
>> On 28 Mar 2012, at 15:35, Andreas Grosam wrote:
>>
>>>
>>> On Mar 28, 2012, at 3:58 PM, email@hidden wrote:
>>>>>
>>>> I presume that you considered CFStringAppendCString():
>>>>
>>>> void CFStringAppendCString (
>>>> CFMutableStringRef theString,
>>>> const char *cStr,
>>>> CFStringEncoding encoding
>>>> );
>>>>
>>>
>>>
>>> Yes, but:
>>>
>>> Can I use any code-unit, even so the function indicates that only "char" is allowed? What, if I have uint32_t or uint16_t code-unit types? (I guess, I can use them anyway after a type cast.) The description is not clear about this, though.
>> The fact that the function supports encoding presumably entails support for non char code-unit types.
>> If not, this is a pretty sterile function.
>>
>>>
>>> Also, consider that Unicode NULL (U+0000) is a regular character in Unicode - which conflicts with C strings which shall be zero terminated.
>> A valid point. I don't know how the Unicode NULL is generally used in practice.
>
> 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.
>
> CFAppendCString() is not what you want if you might be using UTF16.


If you have an UTF-16 buffer, I think you can just use CFStringAppendCharacters().

-- Jean-Daniel





_______________________________________________

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


References: 
 >Best Way to Append Bytes With Encoding To CFMutableString (From: Andreas Grosam <email@hidden>)
 >Re: Best Way to Append Bytes With Encoding To CFMutableString (From: "email@hidden" <email@hidden>)
 >Re: Best Way to Append Bytes With Encoding To CFMutableString (From: Andreas Grosam <email@hidden>)
 >Re: Best Way to Append Bytes With Encoding To CFMutableString (From: "email@hidden" <email@hidden>)
 >Re: Best Way to Append Bytes With Encoding To CFMutableString (From: Charles Srstka <email@hidden>)

  • Prev by Date: Re: Best Way to Append Bytes With Encoding To CFMutableString
  • Next by Date: Can't receive a scrollWheel message in a PDFView subclass
  • Previous by thread: Re: Best Way to Append Bytes With Encoding To CFMutableString
  • Next by thread: How to use NSArchiver with ARC?
  • Index(es):
    • Date
    • Thread