string.c: export rb_str_scrub
* 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:
parent
97b88a1773
commit
adbdd97d28
@ -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>
|
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
|
* 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);
|
long rb_str_offset(VALUE, long);
|
||||||
size_t rb_str_capacity(VALUE);
|
size_t rb_str_capacity(VALUE);
|
||||||
VALUE rb_str_ellipsize(VALUE, long);
|
VALUE rb_str_ellipsize(VALUE, long);
|
||||||
|
VALUE rb_str_scrub(VALUE, VALUE);
|
||||||
#if defined(__GNUC__) && !defined(__PCC__)
|
#if defined(__GNUC__) && !defined(__PCC__)
|
||||||
#define rb_str_new_cstr(str) __extension__ ( \
|
#define rb_str_new_cstr(str) __extension__ ( \
|
||||||
{ \
|
{ \
|
||||||
|
20
string.c
20
string.c
@ -7973,20 +7973,18 @@ str_compat_and_valid(VALUE str, rb_encoding *enc)
|
|||||||
* @param repl the replacement character
|
* @param repl the replacement character
|
||||||
* @return If given string is invalid, returns a new string. Otherwise, returns Qnil.
|
* @return If given string is invalid, returns a new string. Otherwise, returns Qnil.
|
||||||
*/
|
*/
|
||||||
static VALUE
|
VALUE
|
||||||
str_scrub0(int argc, VALUE *argv, VALUE str)
|
rb_str_scrub(VALUE str, VALUE repl)
|
||||||
{
|
{
|
||||||
int cr = ENC_CODERANGE(str);
|
int cr = ENC_CODERANGE(str);
|
||||||
rb_encoding *enc;
|
rb_encoding *enc;
|
||||||
int encidx;
|
int encidx;
|
||||||
VALUE repl;
|
|
||||||
|
|
||||||
if (cr == ENC_CODERANGE_7BIT || cr == ENC_CODERANGE_VALID)
|
if (cr == ENC_CODERANGE_7BIT || cr == ENC_CODERANGE_VALID)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
|
||||||
enc = STR_ENC_GET(str);
|
enc = STR_ENC_GET(str);
|
||||||
rb_scan_args(argc, argv, "01", &repl);
|
if (!NIL_P(repl)) {
|
||||||
if (argc != 0) {
|
|
||||||
repl = str_compat_and_valid(repl, enc);
|
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\x81".scrub("*") #=> "abc\u3042*"
|
||||||
* "abc\u3042\xE3\x80".scrub{|bytes| '<'+bytes.unpack('H*')[0]+'>' } #=> "abc\u3042<e380>"
|
* "abc\u3042\xE3\x80".scrub{|bytes| '<'+bytes.unpack('H*')[0]+'>' } #=> "abc\u3042<e380>"
|
||||||
*/
|
*/
|
||||||
VALUE
|
static VALUE
|
||||||
rb_str_scrub(int argc, VALUE *argv, VALUE str)
|
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;
|
return NIL_P(new) ? rb_str_dup(str): new;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8249,7 +8248,8 @@ rb_str_scrub(int argc, VALUE *argv, VALUE str)
|
|||||||
static VALUE
|
static VALUE
|
||||||
str_scrub_bang(int argc, VALUE *argv, VALUE str)
|
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);
|
if (!NIL_P(new)) rb_str_replace(str, new);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@ -8743,7 +8743,7 @@ Init_String(void)
|
|||||||
rb_define_method(rb_cString, "getbyte", rb_str_getbyte, 1);
|
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, "setbyte", rb_str_setbyte, 2);
|
||||||
rb_define_method(rb_cString, "byteslice", rb_str_byteslice, -1);
|
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, "scrub!", str_scrub_bang, -1);
|
||||||
|
|
||||||
rb_define_method(rb_cString, "to_i", rb_str_to_i, -1);
|
rb_define_method(rb_cString, "to_i", rb_str_to_i, -1);
|
||||||
|
11
transcode.c
11
transcode.c
@ -2660,8 +2660,6 @@ str_transcode_enc_args(VALUE str, volatile VALUE *arg1, volatile VALUE *arg2,
|
|||||||
return dencidx;
|
return dencidx;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE rb_str_scrub(int argc, VALUE *argv, VALUE str);
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts)
|
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) {
|
ECONV_XML_ATTR_QUOTE_DECORATOR)) == 0) {
|
||||||
if (senc && senc == denc) {
|
if (senc && senc == denc) {
|
||||||
if (ecflags & ECONV_INVALID_MASK) {
|
if (ecflags & ECONV_INVALID_MASK) {
|
||||||
|
VALUE rep = Qnil;
|
||||||
if (!NIL_P(ecopts)) {
|
if (!NIL_P(ecopts)) {
|
||||||
VALUE rep = rb_hash_aref(ecopts, sym_replace);
|
rep = rb_hash_aref(ecopts, sym_replace);
|
||||||
dest = rb_str_scrub(1, &rep, str);
|
|
||||||
}
|
}
|
||||||
else {
|
*self = rb_str_scrub(str, rep);
|
||||||
dest = rb_str_scrub(0, NULL, str);
|
|
||||||
}
|
|
||||||
*self = dest;
|
|
||||||
return dencidx;
|
return dencidx;
|
||||||
}
|
}
|
||||||
return NIL_P(arg2) ? -1 : dencidx;
|
return NIL_P(arg2) ? -1 : dencidx;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user