Re: Why is NSString->FSRef so hard?
Re: Why is NSString->FSRef so hard?
- Subject: Re: Why is NSString->FSRef so hard?
- From: Erg Consultant <email@hidden>
- Date: Mon, 27 Apr 2009 21:51:28 -0700 (PDT)
Ok so then it should be working:
1) Forget the STL - the string as read in from the temp file is correct - with the tm where it should be (and shown correctly in the debugger).
2) When I convert it to the NSURL using +fileURLWithPath it works and doesn't return an error - the tm is converted and escaped to the percent-escape chars you mentioned (as shown by CFShow).
3) CFURLGetFSRef returns true and then FSRef appears to contain valid data (I can see the path if I examine its memory).
4) I verified that the file I am trying to open using LSOpenApplication exists at the path the URL points to when it gets converted to an FSRef.
So why isn't it working? Why does LSOpenApplication give me an error?
Erg
________________________________
From: Ken Thomases <email@hidden>
To: Erg Consultant <email@hidden>
Cc: email@hidden
Sent: Monday, April 27, 2009 9:41:01 PM
Subject: Re: Why is NSString->FSRef so hard?
On Apr 27, 2009, at 11:26 PM, Erg Consultant wrote:
> One other thing I should mention - the mangled char in question is the tm symbol (option-2). In its string form, the debugger shows it as the tm char.
>
> But when I convert the string to an NSURL using fileURLWithPath, and then do a CFShow, the tm is converted to *three* hex chars:
>
> ™
Right. This is to be expected. Not all characters are legal within URLs. So, URLs have to be escaped. The trademark character in UTF-8 encoding is the byte sequence 0xE2, 0x84, 0xA2. Yes, three bytes. Those bytes are then escaped using percent-sign-hex-value to make them safe for a URL.
I strongly suspect your problems and your confusion about the results you're seeing are because you aren't understanding the subject of string encoding. You appear to be blindly stabbing in the dark, trying to guess why things work or don't. As somebody earlier in the thread pointed out, STL strings are not encoding aware. If you don't know the encoding of the bytes that you used to initialize those STL strings, then you're not going to have any luck interpreting them, writing them sanely to a file in a consistent way, nor reading them back in.
> Are NSURL and CFURL not toll-free bridged?
They are toll-free bridged. What about the above made you think otherwise?
Regards,
Ken
_______________________________________________
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