[前][次][番号順一覧][スレッド一覧]

ruby-changes:31421

From: nobu <ko1@a...>
Date: Fri, 1 Nov 2013 16:56:01 +0900 (JST)
Subject: [ruby-changes:31421] nobu:r43500 (trunk): string.c: export rb_str_scrub

nobu	2013-11-01 16:55:56 +0900 (Fri, 01 Nov 2013)

  New Revision: 43500

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43500

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/intern.h
    trunk/string.c
    trunk/transcode.c
Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 43499)
+++ include/ruby/intern.h	(revision 43500)
@@ -774,6 +774,7 @@ VALUE rb_str_length(VALUE); https://github.com/ruby/ruby/blob/trunk/include/ruby/intern.h#L774
 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__ (	\
 {						\
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43499)
+++ ChangeLog	(revision 43500)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Nov  1 16:55:52 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@g...>
 
 	* thread.c (rb_mutex_struct): reduce rb_mutex_t size by 8 bytes
Index: string.c
===================================================================
--- string.c	(revision 43499)
+++ string.c	(revision 43500)
@@ -7973,20 +7973,18 @@ str_compat_and_valid(VALUE str, rb_encod https://github.com/ruby/ruby/blob/trunk/string.c#L7973
  * @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 https://github.com/ruby/ruby/blob/trunk/string.c#L8223
  *     "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, VALU https://github.com/ruby/ruby/blob/trunk/string.c#L8248
 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) https://github.com/ruby/ruby/blob/trunk/string.c#L8743
     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);
Index: transcode.c
===================================================================
--- transcode.c	(revision 43499)
+++ transcode.c	(revision 43500)
@@ -2660,8 +2660,6 @@ str_transcode_enc_args(VALUE str, volati https://github.com/ruby/ruby/blob/trunk/transcode.c#L2660
     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, VA https://github.com/ruby/ruby/blob/trunk/transcode.c#L2695
                     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);
-		}
-		else {
-		    dest = rb_str_scrub(0, NULL, str);
+		    rep = rb_hash_aref(ecopts, sym_replace);
 		}
-		*self = dest;
+		*self = rb_str_scrub(str, rep);
 		return dencidx;
 	    }
             return NIL_P(arg2) ? -1 : dencidx;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]