1 /* Copyright (c) 2009 Glenn Ganz
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
10 #import <Foundation/NSString_defaultEncoding.h>
11 #import <Foundation/NSException.h>
17 NSStringEncoding defaultEncoding()
19 //don't use objc calls because they call often defaultCStringEncoding
21 static int defaultEncoding = -1;
23 if (defaultEncoding == -1) {
24 static struct passwd *pwent = NULL;
25 char filename[255] = {0};
28 pwent = getpwuid(getuid());
30 strcpy(filename, pwent->pw_dir);
31 strcat(filename, "/.CFUserTextEncoding");
33 fhandle = fopen(filename, "r");
37 fscanf (fhandle,"%X",&enc);
42 defaultEncoding = NSMacOSRomanStringEncoding;
45 defaultEncoding = NSWindowsCP1252StringEncoding;
48 defaultEncoding = NSISOLatin1StringEncoding;
51 defaultEncoding = NSISOLatin2StringEncoding;
52 // FIXME: use until the right encoding is implemented
53 defaultEncoding = NSISOLatin1StringEncoding;
56 defaultEncoding = NSNEXTSTEPStringEncoding;
59 defaultEncoding = NSASCIIStringEncoding;
62 defaultEncoding = NSUnicodeStringEncoding;
63 // FIXME: use until the right encoding is implemented
64 defaultEncoding = NSISOLatin1StringEncoding;
67 defaultEncoding = NSUTF8StringEncoding;
68 // FIXME: use until the right encoding is implemented
69 defaultEncoding = NSISOLatin1StringEncoding;
72 defaultEncoding = NSNonLossyASCIIStringEncoding;
73 // FIXME: use until the right encoding is implemented
74 defaultEncoding = NSISOLatin1StringEncoding;
77 defaultEncoding = NSShiftJISStringEncoding;
78 // FIXME: use until the right encoding is implemented
79 defaultEncoding = NSISOLatin1StringEncoding;
82 defaultEncoding = NSJapaneseEUCStringEncoding;
83 // FIXME: use until the right encoding is implemented
84 defaultEncoding = NSISOLatin1StringEncoding;
87 defaultEncoding = NSMacOSRomanStringEncoding;
92 if(defaultEncoding == -1) {
93 defaultEncoding = NSMacOSRomanStringEncoding;
97 return defaultEncoding;