summaryrefslogtreecommitdiff
path: root/transcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/transcode.c b/transcode.c
index 5031d49989..6d02875051 100644
--- a/transcode.c
+++ b/transcode.c
@@ -2307,28 +2307,27 @@ rb_econv_prepare_opts(VALUE opthash, VALUE *opts)
{
int ecflags;
VALUE newhash = Qnil;
+ VALUE v;
+
if (NIL_P(opthash)) {
*opts = Qnil;
return 0;
}
ecflags = econv_opts(opthash);
-
- if ((ecflags & ECONV_INVALID_MASK) == ECONV_INVALID_REPLACE ||
- (ecflags & ECONV_UNDEF_MASK) == ECONV_UNDEF_REPLACE) {
- VALUE v = rb_hash_aref(opthash, sym_replace);
- if (!NIL_P(v)) {
- StringValue(v);
- if (rb_enc_str_coderange(v) == ENC_CODERANGE_BROKEN) {
- VALUE dumped = rb_str_dump(v);
- rb_raise(rb_eArgError, "replacement string is broken: %s as %s",
- StringValueCStr(dumped),
- rb_enc_name(rb_enc_get(v)));
- }
- v = rb_str_new_frozen(v);
- newhash = rb_hash_new();
- rb_hash_aset(newhash, sym_replace, v);
- }
+ v = rb_hash_aref(opthash, sym_replace);
+ if (!NIL_P(v)) {
+ StringValue(v);
+ if (rb_enc_str_coderange(v) == ENC_CODERANGE_BROKEN) {
+ VALUE dumped = rb_str_dump(v);
+ rb_raise(rb_eArgError, "replacement string is broken: %s as %s",
+ StringValueCStr(dumped),
+ rb_enc_name(rb_enc_get(v)));
+ }
+ v = rb_str_new_frozen(v);
+ newhash = rb_hash_new();
+ rb_hash_aset(newhash, sym_replace, v);
}
+
if (!NIL_P(newhash))
rb_hash_freeze(newhash);
*opts = newhash;
@@ -2444,6 +2443,7 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts)
if (NIL_P(arg1)) {
return -1;
}
+ ecflags |= ECONV_INVALID_REPLACE | ECONV_UNDEF_REPLACE;
}
else {
arg1 = argv[0];