• 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: Converting string to encoding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting string to encoding


  • Subject: Re: Converting string to encoding
  • From: "dexter morgan" <email@hidden>
  • Date: Sat, 14 Jun 2008 17:53:53 +0200

What do you think about it? (I've found this in Pantomime framework)
http://pastebin.com/m2a8e4df2

So my code become simple:

NSData *data = [self decodeQuotedPrintableInHeader: NO]; // self is raw data
from file (written in NSISOLatin1)

encoded = [[NSString alloc] initWithData: data encoding:finalEncoding]; //
final encoding is UTF-8 according to headers


However the results of encoded is nil :(


On Sat, Jun 14, 2008 at 5:36 PM, Jens Alfke <email@hidden> wrote:

> I think the problem is here:
>
>             [newString appendFormat:@"%c", (char)character];
>>
>
> This interprets the character as Unicode, since NSString is pure Unicode.
> Then when you ask for the data in ISO-Latin-1, that character gets encoded
> from Unicode to ISO-Latin-1, which changes its numeric value (if it's > 7F).
> But then you read it back into a string as ISO-Latin-1, which will keep the
> changed value, so it's not the character you intended.
>
> I don't think it's best to do this by translating back and forth between
> data and string. It's slow, and there's too much opportunity for encoding
> mistakes like this one. Instead, just leave it as NSData and scan through
> the raw bytes; then convert the unquoted result data directly into the
> desired string encoding.
>
> —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

References: 
 >Converting string to encoding (From: Dex Morgan <email@hidden>)
 >Re: Converting string to encoding (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Converting string to encoding
  • Next by Date: Newbie: applescript "call method" to obj-c method (booleans & image data)
  • Previous by thread: Re: Converting string to encoding
  • Next by thread: checkbox in nstableview
  • Index(es):
    • Date
    • Thread