Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81169 views
1
"use strict"
2
3
// Description of supported double byte encodings and aliases.
4
// Tables are not require()-d until they are needed to speed up library load.
5
// require()-s are direct to support Browserify.
6
7
module.exports = {
8
9
// == Japanese/ShiftJIS ====================================================
10
// All japanese encodings are based on JIS X set of standards:
11
// JIS X 0201 - Single-byte encoding of ASCII + ¥ + Kana chars at 0xA1-0xDF.
12
// JIS X 0208 - Main set of 6879 characters, placed in 94x94 plane, to be encoded by 2 bytes.
13
// Has several variations in 1978, 1983, 1990 and 1997.
14
// JIS X 0212 - Supplementary plane of 6067 chars in 94x94 plane. 1990. Effectively dead.
15
// JIS X 0213 - Extension and modern replacement of 0208 and 0212. Total chars: 11233.
16
// 2 planes, first is superset of 0208, second - revised 0212.
17
// Introduced in 2000, revised 2004. Some characters are in Unicode Plane 2 (0x2xxxx)
18
19
// Byte encodings are:
20
// * Shift_JIS: Compatible with 0201, uses not defined chars in top half as lead bytes for double-byte
21
// encoding of 0208. Lead byte ranges: 0x81-0x9F, 0xE0-0xEF; Trail byte ranges: 0x40-0x7E, 0x80-0x9E, 0x9F-0xFC.
22
// Windows CP932 is a superset of Shift_JIS. Some companies added more chars, notably KDDI.
23
// * EUC-JP: Up to 3 bytes per character. Used mostly on *nixes.
24
// 0x00-0x7F - lower part of 0201
25
// 0x8E, 0xA1-0xDF - upper part of 0201
26
// (0xA1-0xFE)x2 - 0208 plane (94x94).
27
// 0x8F, (0xA1-0xFE)x2 - 0212 plane (94x94).
28
// * JIS X 208: 7-bit, direct encoding of 0208. Byte ranges: 0x21-0x7E (94 values). Uncommon.
29
// Used as-is in ISO2022 family.
30
// * ISO2022-JP: Stateful encoding, with escape sequences to switch between ASCII,
31
// 0201-1976 Roman, 0208-1978, 0208-1983.
32
// * ISO2022-JP-1: Adds esc seq for 0212-1990.
33
// * ISO2022-JP-2: Adds esc seq for GB2313-1980, KSX1001-1992, ISO8859-1, ISO8859-7.
34
// * ISO2022-JP-3: Adds esc seq for 0201-1976 Kana set, 0213-2000 Planes 1, 2.
35
// * ISO2022-JP-2004: Adds 0213-2004 Plane 1.
36
//
37
// After JIS X 0213 appeared, Shift_JIS-2004, EUC-JISX0213 and ISO2022-JP-2004 followed, with just changing the planes.
38
//
39
// Overall, it seems that it's a mess :( http://www8.plala.or.jp/tkubota1/unicode-symbols-map2.html
40
41
42
'shiftjis': {
43
type: '_dbcs',
44
table: function() { return require('./tables/shiftjis.json') },
45
encodeAdd: {'\u00a5': 0x5C, '\u203E': 0x7E},
46
encodeSkipVals: [{from: 0xED40, to: 0xF940}],
47
},
48
'csshiftjis': 'shiftjis',
49
'mskanji': 'shiftjis',
50
'sjis': 'shiftjis',
51
'windows31j': 'shiftjis',
52
'xsjis': 'shiftjis',
53
'windows932': 'shiftjis',
54
'932': 'shiftjis',
55
'cp932': 'shiftjis',
56
57
'eucjp': {
58
type: '_dbcs',
59
table: function() { return require('./tables/eucjp.json') },
60
encodeAdd: {'\u00a5': 0x5C, '\u203E': 0x7E},
61
},
62
63
// TODO: KDDI extension to Shift_JIS
64
// TODO: IBM CCSID 942 = CP932, but F0-F9 custom chars and other char changes.
65
// TODO: IBM CCSID 943 = Shift_JIS = CP932 with original Shift_JIS lower 128 chars.
66
67
// == Chinese/GBK ==========================================================
68
// http://en.wikipedia.org/wiki/GBK
69
70
// Oldest GB2312 (1981, ~7600 chars) is a subset of CP936
71
'gb2312': 'cp936',
72
'gb231280': 'cp936',
73
'gb23121980': 'cp936',
74
'csgb2312': 'cp936',
75
'csiso58gb231280': 'cp936',
76
'euccn': 'cp936',
77
'isoir58': 'gbk',
78
79
// Microsoft's CP936 is a subset and approximation of GBK.
80
// TODO: Euro = 0x80 in cp936, but not in GBK (where it's valid but undefined)
81
'windows936': 'cp936',
82
'936': 'cp936',
83
'cp936': {
84
type: '_dbcs',
85
table: function() { return require('./tables/cp936.json') },
86
},
87
88
// GBK (~22000 chars) is an extension of CP936 that added user-mapped chars and some other.
89
'gbk': {
90
type: '_dbcs',
91
table: function() { return require('./tables/cp936.json').concat(require('./tables/gbk-added.json')) },
92
},
93
'xgbk': 'gbk',
94
95
// GB18030 is an algorithmic extension of GBK.
96
'gb18030': {
97
type: '_dbcs',
98
table: function() { return require('./tables/cp936.json').concat(require('./tables/gbk-added.json')) },
99
gb18030: function() { return require('./tables/gb18030-ranges.json') },
100
},
101
102
'chinese': 'gb18030',
103
104
// TODO: Support GB18030 (~27000 chars + whole unicode mapping, cp54936)
105
// http://icu-project.org/docs/papers/gb18030.html
106
// http://source.icu-project.org/repos/icu/data/trunk/charset/data/xml/gb-18030-2000.xml
107
// http://www.khngai.com/chinese/charmap/tblgbk.php?page=0
108
109
// == Korean ===============================================================
110
// EUC-KR, KS_C_5601 and KS X 1001 are exactly the same.
111
'windows949': 'cp949',
112
'949': 'cp949',
113
'cp949': {
114
type: '_dbcs',
115
table: function() { return require('./tables/cp949.json') },
116
},
117
118
'cseuckr': 'cp949',
119
'csksc56011987': 'cp949',
120
'euckr': 'cp949',
121
'isoir149': 'cp949',
122
'korean': 'cp949',
123
'ksc56011987': 'cp949',
124
'ksc56011989': 'cp949',
125
'ksc5601': 'cp949',
126
127
128
// == Big5/Taiwan/Hong Kong ================================================
129
// There are lots of tables for Big5 and cp950. Please see the following links for history:
130
// http://moztw.org/docs/big5/ http://www.haible.de/bruno/charsets/conversion-tables/Big5.html
131
// Variations, in roughly number of defined chars:
132
// * Windows CP 950: Microsoft variant of Big5. Canonical: http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP950.TXT
133
// * Windows CP 951: Microsoft variant of Big5-HKSCS-2001. Seems to be never public. http://me.abelcheung.org/articles/research/what-is-cp951/
134
// * Big5-2003 (Taiwan standard) almost superset of cp950.
135
// * Unicode-at-on (UAO) / Mozilla 1.8. Falling out of use on the Web. Not supported by other browsers.
136
// * Big5-HKSCS (-2001, -2004, -2008). Hong Kong standard.
137
// many unicode code points moved from PUA to Supplementary plane (U+2XXXX) over the years.
138
// Plus, it has 4 combining sequences.
139
// Seems that Mozilla refused to support it for 10 yrs. https://bugzilla.mozilla.org/show_bug.cgi?id=162431 https://bugzilla.mozilla.org/show_bug.cgi?id=310299
140
// because big5-hkscs is the only encoding to include astral characters in non-algorithmic way.
141
// Implementations are not consistent within browsers; sometimes labeled as just big5.
142
// MS Internet Explorer switches from big5 to big5-hkscs when a patch applied.
143
// Great discussion & recap of what's going on https://bugzilla.mozilla.org/show_bug.cgi?id=912470#c31
144
// In the encoder, it might make sense to support encoding old PUA mappings to Big5 bytes seq-s.
145
// Official spec: http://www.ogcio.gov.hk/en/business/tech_promotion/ccli/terms/doc/2003cmp_2008.txt
146
// http://www.ogcio.gov.hk/tc/business/tech_promotion/ccli/terms/doc/hkscs-2008-big5-iso.txt
147
//
148
// Current understanding of how to deal with Big5(-HKSCS) is in the Encoding Standard, http://encoding.spec.whatwg.org/#big5-encoder
149
// Unicode mapping (http://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/OTHER/BIG5.TXT) is said to be wrong.
150
151
'windows950': 'cp950',
152
'950': 'cp950',
153
'cp950': {
154
type: '_dbcs',
155
table: function() { return require('./tables/cp950.json') },
156
},
157
158
// Big5 has many variations and is an extension of cp950. We use Encoding Standard's as a consensus.
159
'big5': 'big5hkscs',
160
'big5hkscs': {
161
type: '_dbcs',
162
table: function() { return require('./tables/cp950.json').concat(require('./tables/big5-added.json')) },
163
encodeSkipVals: [0xa2cc],
164
},
165
166
'cnbig5': 'big5hkscs',
167
'csbig5': 'big5hkscs',
168
'xxbig5': 'big5hkscs',
169
170
};
171
172