string.c: replacement and block
* string.c (rb_enc_str_scrub): only one of replacement and block is allowed. [ruby-core:79038] [Bug #13119] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a3aa4da773
commit
9029464175
14
string.c
14
string.c
@ -9206,9 +9206,15 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl)
|
|||||||
int encidx;
|
int encidx;
|
||||||
VALUE buf = Qnil;
|
VALUE buf = Qnil;
|
||||||
const char *rep;
|
const char *rep;
|
||||||
long replen;
|
long replen = -1;
|
||||||
int tainted = 0;
|
int tainted = 0;
|
||||||
|
|
||||||
|
if (rb_block_given_p()) {
|
||||||
|
if (!NIL_P(repl))
|
||||||
|
rb_raise(rb_eArgError, "both of block and replacement given");
|
||||||
|
replen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (ENC_CODERANGE_CLEAN_P(cr))
|
if (ENC_CODERANGE_CLEAN_P(cr))
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
|
||||||
@ -9232,9 +9238,8 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl)
|
|||||||
const char *e = RSTRING_END(str);
|
const char *e = RSTRING_END(str);
|
||||||
const char *p1 = p;
|
const char *p1 = p;
|
||||||
int rep7bit_p;
|
int rep7bit_p;
|
||||||
if (rb_block_given_p()) {
|
if (!replen) {
|
||||||
rep = NULL;
|
rep = NULL;
|
||||||
replen = 0;
|
|
||||||
rep7bit_p = FALSE;
|
rep7bit_p = FALSE;
|
||||||
}
|
}
|
||||||
else if (!NIL_P(repl)) {
|
else if (!NIL_P(repl)) {
|
||||||
@ -9345,9 +9350,8 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl)
|
|||||||
const char *e = RSTRING_END(str);
|
const char *e = RSTRING_END(str);
|
||||||
const char *p1 = p;
|
const char *p1 = p;
|
||||||
long mbminlen = rb_enc_mbminlen(enc);
|
long mbminlen = rb_enc_mbminlen(enc);
|
||||||
if (rb_block_given_p()) {
|
if (!replen) {
|
||||||
rep = NULL;
|
rep = NULL;
|
||||||
replen = 0;
|
|
||||||
}
|
}
|
||||||
else if (!NIL_P(repl)) {
|
else if (!NIL_P(repl)) {
|
||||||
rep = RSTRING_PTR(repl);
|
rep = RSTRING_PTR(repl);
|
||||||
|
@ -1625,6 +1625,7 @@ class TestM17N < Test::Unit::TestCase
|
|||||||
|
|
||||||
assert_equal(u("\x81"), u("a\x81c").scrub {|c| break c})
|
assert_equal(u("\x81"), u("a\x81c").scrub {|c| break c})
|
||||||
assert_raise(ArgumentError) {u("a\x81").scrub {|c| c}}
|
assert_raise(ArgumentError) {u("a\x81").scrub {|c| c}}
|
||||||
|
assert_raise(ArgumentError) {u("a").scrub("?") {|c| c}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_scrub_widechar
|
def test_scrub_widechar
|
||||||
@ -1645,6 +1646,7 @@ class TestM17N < Test::Unit::TestCase
|
|||||||
"\x00\xD8\x42\x30".force_encoding(Encoding::UTF_16LE).
|
"\x00\xD8\x42\x30".force_encoding(Encoding::UTF_16LE).
|
||||||
scrub {|e| c = e; "?".encode(Encoding::UTF_16LE)})
|
scrub {|e| c = e; "?".encode(Encoding::UTF_16LE)})
|
||||||
assert_equal("\x00\xD8".force_encoding(Encoding::UTF_16LE), c)
|
assert_equal("\x00\xD8".force_encoding(Encoding::UTF_16LE), c)
|
||||||
|
assert_raise(ArgumentError) {"\uFFFD\u3042".encode("UTF-16BE").scrub("") {}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_scrub_dummy_encoding
|
def test_scrub_dummy_encoding
|
||||||
|
Loading…
x
Reference in New Issue
Block a user