• 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
stringByReplacingPercentEscapesUsingEncoding question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stringByReplacingPercentEscapesUsingEncoding question


  • Subject: stringByReplacingPercentEscapesUsingEncoding question
  • From: Rudi Sherry <email@hidden>
  • Date: Thu, 22 Dec 2005 15:16:36 -0800

I'm working on a project where we get URLs from Japanese Windows XP servers, using ShiftJIS encodings.

In one case, the URL string we get is:

http://foo.com/ベガステスト/マルチメディ% 83A/file.html

I get access to a string, not a URL (I'm using the Cocoa Browser Plug- in in WebKit); the above it what is printed with NSLog. I need to create a URL out of it to fetch it, but:

[ NSURL URLWithString: theString ] returns nil.

[ theString stringByReplacingPercentEscapesUsingEncoding: NSShiftJISStringEncoding ] returns nil.

But this little bit of code returns the correct string:

NSString *strNew = [ theString stringByReplacingPercentEscapesUsingEncoding: NSMacOSRomanStringEncoding ];
const char *cstring = [ strNew cStringUsingEncoding: NSMacOSRomanStringEncoding ];
NSString *strEncoded = [ [ NSString alloc ] initWithBytes: cstring length: strlen(cstring) encoding: NSShiftJISStringEncoding ];

NSLog( strEncoded) prints this:

http://foo.com/繝吶ぎ繧ケ繝繧ケ繝/繝槭Ν繝√Γ繝繧」繧「/file.html

...which matches the Kanji on the Windows server, and:

[ NSURL URLWithString: strEncoded ] creates a URL like this:

http://foo.com/ベガステスト/マルチメデ% 83Bア/file.html

...which correctly fetches the file.

The difference from the first URL is that the '}' and the '`' are now percent-encoded.

I can sort of understand NSURL not wanting to make a URL with the '}' and '`', but I would think that stringByReplacingPercentEscapesUsingEncoding should be smart enough to understand when it un-escapes the first byte of a two-byte glyph, that it should use the second byte whether or not it was escaped.

Is this an accurate assessment of what is happening?

Thanks,
Rudi

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Re: CoreData document based app with single source
  • Next by Date: Re: CoreData, inheritance and plug-ins
  • Previous by thread: Re: The simplest recorder
  • Next by thread: Keychain differences 10.3 vs. 10.4?
  • Index(es):
    • Date
    • Thread