ruby-changes:7767
From: akr <ko1@a...>
Date: Thu, 11 Sep 2008 02:27:07 +0900 (JST)
Subject: [ruby-changes:7767] Ruby:r19288 (trunk): * transcode.c (make_encoding): new function.
akr 2008-09-11 02:26:49 +0900 (Thu, 11 Sep 2008) New Revision: 19288 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19288 Log: * transcode.c (make_encoding): new function. (make_encobj): new function. (econv_s_asciicompat_encoding): use make_encoding. (rb_econv_open_exc): use SUPPLEMENTAL_CONVERSION. (econv_convpath): use encoding object in the result. Modified files: trunk/ChangeLog trunk/test/ruby/test_econv.rb trunk/transcode.c Index: ChangeLog =================================================================== --- ChangeLog (revision 19287) +++ ChangeLog (revision 19288) @@ -1,3 +1,11 @@ +Thu Sep 11 02:25:34 2008 Tanaka Akira <akr@f...> + + * transcode.c (make_encoding): new function. + (make_encobj): new function. + (econv_s_asciicompat_encoding): use make_encoding. + (rb_econv_open_exc): use SUPPLEMENTAL_CONVERSION. + (econv_convpath): use encoding object in the result. + Thu Sep 11 02:14:38 2008 Tanaka Akira <akr@f...> * transcode.c (econv_convpath): new method. Index: test/ruby/test_econv.rb =================================================================== --- test/ruby/test_econv.rb (revision 19287) +++ test/ruby/test_econv.rb (revision 19288) @@ -809,21 +809,28 @@ end def test_convpath + eucjp = Encoding::EUC_JP + utf8 = Encoding::UTF_8 + utf16be = Encoding::UTF_16BE + utf16le = Encoding::UTF_16LE + iso88591 = Encoding::ISO_8859_1 + iso2022jp = Encoding::ISO_2022_JP + siso2022jp = Encoding::STATELESS_ISO_2022_JP assert_equal([], Encoding::Converter.new("", "").convpath) - assert_equal([["EUC-JP", "UTF-8"], ["UTF-8", "ISO-8859-1"]], - Encoding::Converter.new("EUC-JP", "ISO-8859-1").convpath) - assert_equal([["EUC-JP", "stateless-ISO-2022-JP"], ["stateless-ISO-2022-JP", "ISO-2022-JP"]], - Encoding::Converter.new("EUC-JP", "ISO-2022-JP").convpath) - assert_equal([["ISO-2022-JP", "stateless-ISO-2022-JP"], - ["stateless-ISO-2022-JP", "EUC-JP"], - ["EUC-JP", "UTF-8"], - ["UTF-8", "ISO-8859-1"]], - Encoding::Converter.new("ISO-2022-JP", "ISO-8859-1").convpath) - assert_equal(["universal_newline", ["UTF-8", "UTF-16BE"]], - Encoding::Converter.new("UTF-8", "UTF-16BE", universal_newline: true).convpath) - assert_equal([["UTF-16BE", "UTF-8"], "universal_newline"], - Encoding::Converter.new("UTF-16BE", "UTF-8", universal_newline: true).convpath) - assert_equal([["UTF-16BE", "UTF-8"], "universal_newline", ["UTF-8", "UTF-16LE"]], - Encoding::Converter.new("UTF-16BE", "UTF-16LE", universal_newline: true).convpath) + assert_equal([[eucjp, utf8], [utf8, iso88591]], + Encoding::Converter.new(eucjp, iso88591).convpath) + assert_equal([[eucjp, siso2022jp], [siso2022jp, iso2022jp]], + Encoding::Converter.new(eucjp, iso2022jp).convpath) + assert_equal([[iso2022jp, siso2022jp], + [siso2022jp, eucjp], + [eucjp, utf8], + [utf8, iso88591]], + Encoding::Converter.new(iso2022jp, iso88591).convpath) + assert_equal(["universal_newline", [utf8, utf16be]], + Encoding::Converter.new(utf8, utf16be, universal_newline: true).convpath) + assert_equal([[utf16be, utf8], "universal_newline"], + Encoding::Converter.new(utf16be, utf8, universal_newline: true).convpath) + assert_equal([[utf16be, utf8], "universal_newline", [utf8, utf16le]], + Encoding::Converter.new(utf16be, utf16le, universal_newline: true).convpath) end end Index: transcode.c =================================================================== --- transcode.c (revision 19287) +++ transcode.c (revision 19288) @@ -2560,6 +2560,22 @@ return enc; } +static rb_encoding * +make_encoding(const char *name) +{ + rb_encoding *enc; + enc = rb_enc_find(name); + if (!enc) + enc = make_dummy_encoding(name); + return enc; +} + +static VALUE +make_encobj(const char *name) +{ + return rb_enc_from_encoding(make_encoding(name)); +} + /* * call-seq: * Encoding::Converter.asciicompat_encoding(string) => encoding or nil @@ -2592,11 +2608,8 @@ if (result_name == NULL) return Qnil; - result_enc = rb_enc_find(result_name); + result_enc = make_encoding(result_name); - if (!result_enc) - result_enc = make_dummy_encoding(result_name); - return rb_enc_from_encoding(result_enc); } @@ -2695,7 +2708,7 @@ rb_exc_raise(rb_econv_open_exc(sname, dname, ecflags)); } - if (*sname && *dname) { /* check "" to "universal_newline" */ + if (!SUPPLEMENTAL_CONVERSION(sname, dname)) { if (!senc) senc = make_dummy_encoding(sname); if (!denc) @@ -2795,14 +2808,16 @@ * * ec = Encoding::Converter.new("ISo-8859-1", "EUC-JP", crlf_newline: true) * p ec.convpath - * #=> [["ISO-8859-1", "UTF-8"], ["UTF-8", "EUC-JP"], "crlf_newline"] + * #=> [[#<Encoding:ISO-8859-1>, #<Encoding:UTF-8>], + * # [#<Encoding:UTF-8>, #<Encoding:EUC-JP>], + * # "crlf_newline"] * - * A element of the array is a pair of string or a string. + * A element of the array is a pair of encodings or a string. * The pair means encoding conversion. * The string means decorator. * - * In the above example, ["ISO-8859-1", "UTF-8"] means a converter from - * ISO-8859-1 to UTF-8. + * In the above example, [#<Encoding:ISO-8859-1>, #<Encoding:UTF-8>] means + * a converter from ISO-8859-1 to UTF-8. * "crlf_newline" means newline converter from LF to CRLF. */ static VALUE @@ -2819,7 +2834,7 @@ if (SUPPLEMENTAL_CONVERSION(tr->src_encoding, tr->dst_encoding)) v = rb_str_new_cstr(tr->dst_encoding); else - v = rb_assoc_new(rb_str_new_cstr(tr->src_encoding), rb_str_new_cstr(tr->dst_encoding)); + v = rb_assoc_new(make_encobj(tr->src_encoding), make_encobj(tr->dst_encoding)); rb_ary_push(result, v); } return result; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/