Skip to content

Commit 8984fa6

Browse files
committed
* enc/{euc_jp.c,gbk.c,iso_8859_1.c,iso_8859_11.c,iso_8859_13.c,
iso_8859_2.c,iso_8859_6.c,iso_8859_7.c,iso_8859_8.c,iso_8859_9.c, shift_jis.c,windows_1251.c}: add document about encodings. * enc/cp949.c: divided into new file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 0f4199f commit 8984fa6

14 files changed

Lines changed: 345 additions & 4 deletions

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Sun Feb 17 12:17:52 2008 NARUSE, Yui <naruse@ruby-lang.org>
2+
3+
* enc/{euc_jp.c,gbk.c,iso_8859_1.c,iso_8859_11.c,iso_8859_13.c,
4+
iso_8859_2.c,iso_8859_6.c,iso_8859_7.c,iso_8859_8.c,iso_8859_9.c,
5+
shift_jis.c,windows_1251.c}: add document about encodings.
6+
7+
* enc/cp949.c: divided into new file.
8+
19
Sun Feb 17 10:59:04 2008 Tanaka Akira <akr@fsij.org>
210

311
* re.c (rb_reg_quote): return US-ASCII string consistently.

enc/cp949.c

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/**********************************************************************
2+
cp949.c - Oniguruma (regular expression library)
3+
**********************************************************************/
4+
/*-
5+
* Copyright (c) 2002-2007 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
* 1. Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27+
* SUCH DAMAGE.
28+
*/
29+
30+
#include "regenc.h"
31+
32+
static const int EncLen_CP949[] = {
33+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
34+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
35+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
36+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
37+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
38+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
39+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
40+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
41+
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
42+
2, 2, 2,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 1, 1, 1, 1, 1, 1, 1, 1,
65+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
66+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
67+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
68+
};
69+
70+
#define CP949_ISMB_FIRST(byte) (EncLen_CP949[byte] > 1)
71+
#define CP949_ISMB_TRAIL(byte) CP949_CAN_BE_TRAIL_TABLE[(byte)]
72+
73+
typedef enum { FAILURE = -2, ACCEPT = -1, S0 = 0, S1 } state_t;
74+
#define A ACCEPT
75+
#define F FAILURE
76+
static const signed char trans[][0x100] = {
77+
{ /* S0 0 1 2 3 4 5 6 7 8 9 a b c d e f */
78+
/* 0 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
79+
/* 1 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
80+
/* 2 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
81+
/* 3 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
82+
/* 4 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
83+
/* 5 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
84+
/* 6 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
85+
/* 7 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
86+
/* 8 */ A, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
87+
/* 9 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
88+
/* a */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
89+
/* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
90+
/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
91+
/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
92+
/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
93+
/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, F
94+
},
95+
{ /* S1 0 1 2 3 4 5 6 7 8 9 a b c d e f */
96+
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
97+
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
98+
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
99+
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
100+
/* 4 */ F, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
101+
/* 5 */ A, A, A, A, A, A, A, A, A, A, A, F, F, F, F, F,
102+
/* 6 */ F, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
103+
/* 7 */ A, A, A, A, A, A, A, A, A, A, A, F, F, F, F, F,
104+
/* 8 */ F, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
105+
/* 9 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
106+
/* a */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
107+
/* b */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
108+
/* c */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
109+
/* d */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
110+
/* e */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
111+
/* f */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, F
112+
}
113+
};
114+
#undef A
115+
#undef F
116+
117+
static int
118+
cp949_mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
119+
{
120+
int firstbyte = *p++;
121+
state_t s = trans[0][firstbyte];
122+
#define RETURN(n) \
123+
return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(n) : \
124+
ONIGENC_CONSTRUCT_MBCLEN_INVALID()
125+
if (s < 0) RETURN(1);
126+
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_CP949[firstbyte]-1);
127+
s = trans[s][*p++];
128+
RETURN(2);
129+
#undef RETURN
130+
}
131+
132+
static OnigCodePoint
133+
cp949_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
134+
{
135+
return onigenc_mbn_mbc_to_code(enc, p, end);
136+
}
137+
138+
static int
139+
cp949_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
140+
{
141+
return onigenc_mb2_code_to_mbc(enc, code, buf);
142+
}
143+
144+
static int
145+
cp949_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end,
146+
UChar* lower, OnigEncoding enc)
147+
{
148+
return onigenc_mbn_mbc_case_fold(enc, flag,
149+
pp, end, lower);
150+
}
151+
152+
#if 0
153+
static int
154+
cp949_is_mbc_ambiguous(OnigCaseFoldType flag,
155+
const UChar** pp, const UChar* end, OnigEncoding enc)
156+
{
157+
return onigenc_mbn_is_mbc_ambiguous(enc, flag, pp, end);
158+
}
159+
#endif
160+
161+
static int
162+
cp949_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
163+
{
164+
return onigenc_mb2_is_code_ctype(enc, code, ctype);
165+
}
166+
167+
static UChar*
168+
cp949_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
169+
{
170+
const UChar *p;
171+
int len;
172+
173+
if (s <= start) return (UChar* )s;
174+
p = s;
175+
176+
if (CP949_ISMB_TRAIL(*p)) {
177+
while (p > start) {
178+
if (! CP949_ISMB_FIRST(*--p)) {
179+
p++;
180+
break;
181+
}
182+
}
183+
}
184+
len = enclen(enc, p, s);
185+
if (p + len > s) return (UChar* )p;
186+
p += len;
187+
return (UChar* )(p + ((s - p) & ~1));
188+
}
189+
190+
static int
191+
cp949_is_allowed_reverse_match(const UChar* s, const UChar* end ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
192+
{
193+
const UChar c = *s;
194+
return (CP949_ISMB_TRAIL(c) ? FALSE : TRUE);
195+
}
196+
197+
OnigEncodingDefine(cp949, CP949) = {
198+
cp949_mbc_enc_len,
199+
"CP949", /* name */
200+
2, /* max enc length */
201+
1, /* min enc length */
202+
onigenc_is_mbc_newline_0x0a,
203+
cp949_mbc_to_code,
204+
onigenc_mb2_code_to_mbclen,
205+
cp949_code_to_mbc,
206+
cp949_mbc_case_fold,
207+
onigenc_ascii_apply_all_case_fold,
208+
onigenc_ascii_get_case_fold_codes_by_str,
209+
onigenc_minimum_property_name_to_ctype,
210+
cp949_is_code_ctype,
211+
onigenc_not_support_get_ctype_code_range,
212+
cp949_left_adjust_char_head,
213+
cp949_is_allowed_reverse_match
214+
};
215+
/*
216+
* Name: CP949
217+
* Link: http://www.microsoft.com/globaldev/reference/dbcs/949.mspx
218+
* Link: http://en.wikipedia.org/wiki/EUC-KR#EUC-KR
219+
*/

enc/euc_jp.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,27 @@ OnigEncodingDefine(euc_jp, EUC_JP) = {
362362
is_allowed_reverse_match,
363363
0
364364
};
365+
/*
366+
* Name: EUC-JP
367+
* MIBenum: 18
368+
* Link: http://www.iana.org/assignments/character-sets
369+
* Link: http://home.m05.itscom.net/numa/cde/sjis-euc/sjis-euc.html
370+
*/
365371
ENC_ALIAS("eucJP", "EUC-JP"); /* UI-OSF Application Platform Profile for Japanese Environment Version 1.1 */
372+
373+
/*
374+
* Name: eucJP-ms
375+
* Link: http://home.m05.itscom.net/numa/cde/ucs-conv/ucs-conv.html
376+
* Link: http://www2d.biglobe.ne.jp/~msyk/charcode/cp932/eucJP-ms.html
377+
* Link: http://ja.wikipedia.org/wiki/EUC-JP
378+
*/
366379
ENC_REPLICATE("eucJP-ms", "EUC-JP"); /* TOG/JVC CDE/Motif Technical WG */
367380
ENC_ALIAS("euc-jp-ms", "EUC-JP");
368-
ENC_REPLICATE("CP51932", "EUC-JP"); /* Windows CodePage 51932 */
381+
382+
/*
383+
* Name: CP51932
384+
* Link: http://search.cpan.org/src/NARUSE/Encode-EUCJPMS-0.07/ucm/cp51932.ucm
385+
* Link: http://legacy-encoding.sourceforge.jp/wiki/index.php?cp51932
386+
* Link: http://msyk.at.webry.info/200511/article_2.html
387+
*/
388+
ENC_REPLICATE("CP51932", "EUC-JP");

enc/gbk.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,11 @@ OnigEncodingDefine(gbk, GBK) = {
212212
gbk_left_adjust_char_head,
213213
gbk_is_allowed_reverse_match
214214
};
215+
/*
216+
* Name: GBK
217+
* MIBenum: 113
218+
* Link: http://www.iana.org/assignments/character-sets
219+
* Link: http://www.iana.org/assignments/charset-reg/GBK
220+
* Link: http://www.microsoft.com/globaldev/reference/dbcs/936.mspx
221+
*/
215222
ENC_ALIAS("CP936", "GBK");
216-
ENC_REPLICATE("CP949", "GBK");

enc/iso_8859_1.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,5 +273,13 @@ OnigEncodingDefine(iso_8859_1, ISO_8859_1) = {
273273
onigenc_always_true_is_allowed_reverse_match
274274
};
275275
ENC_ALIAS("ISO8859-1", "ISO-8859-1");
276+
277+
/*
278+
* Name: windows-1252
279+
* MIBenum: 2252
280+
* Link: http://www.iana.org/assignments/character-sets
281+
* Link: http://www.microsoft.com/globaldev/reference/sbcs/1252.mspx
282+
* Link: http://en.wikipedia.org/wiki/Windows-1252
283+
*/
276284
ENC_REPLICATE("Windows-1252", "ISO-8859-1");
277285
ENC_ALIAS("CP1252", "Windows-1252");

enc/iso_8859_11.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ OnigEncodingDefine(iso_8859_11, ISO_8859_11) = {
9595
onigenc_always_true_is_allowed_reverse_match
9696
};
9797
ENC_ALIAS("ISO8859-11", "ISO-8859-11");
98+
99+
/*
100+
* Name: TIS-620
101+
* MIBenum: 2259
102+
* Link: http://en.wikipedia.org/wiki/Thai_Industrial_Standard_620-2533
103+
*/
98104
ENC_REPLICATE("TIS-620", "ISO-8859-11");
105+
106+
/*
107+
* Name: Windows-874
108+
* Link: http://www.microsoft.com/globaldev/reference/sbcs/874.mspx
109+
*/
99110
ENC_REPLICATE("Windows-874", "ISO-8859-11");
100111
ENC_ALIAS("CP874", "Windows-874");

enc/iso_8859_13.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ ENC_ALIAS("ISO8859-13", "ISO-8859-13");
235235
/*
236236
* Name: windows-1257
237237
* MIBenum: 2257
238-
* http://www.microsoft.com/globaldev/reference/sbcs/1257.mspx
239-
* http://en.wikipedia.org/wiki/Windows-1257
238+
* Link: http://www.iana.org/assignments/character-sets
239+
* Link: http://www.microsoft.com/globaldev/reference/sbcs/1257.mspx
240+
* Link: http://en.wikipedia.org/wiki/Windows-1257
240241
*/
241242
ENC_REPLICATE("Windows-1257", "ISO-8859-13");
242243
ENC_ALIAS("CP1257", "Windows-1257");

enc/iso_8859_2.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,5 +238,13 @@ OnigEncodingDefine(iso_8859_2, ISO_8859_2) = {
238238
onigenc_always_true_is_allowed_reverse_match
239239
};
240240
ENC_ALIAS("ISO8859-2", "ISO-8859-2");
241+
242+
/*
243+
* Name: windows-1250
244+
* MIBenum: 2250
245+
* Link: http://www.iana.org/assignments/character-sets
246+
* Link: http://www.microsoft.com/globaldev/reference/sbcs/1250.mspx
247+
* Link: http://en.wikipedia.org/wiki/Windows-1250
248+
*/
241249
ENC_REPLICATE("Windows-1250", "ISO-8859-2");
242250
ENC_ALIAS("CP1250", "Windows-1250");

enc/iso_8859_6.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,13 @@ OnigEncodingDefine(iso_8859_6, ISO_8859_6) = {
9595
onigenc_always_true_is_allowed_reverse_match
9696
};
9797
ENC_ALIAS("ISO8859-6", "ISO-8859-6");
98+
99+
/*
100+
* Name: windows-1256
101+
* MIBenum: 2256
102+
* Link: http://www.iana.org/assignments/character-sets
103+
* Link: http://www.microsoft.com/globaldev/reference/sbcs/1256.mspx
104+
* Link: http://en.wikipedia.org/wiki/Windows-1256
105+
*/
98106
ENC_REPLICATE("Windows-1256", "ISO-8859-6");
99107
ENC_ALIAS("CP1256", "Windows-1256");

enc/iso_8859_7.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,13 @@ OnigEncodingDefine(iso_8859_7, ISO_8859_7) = {
225225
onigenc_always_true_is_allowed_reverse_match
226226
};
227227
ENC_ALIAS("ISO8859-7", "ISO-8859-7");
228+
229+
/*
230+
* Name: windows-1253
231+
* MIBenum: 2253
232+
* Link: http://www.iana.org/assignments/character-sets
233+
* Link: http://www.microsoft.com/globaldev/reference/sbcs/1253.mspx
234+
* Link: http://en.wikipedia.org/wiki/Windows-1253
235+
*/
228236
ENC_REPLICATE("Windows-1253", "ISO-8859-7");
229237
ENC_ALIAS("CP1253", "Windows-1253");

0 commit comments

Comments
 (0)