From a1c5ebe7875cd1b59865fe6c2b88c7981a25939d Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 6 Sep 2011 03:07:16 +0000 Subject: * transcode.c: enabled econv newline option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ test/ruby/test_econv.rb | 6 ++++++ transcode.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3570298a26..4f6d181b49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Sep 6 12:07:10 2011 Nobuyoshi Nakada + + * transcode.c: enabled econv newline option. + Tue Sep 6 06:44:57 2011 Marc-Andre Lafortune * numeric.c (dbl2ival): Fix Float#divmod and #round for 32 bit diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb index 765616da3d..080d027c4a 100644 --- a/test/ruby/test_econv.rb +++ b/test/ruby/test_econv.rb @@ -902,4 +902,10 @@ class TestEncodingConverter < Test::Unit::TestCase "".encode("euc-jp", :undef => :replace, :replace => broken) } end + + def test_newline_option + ec1 = Encoding::Converter.new("", "", universal_newline: true) + ec2 = Encoding::Converter.new("", "", newline: :universal) + assert_equal(ec1, ec2) + end end diff --git a/transcode.c b/transcode.c index 2c188b67f7..68ac71755c 100644 --- a/transcode.c +++ b/transcode.c @@ -15,6 +15,8 @@ #include "transcode_data.h" #include +#define ENABLE_ECONV_NEWLINE_OPTION 1 + /* VALUE rb_cEncoding = rb_define_class("Encoding", rb_cObject); */ VALUE rb_eUndefinedConversionError; VALUE rb_eInvalidByteSequenceError; @@ -1884,6 +1886,7 @@ rb_econv_add_converter(rb_econv_t *ec, const char *sname, const char *dname, int return -1; tr = load_transcoder_entry(entry); + if (!tr) return -1; return rb_econv_add_transcoder_at(ec, tr, n); } @@ -3107,11 +3110,15 @@ search_convpath_i(const char *sname, const char *dname, int depth, void *arg) * # [#, #]] * * p Encoding::Converter.search_convpath("ISO-8859-1", "EUC-JP", universal_newline: true) + * or + * p Encoding::Converter.search_convpath("ISO-8859-1", "EUC-JP", newline: :universal) * #=> [[#, #], * # [#, #], * # "universal_newline"] * * p Encoding::Converter.search_convpath("ISO-8859-1", "UTF-32BE", universal_newline: true) + * or + * p Encoding::Converter.search_convpath("ISO-8859-1", "UTF-32BE", newline: :universal) * #=> [[#, #], * # "universal_newline", * # [#, #]] @@ -3256,6 +3263,9 @@ rb_econv_init_by_convpath(VALUE self, VALUE convpath, * :undef => nil # raise error on undefined conversion (default) * :undef => :replace # replace undefined conversion * :replace => string # replacement string ("?" or "\uFFFD" if not specified) + * :newline => :universal # decorator for converting CRLF and CR to LF + * :newline => :crlf # decorator for converting LF to CRLF + * :newline => :cr # decorator for converting LF to CR * :universal_newline => true # decorator for converting CRLF and CR to LF * :crlf_newline => true # decorator for converting LF to CRLF * :cr_newline => true # decorator for converting LF to CR @@ -3504,6 +3514,45 @@ econv_convpath(VALUE self) return result; } +/* + * call-seq: + * ec == other -> true or false + */ +static VALUE +econv_equal(VALUE self, VALUE other) +{ + rb_econv_t *ec1 = check_econv(self); + rb_econv_t *ec2; + int i; + + if (!rb_typeddata_is_kind_of(other, &econv_data_type)) { + return Qnil; + } + ec2 = DATA_PTR(other); + if (!ec2) return Qfalse; + if (ec1->source_encoding_name != ec2->source_encoding_name && + strcmp(ec1->source_encoding_name, ec2->source_encoding_name)) + return Qfalse; + if (ec1->destination_encoding_name != ec2->destination_encoding_name && + strcmp(ec1->destination_encoding_name, ec2->destination_encoding_name)) + return Qfalse; + if (ec1->flags != ec2->flags) return Qfalse; + if (ec1->replacement_enc != ec2->replacement_enc && + strcmp(ec1->replacement_enc, ec2->replacement_enc)) + return Qfalse; + if (ec1->replacement_len != ec2->replacement_len) return Qfalse; + if (ec1->replacement_str != ec2->replacement_str && + memcmp(ec1->replacement_str, ec2->replacement_str, ec2->replacement_len)) + return Qfalse; + + if (ec1->num_trans != ec2->num_trans) return Qfalse; + for (i = 0; i < ec1->num_trans; i++) { + if (ec1->elems[i].tc->transcoder != ec2->elems[i].tc->transcoder) + return Qfalse; + } + return Qtrue; +} + static VALUE econv_result_to_symbol(rb_econv_result_t res) { @@ -4383,6 +4432,7 @@ Init_transcode(void) rb_define_method(rb_cEncodingConverter, "last_error", econv_last_error, 0); rb_define_method(rb_cEncodingConverter, "replacement", econv_get_replacement, 0); rb_define_method(rb_cEncodingConverter, "replacement=", econv_set_replacement, 1); + rb_define_method(rb_cEncodingConverter, "==", econv_equal, 1); rb_define_const(rb_cEncodingConverter, "INVALID_MASK", INT2FIX(ECONV_INVALID_MASK)); rb_define_const(rb_cEncodingConverter, "INVALID_REPLACE", INT2FIX(ECONV_INVALID_REPLACE)); -- cgit v1.2.3