diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-10 18:13:56 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-10 18:13:56 +0000 |
commit | 04e65c3862fd049a4fc972b67b739e3894b231af (patch) | |
tree | 6ad45e9bcc3471d70347b7d6c053a297d3e170bb | |
parent | 84a867fae8ef7bb0947e3809b190f1e36ca8fe80 (diff) |
merge revision(s) 33200: [Backport #5794]
* transcode.c: enabled econv newline option.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | test/ruby/test_econv.rb | 6 | ||||
-rw-r--r-- | transcode.c | 50 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 61 insertions, 1 deletions
@@ -1,3 +1,7 @@ +Sat Feb 11 03:13:27 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * transcode.c: enabled econv newline option. + Sat Feb 11 02:39:09 2012 CHIKANAGA Tomoyuki <nagachika00@gmail.com> * variable.c (set_const_visibility): clear inine-cache when constant's 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 64d093dbec..4c3a273e7a 100644 --- a/transcode.c +++ b/transcode.c @@ -15,6 +15,8 @@ #include "transcode_data.h" #include <ctype.h> +#define ENABLE_ECONV_NEWLINE_OPTION 1 + /* VALUE rb_cEncoding = rb_define_class("Encoding", rb_cObject); */ VALUE rb_eUndefinedConversionError; VALUE rb_eInvalidByteSequenceError; @@ -1889,6 +1891,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); } @@ -3112,11 +3115,15 @@ search_convpath_i(const char *sname, const char *dname, int depth, void *arg) * # [#<Encoding:UTF-8>, #<Encoding:EUC-JP>]] * * 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) * #=> [[#<Encoding:ISO-8859-1>, #<Encoding:UTF-8>], * # [#<Encoding:UTF-8>, #<Encoding:EUC-JP>], * # "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) * #=> [[#<Encoding:ISO-8859-1>, #<Encoding:UTF-8>], * # "universal_newline", * # [#<Encoding:UTF-8>, #<Encoding:UTF-32BE>]] @@ -3261,6 +3268,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 @@ -3509,6 +3519,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) { @@ -4388,6 +4437,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)); @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 84 +#define RUBY_PATCHLEVEL 85 #define RUBY_RELEASE_DATE "2012-02-11" #define RUBY_RELEASE_YEAR 2012 |