[macruby-changes] [971] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 17 17:21:18 PDT 2009
Revision: 971
http://trac.macosforge.org/projects/ruby/changeset/971
Author: lsansonetti at apple.com
Date: 2009-03-17 17:21:18 -0700 (Tue, 17 Mar 2009)
Log Message:
-----------
make sure Symbol#inspect returns a quoted symbol when necessary
Modified Paths:
--------------
MacRuby/branches/experimental/string.c
MacRuby/branches/experimental/test_roxor.rb
Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c 2009-03-18 00:14:36 UTC (rev 970)
+++ MacRuby/branches/experimental/string.c 2009-03-18 00:21:18 UTC (rev 971)
@@ -4925,15 +4925,24 @@
static VALUE
sym_inspect(VALUE sym, SEL sel)
{
- VALUE str;
+ assert(RSTRING_LEN(sym) > 0);
-#if 0
- if (!rb_enc_symname_p(RSTRING_PTR(sym), NULL)) {
- sym = rb_str_inspect(sym);
+ CFCharacterSetRef letters =
+ CFCharacterSetGetPredefined(kCFCharacterSetLetter);
+ const bool should_be_quoted =
+ !CFCharacterSetIsCharacterMember(letters,
+ CFStringGetCharacterAtIndex((CFStringRef)sym, 0));
+
+ VALUE str = rb_str_new2(":");
+
+ if (should_be_quoted) {
+ rb_str_buf_cat2(str, "\"");
}
-#endif
- str = rb_str_new2(":");
rb_str_buf_append(str, sym);
+ if (should_be_quoted) {
+ rb_str_buf_cat2(str, "\"");
+ }
+
return str;
}
Modified: MacRuby/branches/experimental/test_roxor.rb
===================================================================
--- MacRuby/branches/experimental/test_roxor.rb 2009-03-18 00:14:36 UTC (rev 970)
+++ MacRuby/branches/experimental/test_roxor.rb 2009-03-18 00:21:18 UTC (rev 971)
@@ -244,9 +244,10 @@
assert '"foo246bar"', "p \"foo#{1+1}#{2+2}#{3+3}bar\""
assert ":ok", 'p :ok'
- assert ":\"foo\"", 'p :"foo"'
+ assert ":ok", 'p :"ok"'
assert ":ok", 'p :"#{:ok}"'
assert ":\"42\"", 'p :"#{40+2}"'
+ assert ":foo42", 'p :"foo#{40+2}"'
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090317/bb009a5a/attachment-0001.html>
More information about the macruby-changes
mailing list