-
Notifications
You must be signed in to change notification settings - Fork 2
/
CharacterEncoding.m
135 lines (98 loc) · 3.09 KB
/
CharacterEncoding.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// CharacterEncoding.m
// iMusicTags
//
// Created by Kevin Chen on 10-8-24.
// Copyright 2010 KevinChen's workstation. All rights reserved.
//
#import "CharacterEncoding.h"
@implementation CharacterEncoding
@synthesize description;
@synthesize encodingType;
@synthesize encodingCode;
- (id)initWithEncoding:(CFStringEncoding)anEncodingCode desciption:(NSString *)aDescription type:(NSInteger)aType
{
if ([super init]) {
[self setEncodingType:aType];
[self setEncodingCode:anEncodingCode];
[self setDescription:aDescription];
return self;
}
return nil;
}
@end
@implementation CharacterCatalog
- (id)initWithValue:(NSInteger)aValue description:(NSString *)aDescription
{
if ([super init]) {
[self setCatalogType:aValue];
[self setDescription:aDescription];
return self;
}
return nil;
}
+ (NSArray *)catalogs
{
NSMutableArray *catalogs = [[NSMutableArray alloc] init];
// Choose Catalog mention
//[catalogs addObject:[[CharacterCatalog alloc] initWithValue:C_CATALOG_CHOOSE
// description:@" "]];
// Simplified Chinese
[catalogs addObject:[[CharacterCatalog alloc] initWithValue:C_SIMPLIFIED_CHINESE
description:@"Simplified Chinese"]];
// Traditional Chinese
[catalogs addObject:[[CharacterCatalog alloc] initWithValue:C_TRADITIONAL_CHINESE
description:@"Traditional Chinese"]];
return catalogs;
}
@synthesize catalogType;
@synthesize description;
@end
@implementation CharacterEncodingUtil
- (NSArray *)encodings:(NSInteger)catalogType
{
NSArray *encodings = [[NSMutableArray alloc] init];
switch (catalogType) {
case C_SIMPLIFIED_CHINESE:
encodings = [self simplifiedChinese];
break;
case C_TRADITIONAL_CHINESE:
encodings = [self traditionalChinese];
break;
default:
break;
}
return encodings;
}
- (NSArray *)simplifiedChinese
{
NSMutableArray *encodings = [[NSMutableArray alloc] init];
// GB18030
[encodings addObject:[[CharacterEncoding alloc] initWithEncoding:kCFStringEncodingGB_18030_2000
desciption:@"18030"
type:C_SIMPLIFIED_CHINESE]];
// GBK
[encodings addObject:[[CharacterEncoding alloc] initWithEncoding:kCFStringEncodingGBK_95
desciption:@"GBK"
type:C_SIMPLIFIED_CHINESE]];
// GB2312
[encodings addObject:[[CharacterEncoding alloc] initWithEncoding:kCFStringEncodingGB_2312_80
desciption:@"2312"
type:C_SIMPLIFIED_CHINESE]];
return encodings;
}
- (NSArray *)traditionalChinese
{
NSMutableArray *encodings = [[NSMutableArray alloc] init];
[encodings addObject:[[CharacterEncoding alloc] initWithEncoding:kCFStringEncodingBig5
desciption:@"BIG5"
type:C_TRADITIONAL_CHINESE]];
[encodings addObject:[[CharacterEncoding alloc] initWithEncoding:kCFStringEncodingBig5_E
desciption:@"BIG5_E"
type:C_TRADITIONAL_CHINESE]];
[encodings addObject:[[CharacterEncoding alloc] initWithEncoding:kCFStringEncodingBig5_HKSCS_1999
desciption:@"BIG5_HKSCS"
type:C_TRADITIONAL_CHINESE]];
return encodings;
}
@end