* string.c (rb_str_scrub): export with fixed length arguments, and
  allow nil as replacement string instead of omitting.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-11-01 07:55:56 +00:00
Родитель 97b88a1773
Коммит adbdd97d28
4 изменённых файлов: 19 добавлений и 18 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Fri Nov 1 16:55:52 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_scrub): export with fixed length arguments, and
allow nil as replacement string instead of omitting.
Fri Nov 1 06:20:44 2013 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* thread.c (rb_mutex_struct): reduce rb_mutex_t size by 8 bytes

Просмотреть файл

@ -774,6 +774,7 @@ VALUE rb_str_length(VALUE);
long rb_str_offset(VALUE, long);
size_t rb_str_capacity(VALUE);
VALUE rb_str_ellipsize(VALUE, long);
VALUE rb_str_scrub(VALUE, VALUE);
#if defined(__GNUC__) && !defined(__PCC__)
#define rb_str_new_cstr(str) __extension__ ( \
{ \

Просмотреть файл

@ -7973,20 +7973,18 @@ str_compat_and_valid(VALUE str, rb_encoding *enc)
* @param repl the replacement character
* @return If given string is invalid, returns a new string. Otherwise, returns Qnil.
*/
static VALUE
str_scrub0(int argc, VALUE *argv, VALUE str)
VALUE
rb_str_scrub(VALUE str, VALUE repl)
{
int cr = ENC_CODERANGE(str);
rb_encoding *enc;
int encidx;
VALUE repl;
if (cr == ENC_CODERANGE_7BIT || cr == ENC_CODERANGE_VALID)
return Qnil;
enc = STR_ENC_GET(str);
rb_scan_args(argc, argv, "01", &repl);
if (argc != 0) {
if (!NIL_P(repl)) {
repl = str_compat_and_valid(repl, enc);
}
@ -8225,10 +8223,11 @@ str_scrub0(int argc, VALUE *argv, VALUE str)
* "abc\u3042\x81".scrub("*") #=> "abc\u3042*"
* "abc\u3042\xE3\x80".scrub{|bytes| '<'+bytes.unpack('H*')[0]+'>' } #=> "abc\u3042<e380>"
*/
VALUE
rb_str_scrub(int argc, VALUE *argv, VALUE str)
static VALUE
str_scrub(int argc, VALUE *argv, VALUE str)
{
VALUE new = str_scrub0(argc, argv, str);
VALUE repl = argc ? (rb_check_arity(argc, 0, 1), argv[0]) : Qnil;
VALUE new = rb_str_scrub(str, repl);
return NIL_P(new) ? rb_str_dup(str): new;
}
@ -8249,7 +8248,8 @@ rb_str_scrub(int argc, VALUE *argv, VALUE str)
static VALUE
str_scrub_bang(int argc, VALUE *argv, VALUE str)
{
VALUE new = str_scrub0(argc, argv, str);
VALUE repl = argc ? (rb_check_arity(argc, 0, 1), argv[0]) : Qnil;
VALUE new = rb_str_scrub(str, repl);
if (!NIL_P(new)) rb_str_replace(str, new);
return str;
}
@ -8743,7 +8743,7 @@ Init_String(void)
rb_define_method(rb_cString, "getbyte", rb_str_getbyte, 1);
rb_define_method(rb_cString, "setbyte", rb_str_setbyte, 2);
rb_define_method(rb_cString, "byteslice", rb_str_byteslice, -1);
rb_define_method(rb_cString, "scrub", rb_str_scrub, -1);
rb_define_method(rb_cString, "scrub", str_scrub, -1);
rb_define_method(rb_cString, "scrub!", str_scrub_bang, -1);
rb_define_method(rb_cString, "to_i", rb_str_to_i, -1);

Просмотреть файл

@ -2660,8 +2660,6 @@ str_transcode_enc_args(VALUE str, volatile VALUE *arg1, volatile VALUE *arg2,
return dencidx;
}
VALUE rb_str_scrub(int argc, VALUE *argv, VALUE str);
static int
str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts)
{
@ -2697,14 +2695,11 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts)
ECONV_XML_ATTR_QUOTE_DECORATOR)) == 0) {
if (senc && senc == denc) {
if (ecflags & ECONV_INVALID_MASK) {
VALUE rep = Qnil;
if (!NIL_P(ecopts)) {
VALUE rep = rb_hash_aref(ecopts, sym_replace);
dest = rb_str_scrub(1, &rep, str);
rep = rb_hash_aref(ecopts, sym_replace);
}
else {
dest = rb_str_scrub(0, NULL, str);
}
*self = dest;
*self = rb_str_scrub(str, rep);
return dencidx;
}
return NIL_P(arg2) ? -1 : dencidx;