Revision
3650
Author
lsansonetti@apple.com
Date
2010-02-27 02:10:46 -0800 (Sat, 27 Feb 2010)

Log Message

#split: never push nil strings

Modified Paths

Diff

Modified: MacRuby/branches/icu/string.c (3649 => 3650)


--- MacRuby/branches/icu/string.c	2010-02-27 10:10:08 UTC (rev 3649)
+++ MacRuby/branches/icu/string.c	2010-02-27 10:10:46 UTC (rev 3650)
@@ -2441,7 +2441,9 @@
 
 	    if (beg == pos && results[0].beg == results[0].end) {
 		if (last_null) {
-		    rb_ary_push(result, rstr_substr(str, beg, 1));
+		    if (beg + 1 <= len) {
+			rb_ary_push(result, rstr_substr(str, beg, 1));
+		    }
 		    beg = start;
 		}
 		else {
@@ -2457,7 +2459,10 @@
 	    last_null = false;
 
 	    for (int i = 1; i < count; i++) {
-		rb_ary_push(result, rb_reg_nth_match(i, match));
+		VALUE match_str = rb_reg_nth_match(i, match);
+		if (match_str != Qnil) {
+		    rb_ary_push(result, rb_reg_nth_match(i, match));
+		}
 	    }
 	}
 	while (limit == Qnil || --lim > 1);