Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 77 lines (71 sloc) 4.502 kb
dc5be1c Initial check-in.
uli authored
1 //
2 // UKTextUtilities.m
3 // AngelTemplate
4 //
5 // Created by Uli Kusterer on 17.01.05.
720b0e7 @uliwitness Added licensing information to the source files.
authored
6 // Copyright 2005 Uli Kusterer.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
dc5be1c Initial check-in.
uli authored
26 //
27
28 #import "UKTextUtilities.h"
29
30
31 NSStringEncoding StringEncodingFromName( NSString* encName )
32 {
33 // No encoding? Assume UTF8:
34 if( !encName )
35 return NSUTF8StringEncoding;
36
37 // Build lookup table lazily, but then keep it around so we don't re-build it each time:
38 static NSDictionary* encs = nil;
39 if( !encs )
40 encs = [[NSDictionary alloc] initWithObjectsAndKeys:
41 [NSNumber numberWithInt: NSASCIIStringEncoding], @"ASCII",
42 [NSNumber numberWithInt: NSNEXTSTEPStringEncoding], @"NEXTSTEP",
43 [NSNumber numberWithInt: NSNEXTSTEPStringEncoding], @"NEXTSTEP",
44 [NSNumber numberWithInt: NSJapaneseEUCStringEncoding], @"JapaneseEUC",
45 [NSNumber numberWithInt: NSUTF8StringEncoding], @"UTF8",
46 [NSNumber numberWithInt: NSISOLatin1StringEncoding], @"ISOLatin1",
47 [NSNumber numberWithInt: NSSymbolStringEncoding], @"Symbol",
48 [NSNumber numberWithInt: NSNonLossyASCIIStringEncoding], @"NonLossyASCII",
49 [NSNumber numberWithInt: NSShiftJISStringEncoding], @"ShiftJIS",
50 [NSNumber numberWithInt: NSISOLatin2StringEncoding], @"ISOLatin2",
51 [NSNumber numberWithInt: NSUnicodeStringEncoding], @"Unicode",
52 [NSNumber numberWithInt: NSWindowsCP1251StringEncoding], @"WindowsCP1251",
53 [NSNumber numberWithInt: NSWindowsCP1251StringEncoding], @"Cyrillic",
54 [NSNumber numberWithInt: NSWindowsCP1251StringEncoding], @"AdobeStandardCyrillic",
55 [NSNumber numberWithInt: NSWindowsCP1252StringEncoding], @"CP1252",
56 [NSNumber numberWithInt: NSWindowsCP1252StringEncoding], @"WindowsLatin1",
57 [NSNumber numberWithInt: NSWindowsCP1252StringEncoding], @"WinLatin1",
58 [NSNumber numberWithInt: NSWindowsCP1253StringEncoding], @"CP1253",
59 [NSNumber numberWithInt: NSWindowsCP1253StringEncoding], @"Greek",
60 [NSNumber numberWithInt: NSWindowsCP1254StringEncoding], @"CP1254",
61 [NSNumber numberWithInt: NSWindowsCP1254StringEncoding], @"Turkish",
62 [NSNumber numberWithInt: NSWindowsCP1250StringEncoding], @"CP1250",
63 [NSNumber numberWithInt: NSWindowsCP1250StringEncoding], @"WindowsLatin2",
64 [NSNumber numberWithInt: NSWindowsCP1250StringEncoding], @"WinLatin2",
65 [NSNumber numberWithInt: NSISO2022JPStringEncoding], @"ISO2022JP",
66 [NSNumber numberWithInt: NSMacOSRomanStringEncoding], @"MacOSRoman",
67 [NSNumber numberWithInt: NSMacOSRomanStringEncoding], @"MacRoman",
68 nil ];
69
70 // Get NSStringEncoding for this string:
71 NSNumber* enc = [encs objectForKey: encName];
72 if( enc )
73 return [enc intValue];
74 else
75 return NSUTF8StringEncoding; // Unknown? Use UTF8.
76 }
Something went wrong with that request. Please try again.