Re: Unicode in URLs (was "Handling framework exceptions/errors?")
Re: Unicode in URLs (was "Handling framework exceptions/errors?")
- Subject: Re: Unicode in URLs (was "Handling framework exceptions/errors?")
- From: "Stephen J. Butler" <email@hidden>
- Date: Sun, 29 Jun 2008 16:42:46 -0500
On Sun, Jun 29, 2008 at 3:10 PM, David Troy <email@hidden> wrote:
> I was sort of under the impression that NSURL URLWithString: would deal with
> escaping/translating the Kanji characters, but I could see how it might not.
>
> Is there some method I can use to break the Kanji back out into escaped
> characters before passing it to NSURL URLWithString: ?
The problem is that NSURL doesn't know what encoding scheme to use
when escaping the kanji. Most modern applications expect UTF-8, but
it's possible you need Japanese EUC or Shift_JIS. When you know what
encoding you want to use, pass the string through -[NSString
stringByAddingPercentEscapesUsingEncoding:].
But as someone else hinted, this doesn't fix japanese domain names.
There is, unfortunately, no built in support for punycode, and
-[NSString stringByAddingPercentEscapesUsingEncoding:] will completely
mug your hostname. In this case, you need a more complex scheme to
handle URL strings. Probably break apart the URL into its pieces,
encode the hostname and path separately, and then put it back together
with -[NSURL initWithScheme:host:path:].
_______________________________________________
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