String#sub!{...}


#1

e$B@>;3OB9-$G$9!#e(B

http://zunda.freeshell.org/d/20070126.html#p04
e$B$H$=$N%j%s%/@h$Ne(B
http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/palm-ja-proxy/blazer-ja-proxy/bin/blazer-ja-proxy?rev=1.42.2.10&only_with_tag=RUBY_DEBUG_070126&view=auto
e$B$r$$F:G>.$O$I$N$/$i$$$K$J$j$=$&$+;n$7$F$$^$7$?!#e(B

% irb-1.8.5
ruby 1.8.5 (2006-08-25) [i686-linux]

(s=‘a’).sub!(//){//=~s;‘b’};s.scan(/./m)
=> [“b”, “”]

(s=‘a’).sub!(//){//=~s;‘ABC’};s.scan(/./m)
=> [“A”, “”]

(s=‘foo’).sub!(//){//=~s;‘bar’};s.scan(/./m)
=> [“b”, “a”, “r”, “”]

(s=‘foo’).sub!(//){//=~s;‘hoge’};s.scan(/./m)
=> [“h”, “o”, “g”, “”]

(s=‘foo’).sub!(//){//=~s;‘hogefuga’};s.scan(/./m)
=> [“h”, “o”, “g”, “”]

(s=‘foobar’).sub!(//){//=~s;‘hogefuga’};s.scan(/./m)
=> ["\000", “\000”, “\000”, “\000”, “a”, “r”, “”]

e$B$J$I$H?’!9;n$7$F$$$F!"e(Bsub!e$B$NCf$G$N%^%C%Ae(B(//=~s)e$B8e$Ke(B
e$BJ8;zNs$,D9$/$J$C$F$$$k$H$*$+$7$/$J$C$F$$$k$h$&$Ke(B
e$B8+$($^$9!#e(B

e$B$H$$$&$o$1$G!":G>.$O$3$N$/$i$$$K$J$j$=$&$G$9!#e(B

(s=’’).sub!(//){//=~s;‘a’};s.scan(/./m)
=> [""]


#2

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:30211] String#sub!{…}”
on Jan.30,2007 00:59:52, removed_email_address@domain.invalid wrote:
| e$B$J$I$H?’!9;n$7$F$$$F!“e(Bsub!e$B$NCf$G$N%^%C%Ae(B(//=~s)e$B8e$Ke(B
| e$BJ8;zNs$,D9$/$J$C$F$$$k$H$*$+$7$/$J$C$F$$$k$h$&$Ke(B
| e$B8+$($^$9!#e(B
|
| e$B$H$$$&$o$1$G!”:G>.$O$3$N$/$i$$$K$J$j$=$&$G$9!#e(B
|
| >> (s=’’).sub!(//){//=~s;‘a’};s.scan(/./m)
| => [""]

s.scan(/./) e$B$G$$$1$^$9$M!#e(B

e$B$H$$$&$N$O$I$&$G$b$h$/$F!"$3$s$J46$8$G$7$g$&$+e(B?

Index: string.c

— string.c (revision 11577)
+++ string.c (working copy)
@@ -1966,7 +1966,6 @@

 pat = get_pat(argv[0], 1);
 if (rb_reg_search(pat, str, 0, 0) >= 0) {
  • rb_str_modify(str);
    match = rb_backref_get();
    regs = RMATCH(match)->regs;

@@ -1982,6 +1981,7 @@
else {
repl = rb_reg_regsub(repl, str, regs);
}

  • rb_str_modify(str);
    if (OBJ_TAINTED(repl)) tainted = 1;
    plen = END(0) - BEG(0);
    if (RSTRING(repl)->len > plen) {

e$B$=$l$G$O!#e(B


#3

zundae$B$G$9e(B

String#sub!{}e$B$NIT6q9g!"$b$&$A$g$C$H@0M}$7$F$+$i$3$A$i$Ke(B
e$B$4Js9p$r!D$H;W$C$F$$$?$iD>$7$F$$$?$@$$$A$c$$$^$7$?!#e(B

e$B<j85$G$O!"$J$+$`$ie(B(e$B$&e(B)e$B$5$s$N%Q%C%A$rEv$F$?e(BRubye$B$G!"e(B
e$BA4A3:G>.$K$J$C$F$$$J$$e(B
http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/palm-ja-proxy/blazer-ja-proxy/bin/blazer-ja-proxy?rev=1.42.2.10&only_with_tag=RUBY_DEBUG_070126&view=auto
e$B$G$b4|BTDL$j$N7k2L$K$J$k$3$H$,3NG’$G$-$^$7$?!#e(B

e$B@>;3$5$s!"$J$+$`$ie(B(e$B$&e(B)e$B$5$s!"$"$j$,$H$&$4$6$$$^$7$?!#e(B

— “U.Nakamura” removed_email_address@domain.invalid wrote:

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

e$B!"$3$s$J46$8$G$7$g$&$+e(B?


#4

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:30217] Re: String#sub!{…}”
on Jan.30,2007 14:39:45, removed_email_address@domain.invalid wrote:
| |— string.c (revision 11577)
| |+++ string.c (working copy)
|
| e$B%3%_%C%H$7$F$/$@$5$$$^$;$s$+!)e(B

1.9e$B$K$OLdBj$O$J$$!"$H;W$C$F$$$?$N$G$9$,!"$J$+$@$5$s$K$h$k$He(B1.9
e$B$G$b$A$g$C$H>r7o$rJQ$($k$H:F8=$9$k$h$&$G$9!#e(B
e$BD>$7J}$Oe(B1.8e$B$H0l=o!#e(B

e$B$H$$$&$o$1$G!“e(Btrunke$B$He(Bmatzrubye$B$K$bF~$l$?J}$,$$$$$G$7$g$&$+e(B?
e$B$”$H!"e(B1.8.5e$B$O$I$&$7$^$7$g$&$+e(B?e$B!dKNIt$5$se(B

e$B$=$l$G$O!#e(B


#5

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30212] Re: String#sub!{…}”
on Tue, 30 Jan 2007 01:35:52 +0900, “U.Nakamura”
removed_email_address@domain.invalid writes:

|e$B$H$$$&$N$O$I$&$G$b$h$/$F!"$3$s$J46$8$G$7$g$&$+e(B?

|— string.c (revision 11577)
|+++ string.c (working copy)

e$B%3%_%C%H$7$F$/$@$5$$$^$;$s$+!)e(B


#6

e$BKNIt$G$9!#e(B

U.Nakamura wrote:

e$B$H$$$&$o$1$G!“e(Btrunke$B$He(Bmatzrubye$B$K$bF~$l$?J}$,$$$$$G$7$g$&$+e(B?
e$B$”$H!"e(B1.8.5e$B$O$I$&$7$^$7$g$&$+e(B?e$B!dKNIt$5$se(B

e$B$($C$H!"e(B[ruby-dev:30214]e$B$NBP:v$HF1;~$K$d$k$N$O$J$s$+:.Mp$9$k$H;W$o$l$k$Ne(B
e$B$G!"8~$3$&$,=*$o$C$F$+$i$K$7$^$;$s$+e(B?

e$B4pK\E*$K$Oe(B1.8.5e$B$K$bF~$l$kJ}8~$G9M$($F$^$9!#e(B


#7

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30218] Re: String#sub!{…}”
on Tue, 30 Jan 2007 16:48:31 +0900, “U.Nakamura”
removed_email_address@domain.invalid writes:

|e$B$H$$$&$o$1$G!"e(Btrunke$B$He(Bmatzrubye$B$K$bF~$l$?J}$,$$$$$G$7$g$&$+e(B?

trunke$B$K$O$*4j$$$7$^$9!#e(Bmatzrubye$B$O%U%’!<%I%"%&%H$9$k=IL?$G$9e(B
e$B$+$i%3%_%C%HITMW$G$9!#e(B


#8

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:30223] Re: String#sub!{…}”
on Jan.30,2007 19:31:12, removed_email_address@domain.invalid wrote:
| > e$B$"$H!"e(B1.8.5e$B$O$I$&$7$^$7$g$&$+e(B?e$B!dKNIt$5$se(B
| >
| e$B$($C$H!"e(B[ruby-dev:30214]e$B$NBP:v$HF1;~$K$d$k$N$O$J$s$+:.Mp$9$k$H;W$o$l$k$Ne(B
| e$B$G!"8~$3$&$,=$o$C$F$+$i$K$7$^$;$s$+e(B?
|
| e$B4pK\E
$K$Oe(B1.8.5e$B$K$bF~$l$kJ}8~$G9M$($F$^$9!#e(B

e$BN;2r$G$9!#e(B
e$BMn$ACe$$$?$H$3$m$G$d$j$^$7$g$&!#e(B

e$B$=$l$G$O!#e(B