Re: NSString vs. encoding
Re: NSString vs. encoding
- Subject: Re: NSString vs. encoding
- From: Andrew Farmer <email@hidden>
- Date: Thu, 17 Sep 2009 22:29:50 -0700
On 16 Sep 2009, at 22:55, Johan Kool wrote:
Thanks so much!! That is indeed the case! I now use strunvis and
it's all done in just 4 lines of code. (Well, except that I should
still handle a returned error code.)
int len = [stringA
lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
char dst[len];
strunvis(&dst, [stringA UTF8String]);
return [NSString stringWithUTF8String:dst];
Not to burst your bubble, but that doesn't look quite right. It fails
in the case where stringA contains no escaped characters (including
the case where it's empty) -- the terminating null byte isn't counted
by lengthOfBytesUsingEncoding:, so it ends up writing one byte off the
end of dst[].
_______________________________________________
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