diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-04-26 15:55:21 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-04-26 15:55:21 +0000 |
commit | 876146772787599c894369801034f1fed1d16b54 (patch) | |
tree | 91f02a41b3b508bfea3bffbe4e27985cac0a75d4 /transcode.c | |
parent | 3b937bbdc4abc6ec1d3ec5d6b4e31714e0456e35 (diff) |
* io.c (validate_enc_binmode, rb_io_extract_modeenc): set newline
decorator according to open mode.
* transcode.c (rb_econv_prepare_options): new function, to prepare
econv options with newline flags.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r-- | transcode.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/transcode.c b/transcode.c index 9433e6a3df..92ebf99b4a 100644 --- a/transcode.c +++ b/transcode.c @@ -2423,10 +2423,9 @@ str_transcoding_resize(VALUE destination, size_t len, size_t new_len) } static int -econv_opts(VALUE opt) +econv_opts(VALUE opt, int ecflags) { VALUE v; - int ecflags = 0; v = rb_hash_aref(opt, sym_invalid); if (NIL_P(v)) { @@ -2469,25 +2468,36 @@ econv_opts(VALUE opt) } } - v = rb_hash_aref(opt, sym_universal_newline); - if (RTEST(v)) - ecflags |= ECONV_UNIVERSAL_NEWLINE_DECORATOR; + { + int setflags = 0, newlineflag = 0; + + v = rb_hash_aref(opt, sym_universal_newline); + if (RTEST(v)) + setflags |= ECONV_UNIVERSAL_NEWLINE_DECORATOR; + newlineflag |= !NIL_P(v); + + v = rb_hash_aref(opt, sym_crlf_newline); + if (RTEST(v)) + setflags |= ECONV_CRLF_NEWLINE_DECORATOR; + newlineflag |= !NIL_P(v); - v = rb_hash_aref(opt, sym_crlf_newline); - if (RTEST(v)) - ecflags |= ECONV_CRLF_NEWLINE_DECORATOR; + v = rb_hash_aref(opt, sym_cr_newline); + if (RTEST(v)) + setflags |= ECONV_CR_NEWLINE_DECORATOR; + newlineflag |= !NIL_P(v); - v = rb_hash_aref(opt, sym_cr_newline); - if (RTEST(v)) - ecflags |= ECONV_CR_NEWLINE_DECORATOR; + if (newlineflag) { + ecflags &= ~ECONV_NEWLINE_DECORATOR_MASK; + ecflags |= setflags; + } + } return ecflags; } int -rb_econv_prepare_opts(VALUE opthash, VALUE *opts) +rb_econv_prepare_options(VALUE opthash, VALUE *opts, int ecflags) { - int ecflags; VALUE newhash = Qnil; VALUE v; @@ -2495,7 +2505,7 @@ rb_econv_prepare_opts(VALUE opthash, VALUE *opts) *opts = Qnil; return 0; } - ecflags = econv_opts(opthash); + ecflags = econv_opts(opthash, ecflags); v = rb_hash_aref(opthash, sym_replace); if (!NIL_P(v)) { @@ -2530,6 +2540,12 @@ rb_econv_prepare_opts(VALUE opthash, VALUE *opts) return ecflags; } +int +rb_econv_prepare_opts(VALUE opthash, VALUE *opts) +{ + return rb_econv_prepare_options(opthash, opts, 0); +} + rb_econv_t * rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE opthash) { |