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:14:00 -0700 (PDT)
I write the original STL string to a tmp file, then read it back in. The file is encoded in MacRoman. I tried UTF8 with both converting and reinterpreting but if I use UTF8 when I read it back from file, the read returns nil. If I use MacRoman, the string reads back fine, but when I go to convert it to the URL and then the FSSpec, the FSSpec is invalid and cannot be used byLSOpenApplication
Here are the snippets:
exePathString = [ NSString stringWithContentsOfFile:kTempQuagmireHackFilePathNSString
encoding:NSMacOSRomanStringEncoding
error:&inError ]; // <- Works
....
urlRef = [ NSURL fileURLWithPath:exePathString ]; // <- Works
converted = CFURLGetFSRef( (CFURLRef)urlRef, &exeRef ); // <- Works
inAppParams.application = &exeRef; // I also zero out the whole block before this.
err = LSOpenApplication( &inAppParams, &outPSN ); // <- Fails with -10810 error - Unexpected internal error
________________________________
From: Steve Christensen <email@hidden>
To: Erg Consultant <email@hidden>
Cc: email@hidden
Sent: Saturday, April 25, 2009 6:04:14 PM
Subject: Re: Why is NSString->FSRef so hard?
You'd said in an earlier thread that the file path characters are coming from a text file and that you're then storing those in a STL string. The STL string doesn't care what the encoding is since it's just a storage construct. When you try to create a CFString or NSString from those characters, you need to know what the character encoding is, particularly for the case where a path contains special (non-ASCII) characters, otherwise the CFStringCreate*() or [NSString stringWith*:] calls will fail. If those fail then you won't be able to successfully create a CFURL/NSURL, so CFURLGetFSRef will naturally fail.
Since you haven't been able (so far) to determine what the character encoding is, have you thought about reading in the characters from the file, displaying each character in hex, and finding the value(s) that represent one of the non-ASCII characters? With those values in hand you should be able to do some online research to determine what the character encoding actually is. Once you get past that part, everything else should just work.
On Saturday, April 25, 2009, at 05:28PM, "Erg Consultant" <email@hidden> wrote:
>I was using CFURLGetFSRef passing in the NSString which works fine as long as the path contains no special chars. If it does, CFURLGetFSRef returns nil.
>
>Erg
>
>________________________________
>From: Nick Zitzmann <email@hidden>
>To: Erg Consultant <email@hidden>
>Cc: email@hidden
>Sent: Saturday, April 25, 2009 4:41:20 PM
>Subject: Re: Why is NSString->FSRef so hard?
>
>
>On Apr 25, 2009, at 5:33 PM, Erg Consultant wrote:
>
>> Isn't there some easy way to get an FSRef from an NSString that is a path containing special characters?
>
>
>What, specifically, have you tried? I don't think I've ever had +fileURLWithPath: fail on me with a path string, even if the string contained non-ASCII characters.
_______________________________________________
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