1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* encoding.c (ENC_REGISTER): use &OnigEncoding*.

(ENCINDEX_UTF_8): renamed from ENCINDEX_UTF8.
  (rb_enc_init): use ENC_REGISTER.

* include/ruby/oniguruma.h (OnigEncodingUTF8, ONIG_ENCODING_UTF8):
  removed.

* enc/*.c: remove use of &encoding_*; use enc argument instead.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2008-01-15 13:36:18 +00:00
parent d2a377d747
commit edc61cf4c1
14 changed files with 58 additions and 67 deletions

View file

@ -1,3 +1,14 @@
Tue Jan 15 22:30:43 2008 NARUSE, Yui <naruse@ruby-lang.org>
* encoding.c (ENC_REGISTER): use &OnigEncoding*.
(ENCINDEX_UTF_8): renamed from ENCINDEX_UTF8.
(rb_enc_init): use ENC_REGISTER.
* include/ruby/oniguruma.h (OnigEncodingUTF8, ONIG_ENCODING_UTF8):
removed.
* enc/*.c: remove use of &encoding_*; use enc argument instead.
Tue Jan 15 18:44:46 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* enc/utf_8.c: remove use of ONIG_ENCODING_UTF8 altogether; use

View file

@ -29,8 +29,6 @@
#include "regenc.h"
OnigEncodingDeclare(BIG5);
static const int EncLen_BIG5[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -59,20 +57,20 @@ big5_mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc)
static OnigCodePoint
big5_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
{
return onigenc_mbn_mbc_to_code(&OnigEncodingName(BIG5), p, end);
return onigenc_mbn_mbc_to_code(enc, p, end);
}
static int
big5_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
return onigenc_mb2_code_to_mbc(&OnigEncodingName(BIG5), code, buf);
return onigenc_mb2_code_to_mbc(enc, code, buf);
}
static int
big5_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end,
UChar* lower, OnigEncoding enc)
{
return onigenc_mbn_mbc_case_fold(&OnigEncodingName(BIG5), flag,
return onigenc_mbn_mbc_case_fold(enc, flag,
pp, end, lower);
}
@ -81,14 +79,14 @@ static int
big5_is_mbc_ambiguous(OnigCaseFoldType flag,
const UChar** pp, const UChar* end, OnigEncoding enc)
{
return onigenc_mbn_is_mbc_ambiguous(&OnigEncodingName(BIG5), flag, pp, end);
return onigenc_mbn_is_mbc_ambiguous(enc, flag, pp, end);
}
#endif
static int
big5_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
{
return onigenc_mb2_is_code_ctype(&OnigEncodingName(BIG5), code, ctype);
return onigenc_mb2_is_code_ctype(enc, code, ctype);
}
static const char BIG5_CAN_BE_TRAIL_TABLE[256] = {
@ -130,7 +128,7 @@ big5_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
}
}
}
len = enclen(&OnigEncodingName(BIG5), p, s);
len = enclen(enc, p, s);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));

View file

@ -29,7 +29,6 @@
#include "regint.h"
OnigEncodingDeclare(EUC_JP);
#define eucjp_islead(c) ((UChar )((c) - 0xa1) > 0xfe - 0xa1)
@ -139,7 +138,7 @@ mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
int c, i, len;
OnigCodePoint n;
len = enclen(&OnigEncodingName(EUC_JP), p, end);
len = enclen(enc, p, end);
n = (OnigCodePoint )*p++;
if (len == 1) return n;
@ -191,7 +190,7 @@ code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
*p++ = (UChar )(code & 0xff);
#if 1
if (enclen(&OnigEncodingName(EUC_JP), buf, p) != (p - buf))
if (enclen(enc, buf, p) != (p - buf))
return ONIGERR_INVALID_CODE_POINT_VALUE;
#endif
return p - buf;
@ -213,7 +212,7 @@ mbc_case_fold(OnigCaseFoldType flag,
else {
int i;
len = enclen(&OnigEncodingName(EUC_JP), p, end);
len = enclen(enc, p, end);
for (i = 0; i < len; i++) {
*lower++ = *p++;
}
@ -235,7 +234,7 @@ left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
p = s;
while (!eucjp_islead(*p) && p > start) p--;
len = enclen(&OnigEncodingName(EUC_JP), p, s);
len = enclen(enc, p, s);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));

View file

@ -29,8 +29,6 @@
#include "regenc.h"
OnigEncodingDeclare(EUC_KR);
static const int EncLen_EUCKR[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -59,20 +57,20 @@ euckr_mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc)
static OnigCodePoint
euckr_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
{
return onigenc_mbn_mbc_to_code(&OnigEncodingName(EUC_KR), p, end);
return onigenc_mbn_mbc_to_code(enc, p, end);
}
static int
euckr_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
return onigenc_mb2_code_to_mbc(&OnigEncodingName(EUC_KR), code, buf);
return onigenc_mb2_code_to_mbc(enc, code, buf);
}
static int
euckr_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end,
UChar* lower, OnigEncoding enc)
{
return onigenc_mbn_mbc_case_fold(&OnigEncodingName(EUC_KR), flag,
return onigenc_mbn_mbc_case_fold(enc, flag,
pp, end, lower);
}
@ -81,14 +79,14 @@ static int
euckr_is_mbc_ambiguous(OnigCaseFoldType flag,
const UChar** pp, const UChar* end, OnigEncoding enc)
{
return onigenc_mbn_is_mbc_ambiguous(&OnigEncodingName(EUC_KR), flag, pp, end);
return onigenc_mbn_is_mbc_ambiguous(enc, flag, pp, end);
}
#endif
static int
euckr_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
{
return onigenc_mb2_is_code_ctype(&OnigEncodingName(EUC_KR), code, ctype);
return onigenc_mb2_is_code_ctype(enc, code, ctype);
}
#define euckr_islead(c) ((c) < 0xa1 || (c) == 0xff)
@ -106,7 +104,7 @@ euckr_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc
p = s;
while (!euckr_islead(*p) && p > start) p--;
len = enclen(&OnigEncodingName(EUC_KR), p, s);
len = enclen(enc, p, s);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));

View file

@ -29,8 +29,6 @@
#include "regenc.h"
OnigEncodingDeclare(EUC_TW);
static const int EncLen_EUCTW[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -59,20 +57,20 @@ euctw_mbc_enc_len(const UChar* p, const UChar* end, OnigEncoding enc)
static OnigCodePoint
euctw_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
{
return onigenc_mbn_mbc_to_code(&OnigEncodingName(EUC_TW), p, end);
return onigenc_mbn_mbc_to_code(enc, p, end);
}
static int
euctw_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
return onigenc_mb4_code_to_mbc(&OnigEncodingName(EUC_TW), code, buf);
return onigenc_mb4_code_to_mbc(enc, code, buf);
}
static int
euctw_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end,
UChar* lower, OnigEncoding enc)
{
return onigenc_mbn_mbc_case_fold(&OnigEncodingName(EUC_TW), flag,
return onigenc_mbn_mbc_case_fold(enc, flag,
pp, end, lower);
}
@ -81,14 +79,14 @@ static int
euctw_is_mbc_ambiguous(OnigCaseFoldType flag,
const UChar** pp, const UChar* end, OnigEncoding enc)
{
return onigenc_mbn_is_mbc_ambiguous(&OnigEncodingName(EUC_TW), flag, pp, end);
return onigenc_mbn_is_mbc_ambiguous(enc, flag, pp, end);
}
#endif
static int
euctw_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
{
return onigenc_mb4_is_code_ctype(&OnigEncodingName(EUC_TW), code, ctype);
return onigenc_mb4_is_code_ctype(enc, code, ctype);
}
#define euctw_islead(c) (((c) < 0xa1 && (c) != 0x8e) || (c) == 0xff)
@ -106,7 +104,7 @@ euctw_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc
p = s;
while (!euctw_islead(*p) && p > start) p--;
len = enclen(&OnigEncodingName(EUC_TW), p, s);
len = enclen(enc, p, s);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));

View file

@ -30,8 +30,6 @@
#include "regenc.h"
OnigEncodingDeclare(GB18030);
#if 1
#define DEBUG_GB18030(arg)
#else
@ -80,20 +78,20 @@ gb18030_mbc_enc_len(const UChar* p, const UChar* end, OnigEncoding enc)
static OnigCodePoint
gb18030_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
{
return onigenc_mbn_mbc_to_code(&OnigEncodingName(GB18030), p, end);
return onigenc_mbn_mbc_to_code(enc, p, end);
}
static int
gb18030_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
return onigenc_mb4_code_to_mbc(&OnigEncodingName(GB18030), code, buf);
return onigenc_mb4_code_to_mbc(enc, code, buf);
}
static int
gb18030_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end,
UChar* lower, OnigEncoding enc)
{
return onigenc_mbn_mbc_case_fold(&OnigEncodingName(GB18030), flag,
return onigenc_mbn_mbc_case_fold(enc, flag,
pp, end, lower);
}
@ -102,14 +100,14 @@ static int
gb18030_is_mbc_ambiguous(OnigCaseFoldType flag,
const UChar** pp, const UChar* end, OnigEncoding enc)
{
return onigenc_mbn_is_mbc_ambiguous(&OnigEncodingName(GB18030), flag, pp, end);
return onigenc_mbn_is_mbc_ambiguous(enc, flag, pp, end);
}
#endif
static int
gb18030_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
{
return onigenc_mb4_is_code_ctype(&OnigEncodingName(GB18030), code, ctype);
return onigenc_mb4_is_code_ctype(enc, code, ctype);
}
enum state {

View file

@ -29,8 +29,6 @@
#include "regint.h"
OnigEncodingDeclare(Shift_JIS);
static const int EncLen_SJIS[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -152,7 +150,7 @@ mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
int c, i, len;
OnigCodePoint n;
len = enclen(&OnigEncodingName(Shift_JIS), p, end);
len = enclen(enc, p, end);
c = *p++;
n = c;
if (len == 1) return n;
@ -174,7 +172,7 @@ code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
*p++ = (UChar )(code & 0xff);
#if 0
if (enclen(&OnigEncodingName(Shift_JIS), buf) != (p - buf))
if (enclen(enc, buf) != (p - buf))
return REGERR_INVALID_CODE_POINT_VALUE;
#endif
return p - buf;
@ -194,7 +192,7 @@ mbc_case_fold(OnigCaseFoldType flag,
}
else {
int i;
int len = enclen(&OnigEncodingName(Shift_JIS), p, end);
int len = enclen(enc, p, end);
for (i = 0; i < len; i++) {
*lower++ = *p++;
@ -209,7 +207,7 @@ static int
is_mbc_ambiguous(OnigCaseFoldType flag,
const UChar** pp, const UChar* end)
{
return onigenc_mbn_is_mbc_ambiguous(&OnigEncodingName(Shift_JIS), flag, pp, end);
return onigenc_mbn_is_mbc_ambiguous(enc, flag, pp, end);
}
#endif
@ -247,7 +245,7 @@ left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
}
}
}
len = enclen(&OnigEncodingName(Shift_JIS), p, s);
len = enclen(enc, p, s);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));

View file

@ -29,8 +29,6 @@
#include "regenc.h"
OnigEncodingDeclare(UTF_16BE);
#define UTF16_IS_SURROGATE_FIRST(c) (c >= 0xd8 && c <= 0xdb)
#define UTF16_IS_SURROGATE_SECOND(c) (c >= 0xdc && c <= 0xdf)
@ -155,7 +153,7 @@ utf16be_mbc_case_fold(OnigCaseFoldType flag,
return 2;
}
else
return onigenc_unicode_mbc_case_fold(&OnigEncodingName(UTF_16BE), flag,
return onigenc_unicode_mbc_case_fold(enc, flag,
pp, end, fold);
}
@ -215,7 +213,7 @@ utf16be_get_case_fold_codes_by_str(OnigCaseFoldType flag,
OnigCaseFoldCodeItem items[],
struct OnigEncodingTypeST* enc ARG_UNUSED)
{
return onigenc_unicode_get_case_fold_codes_by_str(&OnigEncodingName(UTF_16BE),
return onigenc_unicode_get_case_fold_codes_by_str(enc,
flag, p, end, items);
}

View file

@ -29,8 +29,6 @@
#include "regenc.h"
OnigEncodingDeclare(UTF_16LE);
#define UTF16_IS_SURROGATE_FIRST(c) (c >= 0xd8 && c <= 0xdb)
#define UTF16_IS_SURROGATE_SECOND(c) (c >= 0xdc && c <= 0xdf)
@ -157,7 +155,7 @@ utf16le_mbc_case_fold(OnigCaseFoldType flag,
return 2;
}
else
return onigenc_unicode_mbc_case_fold(&OnigEncodingName(UTF_16LE), flag, pp,
return onigenc_unicode_mbc_case_fold(enc, flag, pp,
end, fold);
}
@ -216,7 +214,7 @@ utf16le_get_case_fold_codes_by_str(OnigCaseFoldType flag,
OnigCaseFoldCodeItem items[],
struct OnigEncodingTypeST* enc ARG_UNUSED)
{
return onigenc_unicode_get_case_fold_codes_by_str(&OnigEncodingName(UTF_16LE),
return onigenc_unicode_get_case_fold_codes_by_str(enc,
flag, p, end, items);
}

View file

@ -29,8 +29,6 @@
#include "regenc.h"
OnigEncodingDeclare(UTF_32BE);
static int
utf32be_mbc_enc_len(const UChar* p ARG_UNUSED, const OnigUChar* e ARG_UNUSED,
struct OnigEncodingTypeST* enc ARG_UNUSED)
@ -116,7 +114,7 @@ utf32be_mbc_case_fold(OnigCaseFoldType flag,
return 4;
}
else
return onigenc_unicode_mbc_case_fold(&OnigEncodingName(UTF_32BE), flag, pp,
return onigenc_unicode_mbc_case_fold(enc, flag, pp,
end, fold);
}
@ -171,7 +169,7 @@ utf32be_get_case_fold_codes_by_str(OnigCaseFoldType flag,
OnigCaseFoldCodeItem items[],
struct OnigEncodingTypeST* enc ARG_UNUSED)
{
return onigenc_unicode_get_case_fold_codes_by_str(&OnigEncodingName(UTF_32BE),
return onigenc_unicode_get_case_fold_codes_by_str(enc,
flag, p, end, items);
}

View file

@ -29,8 +29,6 @@
#include "regenc.h"
OnigEncodingDeclare(UTF_32LE);
static int
utf32le_mbc_enc_len(const UChar* p ARG_UNUSED, const OnigUChar* e ARG_UNUSED,
struct OnigEncodingTypeST* enc ARG_UNUSED)
@ -117,7 +115,7 @@ utf32le_mbc_case_fold(OnigCaseFoldType flag,
return 4;
}
else
return onigenc_unicode_mbc_case_fold(&OnigEncodingName(UTF_32LE), flag, pp,
return onigenc_unicode_mbc_case_fold(enc, flag, pp,
end, fold);
}
@ -171,7 +169,7 @@ utf32le_get_case_fold_codes_by_str(OnigCaseFoldType flag,
OnigCaseFoldCodeItem items[],
struct OnigEncodingTypeST* enc ARG_UNUSED)
{
return onigenc_unicode_get_case_fold_codes_by_str(&OnigEncodingName(UTF_32LE),
return onigenc_unicode_get_case_fold_codes_by_str(enc,
flag, p, end, items);
}

View file

@ -424,7 +424,7 @@ get_case_fold_codes_by_str(OnigCaseFoldType flag,
return onigenc_unicode_get_case_fold_codes_by_str(enc, flag, p, end, items);
}
OnigEncodingDefine(utf8, UTF8) = {
OnigEncodingDefine(utf_8, UTF_8) = {
mbc_enc_len,
"UTF-8", /* name */
6, /* max byte length */

View file

@ -303,21 +303,22 @@ rb_enc_alias(const char *alias, const char *orig)
enum {
ENCINDEX_ASCII,
ENCINDEX_UTF8,
ENCINDEX_UTF_8,
ENCINDEX_US_ASCII,
ENCINDEX_BUILTIN_MAX
};
extern rb_encoding OnigEncodingUTF_8;
extern rb_encoding OnigEncodingUS_ASCII;
void
rb_enc_init(void)
{
enc_table.count = enc_table_expand(ENCINDEX_BUILTIN_MAX);
#define ENC_REGISTER(enc) enc_register_at(ENCINDEX_##enc, rb_enc_name(ONIG_ENCODING_##enc), ONIG_ENCODING_##enc)
#define ENC_REGISTER(enc) enc_register_at(ENCINDEX_##enc, rb_enc_name(&OnigEncoding##enc), &OnigEncoding##enc)
ENC_REGISTER(ASCII);
ENC_REGISTER(UTF8);
enc_register_at(ENCINDEX_US_ASCII, rb_enc_name(&OnigEncodingUS_ASCII), &OnigEncodingUS_ASCII);
ENC_REGISTER(UTF_8);
ENC_REGISTER(US_ASCII);
#undef ENC_REGISTER
}
@ -868,7 +869,7 @@ rb_utf8_encoding(void)
if (!enc_table.list) {
rb_enc_init();
}
return enc_table.list[ENCINDEX_UTF8].enc;
return enc_table.list[ENCINDEX_UTF_8].enc;
}
rb_encoding *

View file

@ -173,10 +173,8 @@ typedef struct OnigEncodingTypeST {
typedef OnigEncodingType* OnigEncoding;
ONIG_EXTERN OnigEncodingType OnigEncodingASCII;
ONIG_EXTERN OnigEncodingType OnigEncodingUTF8;
#define ONIG_ENCODING_ASCII (&OnigEncodingASCII)
#define ONIG_ENCODING_UTF8 (&OnigEncodingUTF8)
#define ONIG_ENCODING_UNDEF ((OnigEncoding )0)