stringByReplacingPercentEscapesUsingEncoding question
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