Re: Escape xml with CFXMLCreateStringByEscapingEntities
Re: Escape xml with CFXMLCreateStringByEscapingEntities
- Subject: Re: Escape xml with CFXMLCreateStringByEscapingEntities
- From: Jens Alfke <email@hidden>
- Date: Sun, 04 Dec 2011 10:42:46 -0800
On Dec 1, 2011, at 12:19 AM, Claude Saelens wrote:
> NSMutableString *aNSString = [NSMutableString stringWithString:xmlString];
> CFStringRef aCFString;
> CFStringRef bCFString;
> aCFString = CFStringCreateWithCString(NULL, [aNSString UTF8String], NSUTF8StringEncoding);
“NSUTF8StringEncoding” is wrong here — you’re passing it to a CF function, which for some reason has its own different set of constants for string encodings, so you’re telling it the wrong encoding. It should be kCFStringEncodingUTF8.
Except actually you don’t need these lines at all. It looks like you’re trying to convert an NSString to a CFString through a whole bunch of conversions; but all this takes is a simple cast:
CFStringRef aCFString = (CFStringRef) xmlString;
And vice versa, converting CF to NS basically just takes a cast, but you want to (a) inform the garbage collector if any that you’re doing this, and (b) autorelease the string so it won’t be leaked:
NSString* returnValue = [NSMakeCollectable(bCFString) autorelease];
—Jens_______________________________________________
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