From 249c08716da39c4f51c295948125436640a60487 Mon Sep 17 00:00:00 2001 From: naruse Date: Fri, 11 Jan 2008 01:03:23 +0000 Subject: [PATCH] * ext/nkf/nkf-utf8/nkf.c: update to r1.163. * ext/nkf/nkf.c: ASCII's canonical name is US-ASCII. * ext/nkf/lib/kconv.rb (Kconv.isjis): force_encoding('BINARY'). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 +++++++++- ext/nkf/lib/kconv.rb | 2 +- ext/nkf/nkf-utf8/nkf.c | 29 +++++++++++------------------ ext/nkf/nkf.c | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa7f99fb4e..87cde446b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,14 @@ +Fri Jan 11 09:59:05 2008 NARUSE, Yui + + * ext/nkf/nkf-utf8/nkf.c: update to r1.163. + + * ext/nkf/nkf.c: ASCII's canonical name is US-ASCII. + + * ext/nkf/lib/kconv.rb (Kconv.isjis): force_encoding('BINARY'). + Fri Jan 11 09:23:31 2008 NARUSE, Yui - * encoding (set_base_encoding): must use rb_enc_dummy_p. + * encoding.c (set_base_encoding): must use rb_enc_dummy_p. Fri Jan 11 06:13:14 2008 Nobuyoshi Nakada diff --git a/ext/nkf/lib/kconv.rb b/ext/nkf/lib/kconv.rb index a1c62e7765..159a5aa233 100644 --- a/ext/nkf/lib/kconv.rb +++ b/ext/nkf/lib/kconv.rb @@ -181,7 +181,7 @@ module Kconv )* \x1b \x28 B [\t\n\r\x20-\x7E]* )* - \z/nox =~ str.dup.force_encoding(nil) ? true : false + \z/nox =~ str.dup.force_encoding('BINARY') ? true : false end module_function :isjis diff --git a/ext/nkf/nkf-utf8/nkf.c b/ext/nkf/nkf-utf8/nkf.c index 94deb13ed1..431027b574 100644 --- a/ext/nkf/nkf-utf8/nkf.c +++ b/ext/nkf/nkf-utf8/nkf.c @@ -32,10 +32,10 @@ ***********************************************************************/ /* $Id$ */ #define NKF_VERSION "2.0.8" -#define NKF_RELEASE_DATE "2007-01-02" +#define NKF_RELEASE_DATE "2008-01-11" #define COPY_RIGHT \ "Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa),2000 S. Kono, COW\n" \ - "Copyright (C) 2002-2007 Kono, Furukawa, Naruse, mastodon" + "Copyright (C) 2002-2008 Kono, Furukawa, Naruse, mastodon" #include "config.h" #include "utf8tbl.h" @@ -188,22 +188,11 @@ void djgpp_setbinmode(FILE *fp) */ -/* Input Assumption */ - -#define JIS_INPUT 4 -#define EUC_INPUT 16 -#define SJIS_INPUT 5 -#define LATIN1_INPUT 6 -#define UTF8_INPUT 13 -#define UTF16_INPUT 1015 -#define UTF32_INPUT 1017 +/* MIME ENCODE */ #define FIXED_MIME 7 #define STRICT_MIME 8 -/* MIME ENCODE */ - - /* byte order */ enum byte_order { ENDIAN_BIG = 1, @@ -266,6 +255,7 @@ enum nkf_encodings { UTF_32BE_BOM, UTF_32LE, UTF_32LE_BOM, + NKF_ENCODING_TABLE_SIZE, JIS_X_0201=0x1000, JIS_X_0208=0x1001, JIS_X_0212=0x1002, @@ -292,7 +282,7 @@ typedef struct { void (*oconv)(nkf_char c2, nkf_char c1); } nkf_native_encoding; -nkf_native_encoding NkfEncodingASCII = { "US_ASCII", e_iconv, e_oconv }; +nkf_native_encoding NkfEncodingASCII = { "ASCII", e_iconv, e_oconv }; nkf_native_encoding NkfEncodingISO_2022_JP = { "ISO-2022-JP", e_iconv, j_oconv }; nkf_native_encoding NkfEncodingShift_JIS = { "Shift_JIS", s_iconv, s_oconv }; nkf_native_encoding NkfEncodingEUC_JP = { "EUC-JP", e_iconv, e_oconv }; @@ -305,8 +295,9 @@ typedef struct { const char *name; const nkf_native_encoding *base_encoding; } nkf_encoding; + nkf_encoding nkf_encoding_table[] = { - {ASCII, "ASCII", &NkfEncodingASCII}, + {ASCII, "US-ASCII", &NkfEncodingASCII}, {ISO_8859_1, "ISO-8859-1", &NkfEncodingASCII}, {ISO_2022_JP, "ISO-2022-JP", &NkfEncodingISO_2022_JP}, {CP50220, "CP50220", &NkfEncodingISO_2022_JP}, @@ -342,14 +333,15 @@ nkf_encoding nkf_encoding_table[] = { {BINARY, "BINARY", &NkfEncodingASCII}, {-1, NULL, NULL} }; -#define NKF_ENCODING_TABLE_SIZE 34 + struct { const char *name; const int id; } encoding_name_to_id_table[] = { + {"US-ASCII", ASCII}, {"ASCII", ASCII}, {"ISO-2022-JP", ISO_2022_JP}, - {"X-ISO2022JP-CP932", CP50220}, + {"ISO2022JP-CP932", CP50220}, {"CP50220", CP50220}, {"CP50221", CP50221}, {"CP50222", CP50222}, @@ -928,6 +920,7 @@ static nkf_encoding *nkf_enc_from_index(int idx) static int nkf_enc_find_index(const char *name) { int i, index = -1; + if (*name == 'X' && *(name+1) == '-') name += 2; for (i = 0; encoding_name_to_id_table[i].id >= 0; i++) { if (strcmp(name, encoding_name_to_id_table[i].name) == 0) { return encoding_name_to_id_table[i].id; diff --git a/ext/nkf/nkf.c b/ext/nkf/nkf.c index b720198cf2..0cf16fa9e2 100644 --- a/ext/nkf/nkf.c +++ b/ext/nkf/nkf.c @@ -484,7 +484,7 @@ Init_nkf() rb_define_const(mNKF, "NOCONV", Qnil); rb_define_const(mNKF, "UNKNOWN", Qnil); rb_define_const(mNKF, "BINARY", rb_enc_from_encoding(rb_nkf_enc_get("BINARY"))); - rb_define_const(mNKF, "ASCII", rb_enc_from_encoding(rb_nkf_enc_get("ASCII"))); + rb_define_const(mNKF, "ASCII", rb_enc_from_encoding(rb_nkf_enc_get("US-ASCII"))); rb_define_const(mNKF, "JIS", rb_enc_from_encoding(rb_nkf_enc_get("ISO-2022-JP"))); rb_define_const(mNKF, "EUC", rb_enc_from_encoding(rb_nkf_enc_get("EUC-JP"))); rb_define_const(mNKF, "SJIS", rb_enc_from_encoding(rb_nkf_enc_get("Shift_JIS")));