Re: NUL characters in NSString cause unexpected results
Re: NUL characters in NSString cause unexpected results
- Subject: Re: NUL characters in NSString cause unexpected results
- From: Scott Stevenson <email@hidden>
- Date: Wed, 22 Nov 2006 20:01:21 -0800
On Nov 22, 2006, at 6:33 PM, Jerry Krinock wrote:
Every reference I can find on UTF8 states that any valid ASCII
character is
a valid UTF8 character, so this should include the ASCII 'NUL',
0x0. But
when I init an NSString from data including a NUL, using UTF8
encoding, and
then send some messages to it, most messages behave as though the
string
terminates at the NUL.
To be fair, the class reference for NSString is pretty upfront about
this:
-initWithBytes:length:encoding:
Returns an initialized NSString object containing a given number of
bytes from
a given C array of bytes in a given encoding.
bytes: A C array of bytes in the encoding specified by encoding. The
array
must not contain NULL.
<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
Classes/NSString_Class/Reference/NSString.html>
If some nasty person puts an ASCII 0x0 NUL in the file, it flows
right through to my NSString and causes problems
later.
You might need to just preprocess the text.
- Scott
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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