Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
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: "Clark Cox" <email@hidden>
- Date: Tue, 20 Mar 2007 14:31:31 -0700
On 3/20/07, Alexander Hartner <email@hidden> wrote:
On 20 Mar 2007, at 01:54, Clark Cox wrote:
> On 3/19/07, Alexander Hartner <email@hidden> 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]);
>>
>
> This is the only reasonable way to do it without losing data.
But how can i convert this into a properly formed std::string then.
When I use this method it causes problem during the construction of a
std::string.
It *is* a properly formed std::string.
>
>> which seems to work in most cases, however sometime the string
>> contains characters from the extended character set (>127).
>
> You'll have to define "work".
however sometime the string
contains characters from the extended character set (>127) in which
case they are strangely encoded.
>
> [snip]
>
>> NSString * two = @"Björn";
>
> The @"..." syntax does not support non-ASCII characters. In a real
> program, I would recommend using strings loaded from *.strings files.
> But since this is a throwaway test program, use this:
>
> NSString *two = [NSString stringWithUTF8String: "Bj\xC3\xB6rn"];
>
I tried this and it produced the same result as the string i receive
from the iSync API. Using a literal "Björn" inside my code produces a
warning but it does work correctly.
You cannot count on this. Don't do it.
By this I mean that I am able to
construct a std::string and using the gSAOP library pass it correctly
formatted.
What encoding is the library expecting?
I was hoping that there would be a way to reproduce this
behaviour started out from a [NSString stringWithUTF8String: "Bj\xC3
\xB6rn"] rather then a @"Björn". From what I gather from your
comments there is not.
--
Clark S. Cox III
email@hidden
_______________________________________________
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