Re: Filename encodings
Re: Filename encodings
- Subject: Re: Filename encodings
- From: "Mark A. Stratman" <email@hidden>
- Date: Sat, 10 Jul 2004 23:09:51 -0500
Would it be safe to just use NSUTF8StringEncoding? Or are their
problems with that as well, that I'm not aware of?
I've always used UTF8-encoded strings and have never had a problem with
any languages.
-mark
On Jul 10, 2004, at 10:38 PM, Tito Ciuro wrote:
Hello Adam,
If I understand correctly, I believe you should let the OS handle that
by using any of the following methods:
NSString's - (const char *)fileSystemRepresentation
NSFileManager's - (const char
*)fileSystemRepresentationWithPath:(NSString *)path
I hope this helps,
-- Tito
On 10 jul 2004, at 20:49, Adam Maxwell wrote:
I've written a program to do find and replace on a list of filenames.
It works quite well, but testing revealed problems with accented
characters such as i in a filename. I've come up with a workaround,
but I don't understand why it's necessary, and am curious if I'm
missing something.
I run an NSOpenPanel, allow multiple file selection, get the selected
file list as an NSArray, and send it to this method:
- (void)buildPathsArrayWithArray:(NSArray *)array{
NSEnumerator *e = [array objectEnumerator];
NSMutableDictionary *dict = [NSMutableDictionary
dictionaryWithCapacity:2];
NSString *oldPath = nil;
NSString *encodedPath = nil;
NSData *data;
while(oldPath = [e nextObject]){
data = [oldPath dataUsingEncoding:NSMacOSRomanStringEncoding];
encodedPath = [[[NSString alloc] initWithData:data
encoding:NSMacOSRomanStringEncoding] autorelease];
// NSLog(@"encodedPath is %@", encodedPath);
[dict setObject:encodedPath forKey:@"Old Path"];
[dict setObject:@"" forKey:@"New Path"];
... do more stuff...
[pathsArray addObject:[dict copy]];
[dict removeAllObjects];
}
}
Unless I use NSMacOSRomanStringEncoding, things don't work right (I'm
using the AGRegex framework for find/replace). I originally used the
oldPath variable directly, and for a filename of "iagSGAMMA" (randomly
chosen), my [pathsArray description] gave
"e\U0301a\U0301c\U0327SGAMMA". After my NSMacOSRomanStringEncoding
stuff, the array has "\U00e9\U00e1\U00e7SGAMMA" which actually works.
Has anyone else run across this, or know of a better way to handle it?
thanks,
Adam Maxwell
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.