ruby-changes:7673
From: akr <ko1@a...>
Date: Sun, 7 Sep 2008 00:39:19 +0900 (JST)
Subject: [ruby-changes:7673] Ruby:r19193 (trunk): * include/ruby/encoding.h (ECONV_ERROR_HANDLER_MASK): defined.
akr 2008-09-07 00:39:00 +0900 (Sun, 07 Sep 2008) New Revision: 19193 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19193 Log: * include/ruby/encoding.h (ECONV_ERROR_HANDLER_MASK): defined. (ECONV_DECODER_MASK): defined. (ECONV_ENCODER_MASK): defined. * io.c (make_writeconv): restrict ecflags for writeconv with ECONV_ERROR_HANDLER_MASK. Modified files: trunk/ChangeLog trunk/include/ruby/encoding.h trunk/io.c trunk/test/ruby/test_io_m17n.rb Index: include/ruby/encoding.h =================================================================== --- include/ruby/encoding.h (revision 19192) +++ include/ruby/encoding.h (revision 19193) @@ -250,27 +250,32 @@ void rb_econv_binmode(rb_econv_t *ec); /* flags for rb_econv_open */ -#define ECONV_INVALID_MASK 0x000f -#define ECONV_INVALID_REPLACE 0x0002 -#define ECONV_UNDEF_MASK 0x00f0 -#define ECONV_UNDEF_REPLACE 0x0020 -#define ECONV_UNDEF_HEX_CHARREF 0x0030 +#define ECONV_ERROR_HANDLER_MASK 0x000000ff +#define ECONV_INVALID_MASK 0x0000000f +#define ECONV_INVALID_REPLACE 0x00000002 + +#define ECONV_UNDEF_MASK 0x000000f0 +#define ECONV_UNDEF_REPLACE 0x00000020 +#define ECONV_UNDEF_HEX_CHARREF 0x00000030 + /* usable only if destination encoding is ascii compatible */ -#define ECONV_UNIVERSAL_NEWLINE_DECODER 0x0100 +#define ECONV_DECODER_MASK 0x00000f00 +#define ECONV_UNIVERSAL_NEWLINE_DECODER 0x00000100 /* usable only if source encoding is ascii compatible */ -#define ECONV_CRLF_NEWLINE_ENCODER 0x0200 -#define ECONV_CR_NEWLINE_ENCODER 0x0400 -#define ECONV_XML_TEXT_ENCODER 0x0800 -#define ECONV_XML_ATTR_ENCODER 0x1000 +#define ECONV_ENCODER_MASK 0x0000f000 +#define ECONV_CRLF_NEWLINE_ENCODER 0x00001000 +#define ECONV_CR_NEWLINE_ENCODER 0x00002000 +#define ECONV_XML_TEXT_ENCODER 0x00004000 +#define ECONV_XML_ATTR_ENCODER 0x00008000 /* end of flags for rb_econv_open */ /* flags for rb_econv_convert */ -#define ECONV_PARTIAL_INPUT 0x10000 -#define ECONV_OUTPUT_FOLLOWED_BY_INPUT 0x20000 +#define ECONV_PARTIAL_INPUT 0x00010000 +#define ECONV_OUTPUT_FOLLOWED_BY_INPUT 0x00020000 /* end of flags for rb_econv_convert */ #endif /* RUBY_ENCODING_H */ Index: ChangeLog =================================================================== --- ChangeLog (revision 19192) +++ ChangeLog (revision 19193) @@ -1,3 +1,12 @@ +Sun Sep 7 00:37:25 2008 Tanaka Akira <akr@f...> + + * include/ruby/encoding.h (ECONV_ERROR_HANDLER_MASK): defined. + (ECONV_DECODER_MASK): defined. + (ECONV_ENCODER_MASK): defined. + + * io.c (make_writeconv): restrict ecflags for writeconv with + ECONV_ERROR_HANDLER_MASK. + Sat Sep 6 23:03:41 2008 Tanaka Akira <akr@f...> * include/ruby/encoding.h (ECONV_XML_TEXT_ENCODER): renamed from Index: io.c =================================================================== --- io.c (revision 19192) +++ io.c (revision 19193) @@ -716,6 +716,7 @@ if (NEED_NEWLINE_ENCODER(fptr)) fptr->writeconv_pre_ecflags |= TEXTMODE_NEWLINE_ENCODER; #endif + ecflags &= ECONV_ERROR_HANDLER_MASK; enc = fptr->encs.enc2 ? fptr->encs.enc2 : fptr->encs.enc; senc = rb_econv_stateless_encoding(enc->name); Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 19192) +++ test/ruby/test_io_m17n.rb (revision 19193) @@ -1459,5 +1459,27 @@ } end + def test_w_xml_attr + with_tmpdir { + open("eucjp.txt", "w:euc-jp:utf-8", xml: :attr) {|f| + f.print "\u4E02" # U+4E02 is 0x3021 in JIS X 0212 + } + content = File.read("eucjp.txt", :mode=>"rb:ascii-8bit") + assert_equal("\"\x8F\xB0\xA1\"".force_encoding("ascii-8bit"), content) + + open("sjis.txt", "w:sjis:utf-8", xml: :attr) {|f| + f.print "\u4E02" # U+4E02 is 0x3021 in JIS X 0212 + } + content = File.read("sjis.txt", :mode=>"rb:ascii-8bit") + assert_equal("\"丂\"".force_encoding("ascii-8bit"), content) + + open("iso-2022-jp.txt", "w:iso-2022-jp:utf-8", xml: :attr) {|f| + f.print "\u4E02" # U+4E02 is 0x3021 in JIS X 0212 + } + content = File.read("iso-2022-jp.txt", :mode=>"rb:ascii-8bit") + assert_equal("\"丂\"".force_encoding("ascii-8bit"), content) + } + end + end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/