summaryrefslogtreecommitdiff
path: root/transcode.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-01-11 10:19:29 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-01-11 10:42:22 +0900
commiteb737916b1e435ff8212913c03e5798089b0d3fe (patch)
tree924832351005da6aa5aba1d0bbb21908f24b306c /transcode.c
parent8bb24712de04cfa8bb1dbfc0c3cee3de6eb4b40d (diff)
Warn when :newline precedes other newline options
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/transcode.c b/transcode.c
index a336f5d9ad..5cdaaaf61f 100644
--- a/transcode.c
+++ b/transcode.c
@@ -2418,6 +2418,7 @@ static int
econv_opts(VALUE opt, int ecflags)
{
VALUE v;
+ int newlineflag = 0;
v = rb_hash_aref(opt, sym_invalid);
if (NIL_P(v)) {
@@ -2463,6 +2464,7 @@ econv_opts(VALUE opt, int ecflags)
#ifdef ENABLE_ECONV_NEWLINE_OPTION
v = rb_hash_aref(opt, sym_newline);
if (!NIL_P(v)) {
+ newlineflag = 2;
ecflags &= ~ECONV_NEWLINE_DECORATOR_MASK;
if (v == sym_universal) {
ecflags |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;
@@ -2484,10 +2486,9 @@ econv_opts(VALUE opt, int ecflags)
rb_raise(rb_eArgError, "unexpected value for newline option");
}
}
- else
#endif
{
- int setflags = 0, newlineflag = 0;
+ int setflags = 0;
v = rb_hash_aref(opt, sym_universal_newline);
if (RTEST(v))
@@ -2504,9 +2505,15 @@ econv_opts(VALUE opt, int ecflags)
setflags |= ECONV_CR_NEWLINE_DECORATOR;
newlineflag |= !NIL_P(v);
- if (newlineflag) {
+ switch (newlineflag) {
+ case 1:
ecflags &= ~ECONV_NEWLINE_DECORATOR_MASK;
ecflags |= setflags;
+ break;
+
+ case 3:
+ rb_warning(":newline option preceds other newline options");
+ break;
}
}