File name encoding problem
File name encoding problem
- Subject: File name encoding problem
- From: Thomas Hartwich <email@hidden>
- Date: Mon, 19 Sep 2005 12:37:45 +0200
Hi all,
I have a problem figuring out how to match file names returned from
NSFileManger with file names found in a UTF8 encoded XML file.
NSFileManger returns something different from UTF8, but so far I have not
been successful to match the encodings.
I have set my editor in XCode to UTF8 encoding, so the display looks ok.
Here is the dource code, with a few things I tried:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int test1 = 0, test2 = 0;
NSFileManager* fmgr = [NSFileManager defaultManager];
NSMutableSet* settingsToRemove = [NSMutableSet setWithObjects:
[NSString stringWithUTF8String:"High Quality.joboptions"],
[NSString stringWithUTF8String:"Press Quality.joboptions"],
[NSString stringWithUTF8String:"Smallest File Size.joboptions"],
[NSString stringWithUTF8String:"Standard.joboptions"],
[NSString stringWithUTF8String:"Qualit© presse.joboptions"],
[NSString stringWithUTF8String:"Qualit© standard.joboptions"],
[NSString stringWithUTF8String:"Qualit© sup©rieure.joboptions"],
[NSString stringWithUTF8String:"Taille de fichier
minimale.joboptions"],
nil];
NSLog(@"objects: %d",[settingsToRemove count]);
NSEnumerator *enumerator1 = [settingsToRemove objectEnumerator];
NSString* inSet;
while (inSet = [enumerator1 nextObject]) {
NSLog(@"inSet: %@", inSet );
inSet = [inSet decomposedStringWithCanonicalMapping];
NSLog(@"inSet1: %@", inSet );
inSet = [fmgr stringWithFileSystemRepresentation:[inSet
fileSystemRepresentation] length:[inSet length]];
NSLog(@"inSet2: %@", inSet );
} // end while
NSString* myPath = @"/Users/Shared/Adobe PDF 6.0/Settings";
NSArray* files = [fmgr directoryContentsAtPath:myPath];
NSEnumerator *enumerator = [files objectEnumerator];
NSString* fileObj;
while (fileObj = [enumerator nextObject]) {
NSLog(@"file: %@", fileObj );
if ([settingsToRemove containsObject:fileObj]) {
NSLog(@"found file to remove: %@", fileObj );
test2++;
} // end if
} // end while
test1 = [settingsToRemove count];
NSLog(@"found files: %d", test2 );
[pool release];
return 0;
}
And here is the output from the run log:
Running
2005-09-19 12:27:26.804 testFSnames[693] objects: 8
2005-09-19 12:27:26.805 testFSnames[693] inSet: Qualité
supérieure.joboptions
2005-09-19 12:27:26.806 testFSnames[693] inSet1: Qualité
supérieure.joboptions
2005-09-19 12:27:26.806 testFSnames[693] inSet2: Qualité supérieure.joboptio
2005-09-19 12:27:26.806 testFSnames[693] inSet: Taille de fichier
minimale.joboptions
2005-09-19 12:27:26.806 testFSnames[693] inSet1: Taille de fichier
minimale.joboptions
2005-09-19 12:27:26.806 testFSnames[693] inSet2: Taille de fichier
minimale.joboptions
2005-09-19 12:27:26.806 testFSnames[693] inSet: Standard.joboptions
2005-09-19 12:27:26.806 testFSnames[693] inSet1: Standard.joboptions
2005-09-19 12:27:26.806 testFSnames[693] inSet2: Standard.joboptions
2005-09-19 12:27:26.806 testFSnames[693] inSet: High Quality.joboptions
2005-09-19 12:27:26.806 testFSnames[693] inSet1: High Quality.joboptions
2005-09-19 12:27:26.806 testFSnames[693] inSet2: High Quality.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet: Press Quality.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet1: Press Quality.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet2: Press Quality.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet: Smallest File
Size.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet1: Smallest File
Size.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet2: Smallest File
Size.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet: Qualité presse.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet1: Qualité presse.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet2: Qualité presse.joboption
2005-09-19 12:27:26.807 testFSnames[693] inSet: Qualité standard.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet1: Qualité standard.joboptions
2005-09-19 12:27:26.807 testFSnames[693] inSet2: Qualité standard.joboption
2005-09-19 12:27:26.824 testFSnames[693] file: AcroEFGDistSelfHeal.xml
Pending breakpoint 1 - ""testFSnames.m:37" resolved
Printing description of files:
<CFArray 0x31b060 [0xa0728150]>{type = mutable-small, count = 17, values = (
0 : <CFString 0x31b690 [0xa0728150]>{contents =
"AcroEFGDistSelfHeal.xml"}
1 : <CFString 0x31b6c0 [0xa0728150]>{contents =
"DT_Settings_Archiv.zip"}
2 : <CFString 0x31b710 [0xa0728150]>{contents = "High
Quality.joboptions"}
3 : <CFString 0x31b740 [0xa0728150]>{contents = "Hohe
Qualita\u0308t.joboptions"}
4 : <CFString 0x31b780 [0xa0728150]>{contents = "Kleinste
Dateigro\u0308\u00dfe.joboptions"}
5 : <CFString 0x31b7d0 [0xa0728150]>{contents =
"PDF_Settings_Archiv.zip"}
6 : <CFString 0x31b070 [0xa0728150]>{contents = "PDFX1a.joboptions"}
7 : <CFString 0x31b850 [0xa0728150]>{contents = "PDFX3.joboptions"}
8 : <CFString 0x31b870 [0xa0728150]>{contents =
"PrePress-Qualita\u0308t.joboptions"}
9 : <CFString 0x31b6e0 [0xa0728150]>{contents = "Press
Quality.joboptions"}
10 : <CFString 0x31b8c0 [0xa0728150]>{contents = "Qualite\u0301
presse.joboptions"}
11 : <CFString 0x31b900 [0xa0728150]>{contents = "Qualite\u0301
standard.joboptions"}
12 : <CFString 0x31b950 [0xa0728150]>{contents = "Qualite\u0301
supe\u0301rieure.joboptions"}
13 : <CFString 0x31b9a0 [0xa0728150]>{contents = "Smallest File
Size.joboptions"}
14 : <CFString 0x31ba60 [0xa0728150]>{contents = "Standard.joboptions"}
15 : <CFString 0x31b800 [0xa0728150]>{contents =
"Standardqualita\u0308t.joboptions"}
16 : <CFString 0x31ba80 [0xa0728150]>{contents = "Taille de fichier
minimale.joboptions"}
)}
Printing description of settingsToRemove:
<CFSet 0x3047e0 [0xa0728150]>{type = mutable, count = 8, capacity = 8, pairs
= (
0 : <CFString 0x304610 [0xa0728150]>{contents = "Qualit\u00e9
sup\u00e9rieure.joboptions"}
1 : <CFString 0x304660 [0xa0728150]>{contents = "Taille de fichier
minimale.joboptions"}
5 : <CFString 0x304560 [0xa0728150]>{contents = "Standard.joboptions"}
6 : <CFString 0x303c70 [0xa0728150]>{contents = "High
Quality.joboptions"}
7 : <CFString 0x304500 [0xa0728150]>{contents = "Press
Quality.joboptions"}
8 : <CFString 0x304530 [0xa0728150]>{contents = "Smallest File
Size.joboptions"}
9 : <CFString 0x304580 [0xa0728150]>{contents = "Qualit\u00e9
presse.joboptions"}
10 : <CFString 0x3045c0 [0xa0728150]>{contents = "Qualit\u00e9
standard.joboptions"}
)}
(gdb) continue
Current language: auto; currently objective-c
2005-09-19 12:28:28.490 testFSnames[693] file: DT_Settings_Archiv.zip
(gdb) continue
2005-09-19 12:28:57.601 testFSnames[693] file: High Quality.joboptions
2005-09-19 12:28:57.618 testFSnames[693] found file to remove: High
Quality.joboptions
2005-09-19 12:28:57.634 testFSnames[693] file: Hohe Qualität.joboptions
2005-09-19 12:28:57.650 testFSnames[693] file: Kleinste
Dateigröße.joboptions
2005-09-19 12:28:57.665 testFSnames[693] file: PDF_Settings_Archiv.zip
2005-09-19 12:28:57.697 testFSnames[693] file: PDFX1a.joboptions
2005-09-19 12:28:57.698 testFSnames[693] file: PDFX3.joboptions
2005-09-19 12:28:57.698 testFSnames[693] file: PrePress-Qualität.joboptions
2005-09-19 12:28:57.698 testFSnames[693] file: Press Quality.joboptions
2005-09-19 12:28:57.699 testFSnames[693] found file to remove: Press
Quality.joboptions
2005-09-19 12:28:57.699 testFSnames[693] file: Qualité presse.joboptions
2005-09-19 12:28:57.699 testFSnames[693] file: Qualité standard.joboptions
2005-09-19 12:28:57.699 testFSnames[693] file: Qualité supérieure.joboptions
2005-09-19 12:28:57.699 testFSnames[693] file: Smallest File Size.joboptions
2005-09-19 12:28:57.703 testFSnames[693] found file to remove: Smallest File
Size.joboptions
2005-09-19 12:28:57.703 testFSnames[693] file: Standard.joboptions
2005-09-19 12:28:57.703 testFSnames[693] found file to remove:
Standard.joboptions
2005-09-19 12:28:57.703 testFSnames[693] file: Standardqualität.joboptions
2005-09-19 12:28:57.703 testFSnames[693] file: Taille de fichier
minimale.joboptions
2005-09-19 12:28:57.704 testFSnames[693] found file to remove: Taille de
fichier minimale.joboptions
2005-09-19 12:28:57.704 testFSnames[693] found files: 5
Debugger stopped.
Program exited with status value:0.
I am probably overlooking something obvious. Please point me into the right
direction.
Thanks in advance
Thomas Hartwich
_______________________________________________
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