ruby-changes:7659
From: akr <ko1@a...>
Date: Sat, 6 Sep 2008 15:07:52 +0900 (JST)
Subject: [ruby-changes:7659] Ruby:r19180 (trunk): * transcode.c (sym_html): new variable.
akr 2008-09-06 15:07:34 +0900 (Sat, 06 Sep 2008) New Revision: 19180 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19180 Log: * transcode.c (sym_html): new variable. (sym_text): ditto. (sym_attr): ditto. (econv_opts): check :html=>:text and :html=>:attr. (Init_transcode): initialize the above variables. Modified files: trunk/ChangeLog trunk/test/ruby/test_econv.rb trunk/transcode.c Index: ChangeLog =================================================================== --- ChangeLog (revision 19179) +++ ChangeLog (revision 19180) @@ -1,3 +1,11 @@ +Sat Sep 6 15:06:21 2008 Tanaka Akira <akr@f...> + + * transcode.c (sym_html): new variable. + (sym_text): ditto. + (sym_attr): ditto. + (econv_opts): check :html=>:text and :html=>:attr. + (Init_transcode): initialize the above variables. + Sat Sep 6 14:46:12 2008 Tanaka Akira <akr@f...> * include/ruby/encoding.h (ECONV_HTML_TEXT_ENCODER): new constant. Index: test/ruby/test_econv.rb =================================================================== --- test/ruby/test_econv.rb (revision 19179) +++ test/ruby/test_econv.rb (revision 19180) @@ -768,4 +768,11 @@ assert_equal("&\e$B$&\e(B&".force_encoding("iso-2022-jp"), ec.convert("&\u3046&")) assert_equal('', ec.finish) end + + def test_html_hasharg + assert_equal("&\e$B$&\e(B♥&\"'".force_encoding("iso-2022-jp"), + "&\u3046\u2665&\"'".encode("iso-2022-jp", html: :text)) + assert_equal("\"&\e$B$&\e(B♡&"'\"".force_encoding("iso-2022-jp"), + "&\u3046\u2661&\"'".encode("iso-2022-jp", html: :attr)) + end end Index: transcode.c =================================================================== --- transcode.c (revision 19179) +++ transcode.c (revision 19180) @@ -21,6 +21,7 @@ VALUE rb_cEncodingConverter; static VALUE sym_invalid, sym_undef, sym_ignore, sym_replace; +static VALUE sym_html, sym_text, sym_attr; static VALUE sym_universal_newline_decoder; static VALUE sym_crlf_newline_encoder; static VALUE sym_cr_newline_encoder; @@ -2133,6 +2134,20 @@ rb_raise(rb_eArgError, "unknown value for undefined character option"); } + v = rb_hash_aref(opt, sym_html); + if (!NIL_P(v)) { + v = rb_convert_type(v, T_SYMBOL, "Symbol", "to_sym"); + if (v==sym_text) { + ecflags |= ECONV_HTML_TEXT_ENCODER|ECONV_UNDEF_HEX_CHARREF; + } + else if (v==sym_attr) { + ecflags |= ECONV_HTML_ATTR_ENCODER|ECONV_UNDEF_HEX_CHARREF; + } + else { + rb_raise(rb_eArgError, "unexpected value for html option: %s", rb_id2name(SYM2ID(v))); + } + } + v = rb_hash_aref(opt, sym_universal_newline_decoder); if (RTEST(v)) ecflags |= ECONV_UNIVERSAL_NEWLINE_DECODER; @@ -3477,6 +3492,9 @@ sym_undef = ID2SYM(rb_intern("undef")); sym_ignore = ID2SYM(rb_intern("ignore")); sym_replace = ID2SYM(rb_intern("replace")); + sym_html = ID2SYM(rb_intern("html")); + sym_text = ID2SYM(rb_intern("text")); + sym_attr = ID2SYM(rb_intern("attr")); sym_invalid_byte_sequence = ID2SYM(rb_intern("invalid_byte_sequence")); sym_undefined_conversion = ID2SYM(rb_intern("undefined_conversion")); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/