Re: Unicode filename and FSPathMakeRef
Re: Unicode filename and FSPathMakeRef
- Subject: Re: Unicode filename and FSPathMakeRef
- From: Finlay Dobbie <email@hidden>
- Date: Thu, 3 Jan 2002 20:26:03 +0000
On Thursday, January 3, 2002, at 04:51 am, Johnny CN Lee wrote:
I use FSPathMakeRef to convert a NSString filename to FSRef. How
should I
convert a unicode filename (Chinese or Japanese) to a (const UInt8 *)
buffer
for FSPathMakeRef to use properly? I've tried NSString's CString and
UTF8String, but failed.
Just to take a new approach other than the ones that have been suggested
here, you could do something along the lines of this:
// assume myString is something proper
FSRef myRef;
NSURL *myURL = [NSURL fileURLWithPath:myString];
if (!CFURLGetFSRef((CFURLRef)myURL, &myRef)) {
// handle error
}
And to go backwards:
// assume myRef is valid
CFURLRef myURL = CFURLCreateFromFSRef(kCFAllocatorDefault, &myRef);
NSString *myString = (NSString *)CFURLCopyPath(myURL);
CFRelease(myURL);
// remember to release myString
-- Finlay