[macruby-changes] [3715] MacRuby/branches/icu/string.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Mar 8 18:02:53 PST 2010
Revision: 3715
http://trac.macosforge.org/projects/ruby/changeset/3715
Author: lsansonetti at apple.com
Date: 2010-03-08 18:02:51 -0800 (Mon, 08 Mar 2010)
Log Message:
-----------
fixed a bug in #gsub, implemented negation in #tr
Modified Paths:
--------------
MacRuby/branches/icu/string.c
Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c 2010-03-09 01:07:18 UTC (rev 3714)
+++ MacRuby/branches/icu/string.c 2010-03-09 02:02:51 UTC (rev 3715)
@@ -3381,7 +3381,7 @@
VALUE pat = get_pat(argv[0], 1);
VALUE dest = rb_str_new5(str, NULL, 0);
- long offset = 0;
+ long offset = 0, last = 0;
bool changed = false;
const long len = str_length(RSTR(str), false);
@@ -3391,9 +3391,9 @@
if (!changed) {
return bang ? Qnil : rstr_dup(str, 0);
}
- if (offset < len) {
+ if (last < len) {
str_concat_string(RSTR(dest),
- RSTR(rstr_substr(str, offset, len - offset)));
+ RSTR(rstr_substr(str, last, len - last)));
}
break;
}
@@ -3433,7 +3433,7 @@
}
changed = true;
- offset = results[0].end;
+ offset = last = results[0].end;
if (results[0].beg == offset) {
offset++;
}
@@ -4624,19 +4624,41 @@
NULL, repl);
assert(repl_buflen > 0);
- // Fill the table with 0s.
- for (int i = 0; i < 0xff; i++) {
- tbl[i] = 0;
+ // Fill the table based on the values from the linear buffers.
+ if (negate) {
+ for (int i = 0; i < 0xff; i++) {
+ tbl[i] = 1;
+ }
+
+ long pos = 0;
+ while (pos < source_buflen) {
+ const char source_c = source_buf[pos];
+ tbl[(int)source_c] = 0;
+ pos++;
+ }
+
+ for (int i = 0, pos = 0; i < 0xff; i++) {
+ if (tbl[i] == 1) {
+ const char repl_c = pos >= repl_buflen
+ ? repl_buf[repl_buflen - 1] : repl_buf[pos];
+ tbl[i] = repl_c;
+ pos++;
+ }
+ }
}
+ else {
+ for (int i = 0; i < 0xff; i++) {
+ tbl[i] = 0;
+ }
- // Now fill the table based on the linear buffer values.
- long pos = 0;
- while (pos < source_buflen) {
- const char source_c = source_buf[pos];
- const char repl_c = pos >= repl_buflen
- ? repl_buf[repl_buflen - 1] : repl_buf[pos];
- tbl[(int)source_c] = repl_c;
- pos++;
+ long pos = 0;
+ while (pos < source_buflen) {
+ const char source_c = source_buf[pos];
+ const char repl_c = pos >= repl_buflen
+ ? repl_buf[repl_buflen - 1] : repl_buf[pos];
+ tbl[(int)source_c] = repl_c;
+ pos++;
+ }
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100308/720e864a/attachment.html>
More information about the macruby-changes
mailing list