* transcode.c: enabled econv newline option.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
80f54e6810
commit
a1c5ebe787
@ -1,3 +1,7 @@
|
||||
Tue Sep 6 12:07:10 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* transcode.c: enabled econv newline option.
|
||||
|
||||
Tue Sep 6 06:44:57 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||
|
||||
* numeric.c (dbl2ival): Fix Float#divmod and #round for 32 bit
|
||||
|
@ -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
|
||||
|
50
transcode.c
50
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;
|
||||
@ -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)
|
||||
* # [#<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>]]
|
||||
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user