Revision
3821
Author
lsansonetti@apple.com
Date
2010-03-18 20:24:13 -0700 (Thu, 18 Mar 2010)

Log Message

fixed #inspect to escape slashes

Modified Paths

Diff

Modified: MacRuby/trunk/re.cpp (3820 => 3821)


--- MacRuby/trunk/re.cpp	2010-03-19 03:23:56 UTC (rev 3820)
+++ MacRuby/trunk/re.cpp	2010-03-19 03:24:13 UTC (rev 3821)
@@ -846,10 +846,22 @@
 static VALUE
 regexp_inspect(VALUE rcv, SEL sel)
 {
-    VALUE str = rb_str_new2("/");
-    rb_str_concat(str, regexp_source(rcv, 0));
-    rb_str_cat2(str, "/");
+    VALUE str = rb_unicode_str_new(NULL, 0);
+    rb_str_append_uchar(str, '/');
 
+    assert(RREGEXP(rcv)->unistr != NULL);
+    const UChar *chars = RREGEXP(rcv)->unistr->getBuffer();
+    const int32_t chars_len = RREGEXP(rcv)->unistr->length();
+    for (int i = 0; i < chars_len; i++) {
+	UChar c = chars[i];
+	if (c == '/') {
+	    rb_str_append_uchar(str, '\\');
+	}
+	rb_str_append_uchar(str, c);
+    }
+
+    rb_str_append_uchar(str, '/');
+
     const uint32_t options = rb_reg_options(rcv);
     const bool mode_m = options & REGEXP_OPT_MULTILINE;
     const bool mode_i = options & REGEXP_OPT_IGNORECASE;