Author: pmichaud
Date: Sun Nov 30 20:19:01 2008
New Revision: 33399
Modified:
trunk/languages/perl6/src/builtins/any-str.pir
Log:
[rakudo]: Add :g(lobal) flag to .subst($str, $repl)
Modified: trunk/languages/perl6/src/builtins/any-str.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/any-str.pir (original)
+++ trunk/languages/perl6/src/builtins/any-str.pir Sun Nov 30 20:19:01 2008
@@ -895,34 +895,34 @@
.sub 'subst' :method :multi(_, _, _)
.param string substring
.param string replacement
- .local int pos
- .local int pos_after
- .local pmc retv
-
- retv = new 'Perl6Str'
-
- $S0 = self
- pos = index $S0, substring
- if pos < 0 goto no_match
+ .param pmc options :slurpy :named
- pos_after = pos
- $I0 = length substring
- add pos_after, $I0
-
- $S1 = substr $S0, 0, pos
- $S2 = substr $S0, pos_after
- concat retv, $S1
- concat retv, replacement
- concat retv, $S2
+ .local pmc global_flag
+ global_flag = options['global']
+ unless null global_flag goto have_global
+ global_flag = options['g']
+ unless null global_flag goto have_global
+ global_flag = get_hll_global ['Bool'], 'False'
+ have_global:
- goto done
+ .local string result
+ result = self
+ result = clone result
- no_match:
- retv = self
+ .local int pos, substringlen, replacelen
+ pos = 0
+ substringlen = length substring
+ replacelen = length replacement
+ subst_loop:
+ pos = index result, substring, pos
+ if pos < 0 goto subst_done
+ substr result, pos, substringlen, replacement
+ pos += replacelen
+ if global_flag goto subst_loop
+ subst_done:
+ .return (result)
+.end
- done:
- .return(retv)
-.end
.sub 'subst' :method :multi(_, 'Sub', _)
.param pmc regex