[macruby-changes] [2988] MacRuby/trunk/string.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 9 20:44:17 PST 2009
Revision: 2988
http://trac.macosforge.org/projects/ruby/changeset/2988
Author: lsansonetti at apple.com
Date: 2009-11-09 20:44:17 -0800 (Mon, 09 Nov 2009)
Log Message:
-----------
fixed String#dump to escape eval strings
Modified Paths:
--------------
MacRuby/trunk/string.c
Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c 2009-11-10 02:30:31 UTC (rev 2987)
+++ MacRuby/trunk/string.c 2009-11-10 04:44:17 UTC (rev 2988)
@@ -2568,8 +2568,8 @@
__append(out, c);
}
-VALUE
-rb_str_inspect(VALUE str, SEL sel)
+static VALUE
+__rb_str_inspect(VALUE str, bool dump)
{
const long len = CFStringGetLength((CFStringRef)str);
CFStringInlineBuffer buf;
@@ -2578,13 +2578,21 @@
CFMutableStringRef out = CFStringCreateMutable(NULL, 0);
__append(out, '"');
- long i;
- for (i = 0; i < len; i++) {
+ for (long i = 0; i < len; i++) {
UniChar c = CFStringGetCharacterFromInlineBuffer(&buf, i);
if (iswprint(c)) {
if (c == '"'|| c == '\\') {
__append_escape(out, c);
}
+ else if (dump && c == '#' && i + 1 < len) {
+ UniChar c2 = CFStringGetCharacterFromInlineBuffer(&buf, i + 1);
+ if (c2 == '$' || c2 == '@' || c2 == '{') {
+ __append_escape(out, c);
+ }
+ else {
+ __append(out, c);
+ }
+ }
else {
__append(out, c);
}
@@ -2626,7 +2634,11 @@
return res;
}
-#define IS_EVSTR(p,e) ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))
+VALUE
+rb_str_inspect(VALUE str, SEL sel)
+{
+ return __rb_str_inspect(str, false);
+}
/*
* call-seq:
@@ -2639,9 +2651,7 @@
static VALUE
rb_str_dump(VALUE str, SEL sel)
{
- // XXX #dump and #inspect have some slight differences, let's fix that
- // later.
- VALUE res = rb_str_inspect(str, 0);
+ VALUE res = __rb_str_inspect(str, true);
*(VALUE *)res = *(VALUE *)str;
return res;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091109/b84ec30f/attachment.html>
More information about the macruby-changes
mailing list