• 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: NSString vs. encoding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString vs. encoding


  • Subject: Re: NSString vs. encoding
  • From: Johan Kool <email@hidden>
  • Date: Fri, 18 Sep 2009 17:30:00 -0700


Op 17 sep 2009, om 22:29 heeft Andrew Farmer het volgende geschreven:

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[].


Ok, thanks for pointing that out. I'll just increase len by 1, that way it should always fit.

Johan

---
http://www.johankool.nl/

KOOLISTOV - Software for Mac and iPhone
http://www.koolistov.net/




_______________________________________________

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: 
 >Re: NSString vs. encoding (From: Greg Guerin <email@hidden>)
 >Re: NSString vs. encoding (From: Johan Kool <email@hidden>)
 >Re: NSString vs. encoding (From: Joar Wingfors <email@hidden>)
 >Re: NSString vs. encoding (From: Johan Kool <email@hidden>)
 >Re: NSString vs. encoding (From: Joar Wingfors <email@hidden>)
 >Re: NSString vs. encoding (From: Johan Kool <email@hidden>)
 >Re: NSString vs. encoding (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: Static Analyzer and Core Foundation
  • Next by Date: Re: If someone could inspect this code and explain to me what am I doing wrong ?
  • Previous by thread: Re: NSString vs. encoding
  • Next by thread: Re: NSString vs. encoding
  • Index(es):
    • Date
    • Thread