1 /**
2  * 
3  *
4  * License: BSD 3-clause
5  */
6 module libguess_d.encoding;
7 
8 
9 private static import libguess_d.dfa;
10 private static import libguess_d.guess.table.common_table;
11 
12 static import libguess_d.dfa;
13 
14 public:
15 
16 /**
17  *
18  */
19 enum libguess_encoding
20 {
21 	undefined,
22 	BIG5,
23 	CP1251,
24 	CP1253,
25 	CP1254,
26 	CP1255,
27 	CP1256,
28 	CP866,
29 	EUC_JP,
30 	EUC_KR,
31 	GB2312,
32 	GB18030,
33 	ISO_2022_CN,
34 	ISO_2022_JP,
35 	ISO_2022_KR,
36 	ISO_2022_TW,
37 	ISO_8859_6,
38 	ISO_8859_7,
39 	ISO_8859_8_I,
40 	ISO_8859_9,
41 	JOHAB,
42 	KOI8_R,
43 	SJIS,
44 	UCS_2BE,
45 	UCS_2LE,
46 	UTF_8,
47 	UTF_16,
48 	UTF_32,
49 }
50 
51 /**
52  *
53  */
54 enum supported_lang
55 {
56 	ar,
57 	cn,
58 	gr,
59 	hw,
60 	ja,
61 	kr,
62 	ru,
63 	tr,
64 	tw,
65 }
66 
67 /**
68  * 
69  *
70  * Params:
71  *      input = input encoding
72  *
73  * Returns: Character encoding or null
74  */
75 pure nothrow @safe @nogc
76 string encoding_name(bool WITH_G_CONVERT = false)(.libguess_encoding input_encoding)
77 
78 	do
79 	{
80 		switch (input_encoding) {
81 			case .libguess_encoding.UTF_8:
82 				return `UTF-8`;
83 
84 			static if (WITH_G_CONVERT) {
85 				case .libguess_encoding.UCS_2BE:
86 				case .libguess_encoding.UCS_2LE:
87 				case .libguess_encoding.UTF_16:
88 					return `UTF-16`;
89 			} else {
90 				case .libguess_encoding.UTF_16:
91 					return `UTF-16`;
92 
93 				case .libguess_encoding.UCS_2BE:
94 					return `UCS-2BE`;
95 
96 				case .libguess_encoding.UCS_2LE:
97 					return `UCS-2LE`;
98 			}
99 
100 			case .libguess_encoding.UTF_32:
101 				return `UTF-32`;
102 
103 			case .libguess_encoding.BIG5:
104 				return `BIG5`;
105 
106 			case .libguess_encoding.CP1251:
107 				return `CP1251`;
108 
109 			case .libguess_encoding.CP1253:
110 				return `CP1253`;
111 
112 			case .libguess_encoding.CP1254:
113 				return `CP1254`;
114 
115 			case .libguess_encoding.CP1255:
116 				return `CP1255`;
117 
118 			case .libguess_encoding.CP1256:
119 				return `CP1256`;
120 
121 			case .libguess_encoding.CP866:
122 				return `CP866`;
123 
124 			case .libguess_encoding.EUC_JP:
125 				return `EUC-JP`;
126 
127 			case .libguess_encoding.EUC_KR:
128 				return `EUC-KR`;
129 
130 			case .libguess_encoding.GB18030:
131 				return `GB18030`;
132 
133 			case .libguess_encoding.GB2312:
134 				return `GB2312`;
135 
136 			case .libguess_encoding.ISO_2022_CN:
137 				return `ISO-2022-CN`;
138 
139 			case .libguess_encoding.ISO_2022_JP:
140 				return `ISO-2022-JP`;
141 
142 			case .libguess_encoding.ISO_2022_KR:
143 				return `ISO-2022-KR`;
144 
145 			case .libguess_encoding.ISO_2022_TW:
146 				return `ISO-2022-TW`;
147 
148 			case .libguess_encoding.ISO_8859_6:
149 				return `ISO-8859-6`;
150 
151 			case .libguess_encoding.ISO_8859_7:
152 				return `ISO-8859-7`;
153 
154 			case .libguess_encoding.ISO_8859_8_I:
155 				return `ISO-8859-8-I`;
156 
157 			case .libguess_encoding.ISO_8859_9:
158 				return `ISO-8859-9`;
159 
160 			case .libguess_encoding.JOHAB:
161 				return `JOHAB`;
162 
163 			case .libguess_encoding.KOI8_R:
164 				return `KOI8-R`;
165 
166 			case .libguess_encoding.SJIS:
167 				return `SJIS`;
168 
169 			default:
170 				return null;
171 		}
172 	}
173 
174 static immutable libguess_d.dfa.guess_dfa eucjp = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_eucj_st, &libguess_d.guess.table.common_table.guess_eucj_ar, .libguess_encoding.EUC_JP);
175 static immutable libguess_d.dfa.guess_dfa big5 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_big5_st, &libguess_d.guess.table.common_table.guess_big5_ar, .libguess_encoding.BIG5);
176 static immutable libguess_d.dfa.guess_dfa cp1253 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_cp1253_st, &libguess_d.guess.table.common_table.guess_cp1253_ar, .libguess_encoding.CP1253);
177 static immutable libguess_d.dfa.guess_dfa cp1254 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_cp1253_st, &libguess_d.guess.table.common_table.guess_cp1253_ar, .libguess_encoding.CP1254);
178 static immutable libguess_d.dfa.guess_dfa cp1255 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_cp1255_st, &libguess_d.guess.table.common_table.guess_cp1255_ar, .libguess_encoding.CP1255);
179 static immutable libguess_d.dfa.guess_dfa cp1256 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_cp1256_st, &libguess_d.guess.table.common_table.guess_cp1256_ar, .libguess_encoding.CP1256);
180 static immutable libguess_d.dfa.guess_dfa euckr = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_euck_st, &libguess_d.guess.table.common_table.guess_euck_ar, .libguess_encoding.EUC_KR);
181 static immutable libguess_d.dfa.guess_dfa gb2312 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_gb2312_st, &libguess_d.guess.table.common_table.guess_gb2312_ar, .libguess_encoding.GB2312);
182 static immutable libguess_d.dfa.guess_dfa gb18030 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_gb18030_st, &libguess_d.guess.table.common_table.guess_gb18030_ar, .libguess_encoding.GB18030);
183 static immutable libguess_d.dfa.guess_dfa iso8859_6 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_iso8859_6_st, &libguess_d.guess.table.common_table.guess_iso8859_6_ar, .libguess_encoding.ISO_8859_6);
184 static immutable libguess_d.dfa.guess_dfa iso8859_7 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_iso8859_7_st, &libguess_d.guess.table.common_table.guess_iso8859_7_ar, .libguess_encoding.ISO_8859_7);
185 static immutable libguess_d.dfa.guess_dfa iso8859_8 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_iso8859_8_st, &libguess_d.guess.table.common_table.guess_iso8859_8_ar, .libguess_encoding.ISO_8859_8_I);
186 static immutable libguess_d.dfa.guess_dfa iso8859_9 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_iso8859_9_st, &libguess_d.guess.table.common_table.guess_iso8859_9_ar, .libguess_encoding.ISO_8859_9);
187 static immutable libguess_d.dfa.guess_dfa johab = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_johab_st, &libguess_d.guess.table.common_table.guess_johab_ar, .libguess_encoding.JOHAB);
188 static immutable libguess_d.dfa.guess_dfa sjis = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_sjis_st, &libguess_d.guess.table.common_table.guess_sjis_ar, .libguess_encoding.SJIS);
189 static immutable libguess_d.dfa.guess_dfa utf8 = libguess_d.dfa.guess_dfa(&libguess_d.guess.table.common_table.guess_utf8_st, &libguess_d.guess.table.common_table.guess_utf8_ar, .libguess_encoding.UTF_8);