Modified: MacRuby/trunk/string.c (3786 => 3787)
--- MacRuby/trunk/string.c 2010-03-17 18:35:16 UTC (rev 3786)
+++ MacRuby/trunk/string.c 2010-03-17 21:35:16 UTC (rev 3787)
@@ -3415,6 +3415,7 @@
long offset = 0, last = 0;
bool changed = false;
const long len = str_length(RSTR(str), false);
+ VALUE match = Qnil;
while (true) {
const long pos = rb_reg_search(pat, str, offset, false);
@@ -3429,7 +3430,7 @@
break;
}
- VALUE match = rb_backref_get();
+ match = rb_backref_get();
int count = 0;
rb_match_result_t *results = rb_reg_match_results(match, &count);
assert(count > 0);
@@ -3455,9 +3456,9 @@
val = rb_reg_regsub(repl, str, pat, results, count);
}
- if (pos - offset > 0) {
+ if (pos - last > 0) {
str_concat_string(RSTR(dest),
- RSTR(rstr_substr(str, offset, pos - offset)));
+ RSTR(rstr_substr(str, last, pos - last)));
}
str_concat_string(RSTR(dest), str_need_string(val));
@@ -3470,10 +3471,10 @@
if (results[0].beg == offset) {
offset++;
}
-
- rb_backref_set(match);
}
+ rb_backref_set(match);
+
if (bang) {
rstr_modify(str);
str_replace(RSTR(str), dest);