• 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: Escape xml with CFXMLCreateStringByEscapingEntities
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Escape xml with CFXMLCreateStringByEscapingEntities
      • From: Wim Lewis <email@hidden>
References: 
 >Escape xml with CFXMLCreateStringByEscapingEntities (From: Claude Saelens <email@hidden>)

  • Prev by Date: Re: drag and drop to the finder
  • Next by Date: I've Got Those NSKeyedUnarchiver Blues!
  • Previous by thread: Escape xml with CFXMLCreateStringByEscapingEntities
  • Next by thread: Re: Escape xml with CFXMLCreateStringByEscapingEntities
  • Index(es):
    • Date
    • Thread