• 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 encoding problem with extended characters ( AKA : converting NSString to std::string)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)


  • Subject: Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
  • From: Alexander Hartner <email@hidden>
  • Date: Tue, 20 Mar 2007 19:55:33 +0000


On 20 Mar 2007, at 01:19, Ricky Sharp wrote:


On Mar 19, 2007, at 7:54 PM, Alexander Hartner wrote:

I am obtaining a NSString from the iSync API via :

[changeRecord objectForKey:@"first name"]

and I am trying to convert this string into a std::string. I tried using :

std::string * firstName = new std::string([[changeRecord objectForKey:@"first name"] UTF8String]);

which seems to work in most cases, however sometime the string contains characters from the extended character set (>127). I managed to obtain on of these strings and encode is using encoding:NSNonLossyASCIIStringEncoding and ended up with Bj\366rn instead of Björn. After some poking around and trying out many of the other encoding I ended up with the examples at the bottom of this message.

NSNonLossyASCIIStringEncoding uses ASCII7 characters to represent all possible Unicode code points. For all characters with a value above 0x0075, it will use an escaped sequence to represent that char.


I then put together a test program (below) which ended up showing that the string does not support any of the available encoding. This leads me to questions how can I convert the String obtained from the iSync API to a std::string in the correct encoding. I checked the address book and made sure that Björn was entered using the same keyboard combination as the commented line below, to ensure that it's the same character obtained from the literal string and the iSync API. For some reason it didn't work.

[rest snipped]

Why do you need the data to end up in a std::string? The NSString you start with is UTF-16. From there, if you want to save it to a file (I'm guessing UTF-8), you can use writeToFile:atomically:encoding:error:

I need the string to be a std::string to use with gSoap (a C / C++ library for web services).



If you choose to use an encoding other than UTF-xx, you'll end up potentially mangling the data.


___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >NSString encoding problem with extended characters ( AKA : converting NSString to std::string) (From: Alexander Hartner <email@hidden>)
 >Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string) (From: Ricky Sharp <email@hidden>)

  • Prev by Date: [SOLVED] Re: Getting the last date of the month?
  • Next by Date: Re: Releasing an NSManagedObjectContext
  • Previous by thread: Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
  • Next by thread: Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
  • Index(es):
    • Date
    • Thread