[#32945] Shift_JIS variants and UTF-16 support — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

22 messages 2008/01/07
[#32953] Re: Shift_JIS variants and UTF-16 support — Martin Duerst <duerst@...> 2008/01/07

中村さん、こんにちは。

[#32955] Re: Shift_JIS variants and UTF-16 support — Yukihiro Matsumoto <matz@...> 2008/01/07

まつもと ゆきひろです

[#32959] Re: Shift_JIS variants and UTF-16 support — "NARUSE, Yui" <naruse@...> 2008/01/07

成瀬です。

[#32960] Re: Shift_JIS variants and UTF-16 support — Yukihiro Matsumoto <matz@...> 2008/01/07

まつもと ゆきひろです

[#32992] ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...>

成瀬です。

18 messages 2008/01/08
[#32994] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/09

まつもと ゆきひろです

[#32995] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Martin Duerst <duerst@...> 2008/01/09

At 18:13 08/01/09, Yukihiro Matsumoto wrote:

[#33011] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...> 2008/01/11

成瀬です。

[#33012] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/11

まつもと ゆきひろです

[#33014] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...> 2008/01/11

成瀬です。

[#33015] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/11

まつもと ゆきひろです

[#33239] Re: [ruby-cvs:22386] Ruby:r15149 (trunk): * string.c (rb_str_each_char): move forward. — Tanaka Akira <akr@...>

In article <200801210259.m0L2x3CW017171@ci.ruby-lang.org>,

11 messages 2008/01/21
[#33240] Re: [ruby-cvs:22386] Ruby:r15149 (trunk): * string.c (rb_str_each_char): move forward. — Nobuyoshi Nakada <nobu@...> 2008/01/21

なかだです。

[#33303] Time#strftimeのエンコーディング — rubikitch@...

るびきちです。

13 messages 2008/01/23
[#33305] Re: Time#strftimeのエンコーディング — Yukihiro Matsumoto <matz@...> 2008/01/23

まつもと ゆきひろです

[#33368] summary of script encoding — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

22 messages 2008/01/25
[#33375] Re: summary of script encoding — Yukihiro Matsumoto <matz@...> 2008/01/25

まつもと ゆきひろです

[#33376] Re: summary of script encoding — "U.Nakamura" <usa@...> 2008/01/25

こんにちは、なかむら(う)です。

[#33387] HashからStructを作る — rubikitch@...

るびきちです。

19 messages 2008/01/25
[#33455] Re: HashからStructを作る — Yukihiro Matsumoto <matz@...> 2008/01/28

まつもと ゆきひろです

[#33505] Re: HashからStructを作る — rubikitch@... 2008/01/29

From: Yukihiro Matsumoto <matz@ruby-lang.org>

[#33507] Re: HashからStructを作る — Yukihiro Matsumoto <matz@...> 2008/01/29

まつもと ゆきひろです

[#33508] Re: HashからStructを作る — rubikitch@... 2008/01/29

From: Yukihiro Matsumoto <matz@ruby-lang.org>

[#33433] Win32OLE: set encoding to OLE string — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

16 messages 2008/01/28

[#33461] Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...>

=1B$B?9ED$H?=3D$7$^$9!#=1B(B

19 messages 2008/01/28
[#33473] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Nobuyoshi Nakada <nobu@...> 2008/01/28

なかだです。

[#33503] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/29

森田です。

[#33514] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Nobuyoshi Nakada <nobu@...> 2008/01/29

なかだです。

[#33518] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/30

森田です。

[#33545] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Ryutaro Amano <wn9r-amn@...> 2008/01/31

天野竜太郎と申します。

[#33546] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/31

森田です。

[#33547] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Ryutaro Amano <wn9r-amn@...> 2008/01/31

天野です。

[#33551] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/31

森田です。

[#33488] 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...>

永井@知能.九工大です.

20 messages 2008/01/29
[#33491] Re: 現在の script encoding の値を得る方法は? — Yukihiro Matsumoto <matz@...> 2008/01/29

まつもと ゆきひろです

[#33500] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/29

永井@知能.九工大です.

[#33501] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/29

成瀬です。

[#33515] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/30

永井@知能.九工大です.

[#33516] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/30

成瀬です。

[#33519] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/30

永井@知能.九工大です.

[#33522] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/30

成瀬です。

[ruby-dev:33067] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy

From: "NARUSE, Yui" <naruse@...>
Date: 2008-01-12 12:58:48 UTC
List: ruby-dev #33067
成瀬です。

Yukihiro Matsumoto wrote:
> |= 別名の定義
> |
> |どこで定義するのが一番メンテしやすいかといえば、enc/*.c の
> |OnigEncodingDefine() の後で別名も定義してしまうということになるのではな
> |いでしょうか。
> |
> |後はビルド時に enc/make_encmake.rb でそれぞれのファイルを見てまわって、
> |あらかじめエンコーディング名と別名のテーブルを用意しておけばよいかと。
> 
> 誰かそういうの作ってくれる人、いませんか?

これと

> 必要なのは
>
> (1) ロードされている Encoding オブジェクトの array を返す
>     Encoding.list
> (2) 利用可能なEncoding名の配列を返すEncoding.name_list
> (3) 利用可能なaliasを表現するEncoding.aliases(名前から名前へ
>     のhashを返す)。
>
> の3つじゃないかと思います。優先順位は(2)→(1)→(3)かな。
> (3)はなくてもいいかも。

と、

[ruby-dev:32992] の "ASCII" を ASCII-8BIT ではなく US-ASCII の alias に
するパッチです。このパッチで SJIS と EUCJP をビルトインから外せると思う
のですがどうしましょう。

-- 
NARUSE, Yui  <naruse@airemix.com>
DBDB A476 FDBD 9450 02CD 0EFC BCE3 C388 472E C1EA

Attachments (1)

make_encdb.txt (6.77 KB, text/x-diff)
Index: encoding.c
===================================================================
--- encoding.c	(revision 15003)
+++ encoding.c	(working copy)
@@ -12,6 +12,7 @@
 #include "ruby/ruby.h"
 #include "ruby/encoding.h"
 #include "regenc.h"
+#include "encdb.h"
 #include <ctype.h>
 #ifdef HAVE_LANGINFO_H
 #include <langinfo.h>
@@ -307,10 +308,6 @@ rb_enc_init(void)
     ENC_REGISTER(SJIS);
     ENC_REGISTER(UTF8);
 #undef ENC_REGISTER
-    enc_alias("ASCII", rb_enc_name(ONIG_ENCODING_ASCII));
-    enc_alias("BINARY", rb_enc_name(ONIG_ENCODING_ASCII));
-    enc_alias("eucJP", rb_enc_name(ONIG_ENCODING_EUC_JP)); /* UI-OSF Application Platform Profile for Japanese Environment Version 1.1 */
-    enc_alias("SJIS", rb_enc_name(ONIG_ENCODING_SJIS));
 }
 
 rb_encoding *
@@ -373,6 +370,20 @@ rb_enc_find_index(const char *name)
 	OBJ_FREEZE(enclib);
 	if (RTEST(rb_protect(require_enc, enclib, 0)))
 	    i = rb_enc_registered(name);
+	else {
+	    st_data_t key = (st_data_t)name, orig;
+	    if (st_lookup(enc_table_replica_name, key, &orig)) {
+		i = rb_enc_find_index((char *)orig);
+		if (i < 0) {
+		    rb_raise(rb_eRuntimeError, "unknown original encoding name - %s for %s", (char *)orig, name);
+		}
+		i = rb_enc_replicate(name, rb_enc_from_index(i));
+		st_delete(enc_table_replica_name, &key, &orig);
+	    } else if (st_lookup(enc_table_alias_name, key, &orig)) {
+		i = rb_enc_alias(name, (char *)orig);
+		st_delete(enc_table_replica_name, &key, &orig);
+	    }
+	}
 	rb_set_errinfo(Qnil);
     }
     return i;
@@ -978,6 +989,40 @@ set_encoding_alias(st_data_t name, st_da
     return ST_CONTINUE;
 }
 
+static VALUE
+rb_enc_name_list(VALUE klass)
+{
+    VALUE ary = rb_ary_new2(enc_name_list_size);
+    int i;
+    for (i = 0; i < enc_name_list_size; i++) {
+	rb_ary_push(ary, rb_str_new2(enc_name_list[i]));
+    }
+    return ary;
+}
+
+static int
+rb_enc_aliases_enc_i(st_data_t name, st_data_t orig, st_data_t arg)
+{
+    rb_hash_aset((VALUE)arg, rb_str_new2((char *)name), rb_enc_name(rb_enc_from_index((int)orig)));
+    return 0;
+}
+
+static int
+rb_enc_aliases_str_i(st_data_t name, st_data_t orig, st_data_t arg)
+{
+    rb_hash_aset((VALUE)arg, rb_str_new2((char *)name), rb_str_new2((char *)orig));
+    return 0;
+}
+
+static VALUE
+rb_enc_aliases(VALUE klass)
+{
+    VALUE aliases = rb_hash_new();
+    st_foreach(enc_table_alias, rb_enc_aliases_enc_i, (st_data_t)aliases);
+    st_foreach(enc_table_alias_name, rb_enc_aliases_str_i, (st_data_t)aliases);
+    return aliases;
+}
+
 void
 Init_Encoding(void)
 {
@@ -993,6 +1038,8 @@ Init_Encoding(void)
     rb_define_method(rb_cEncoding, "base_encoding", enc_base_encoding, 0);
     rb_define_method(rb_cEncoding, "dummy?", enc_dummy_p, 0);
     rb_define_singleton_method(rb_cEncoding, "list", enc_list, 0);
+    rb_define_singleton_method(rb_cEncoding, "name_list", rb_enc_name_list, 0);
+    rb_define_singleton_method(rb_cEncoding, "aliases", rb_enc_aliases, 0);
     rb_define_singleton_method(rb_cEncoding, "find", enc_find, 1);
     rb_define_singleton_method(rb_cEncoding, "compatible?", enc_compatible_p, 2);
 
@@ -1001,19 +1048,14 @@ Init_Encoding(void)
 
     rb_define_singleton_method(rb_cEncoding, "default_external", get_default_external, 0);
     rb_define_singleton_method(rb_cEncoding, "locale_charmap", rb_locale_charmap, 0);
-
-    /* dummy for unsupported, statefull encoding */
-    rb_define_dummy_encoding("ISO-2022-JP");
-
-    rb_enc_replicate("Windows-31J", rb_enc_from_index(ENCINDEX_SJIS));
-    rb_enc_alias("CP932", "Windows-31J");
-    rb_enc_alias("csWindows31J", "Windows-31J"); /* IANA.  IE6 don't accept Windows-31J but csWindows31J. */
-
+    /*
     for (i = 0; i < enc_table_size; ++i) {
 	rb_encoding *enc = enc_table[i].enc;
 	if (enc) set_encoding_const(rb_enc_name(enc), enc);
     }
     st_foreach(enc_table_alias, set_encoding_alias, 0);
+    */
+    enc_init_db();
 }
 
 /* locale insensitive functions */
Index: regenc.h
===================================================================
--- regenc.h	(revision 15003)
+++ regenc.h	(working copy)
@@ -199,4 +199,7 @@ extern int ONIG_ENC_REGISTER(const char 
 #define OnigEncodingDefine(f,n) OnigEncodingDeclare(n)
 #endif
 
+#define ENC_ALIAS(name, orig)
+#define ENC_REPLICATE(name, orig)
+
 #endif /* REGENC_H */
Index: enc/us_ascii.c
===================================================================
--- enc/us_ascii.c	(revision 15003)
+++ enc/us_ascii.c	(working copy)
@@ -26,3 +26,6 @@ OnigEncodingDefine(us_ascii, US_ASCII) =
   onigenc_single_byte_left_adjust_char_head,
   onigenc_always_true_is_allowed_reverse_match
 };
+ENC_ALIAS("ASCII", "US-ASCII");
+ENC_ALIAS("ANSI_X3.4-1986", "US-ASCII");
+
Index: enc/euc_jp.c
===================================================================
--- enc/euc_jp.c	(revision 15003)
+++ enc/euc_jp.c	(working copy)
@@ -361,3 +361,4 @@ OnigEncodingDefine(euc_jp, EUC_JP) = {
   is_allowed_reverse_match,
   0
 };
+ENC_ALIAS("eucJP", "EUC-JP"); /* UI-OSF Application Platform Profile for Japanese Environment Version 1.1 */
Index: enc/sjis.c
===================================================================
--- enc/sjis.c	(revision 15003)
+++ enc/sjis.c	(working copy)
@@ -370,3 +370,7 @@ OnigEncodingDefine(sjis, SJIS) = {
   is_allowed_reverse_match,
   0
 };
+ENC_ALIAS("SJIS", "Shift_JIS");
+ENC_REPLICATE("Windows-31J", "Shift_JIS");
+ENC_ALIAS("CP932", "Windows-31J");
+ENC_ALIAS("csWindows31J", "Windows-31J"); /* IANA.  IE6 don't accept Windows-31J but csWindows31J. */
Index: enc/ascii.c
===================================================================
--- enc/ascii.c	(revision 15003)
+++ enc/ascii.c	(working copy)
@@ -47,3 +47,4 @@ OnigEncodingDefine(ascii, ASCII) = {
   onigenc_single_byte_left_adjust_char_head,
   onigenc_always_true_is_allowed_reverse_match
 };
+ENC_ALIAS("BINARY", "ASCII-8BIT");
Index: common.mk
===================================================================
--- common.mk	(revision 15003)
+++ common.mk	(working copy)
@@ -431,7 +431,7 @@ dmyext.$(OBJEXT): {$(VPATH)}dmyext.c
 encoding.$(OBJEXT): {$(VPATH)}encoding.c {$(VPATH)}ruby.h \
   {$(VPATH)}config.h {$(VPATH)}defines.h {$(VPATH)}missing.h \
   {$(VPATH)}intern.h {$(VPATH)}st.h {$(VPATH)}encoding.h \
-  {$(VPATH)}oniguruma.h {$(VPATH)}regenc.h
+  {$(VPATH)}oniguruma.h {$(VPATH)}regenc.h {$(VPATH)}encdb.h
 enum.$(OBJEXT): {$(VPATH)}enum.c {$(VPATH)}ruby.h {$(VPATH)}config.h \
   {$(VPATH)}defines.h {$(VPATH)}missing.h {$(VPATH)}intern.h \
   {$(VPATH)}st.h {$(VPATH)}node.h {$(VPATH)}util.h
@@ -708,6 +708,9 @@ incs: $(INSNS) {$(VPATH)}node_name.inc {
 node_name.inc: {$(VPATH)}node.h
 	$(BASERUBY) -n $(srcdir)/tool/node_name.rb $? > $@
 
+encdb.h: $(srcdir)/enc/make_encdb.rb
+	$(BASERUBY) -I$(srcdir) $(srcdir)/enc/make_encdb.rb
+
 miniprelude.c: $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb
 	$(BASERUBY) -I$(srcdir) $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $@
 

In This Thread