[macruby-changes] [1159] MacRuby/branches/experimental/string.c

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 25 22:09:25 PDT 2009


Revision: 1159
          http://trac.macosforge.org/projects/ruby/changeset/1159
Author:   lsansonetti at apple.com
Date:     2009-03-25 22:09:25 -0700 (Wed, 25 Mar 2009)
Log Message:
-----------
fix bugs discovered by rubyspec

Modified Paths:
--------------
    MacRuby/branches/experimental/string.c

Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c	2009-03-26 03:21:33 UTC (rev 1158)
+++ MacRuby/branches/experimental/string.c	2009-03-26 05:09:25 UTC (rev 1159)
@@ -4923,28 +4923,38 @@
  *     :fred.inspect   #=> ":fred"
  */
 
+static inline bool
+sym_printable(const char *str, long len)
+{
+    // TODO multibyte symbols
+    long i;
+    for (i = 0; i < len; i++) {
+	if (!isprint(str[i])) {
+	    return false;
+	}
+    }
+    return true;
+}
+
 static VALUE
 sym_inspect(VALUE sym, SEL sel)
 {
-    if (RSTRING_LEN(sym) == 0) {
+    const char *symstr = RSYMBOL(sym)->str;
+
+    long len = strlen(symstr);
+    if (len == 0) {
 	return rb_str_new2(":\"\"");
     }
 
-    CFCharacterSetRef letters =
-	CFCharacterSetGetPredefined(kCFCharacterSetLetter);
-    const bool should_be_quoted = 
-	!CFCharacterSetIsCharacterMember(letters,
-		CFStringGetCharacterAtIndex((CFStringRef)sym, 0));
-
     VALUE str = rb_str_new2(":");
-
-    if (should_be_quoted) {
+    if (!rb_symname_p(symstr) || !sym_printable(symstr, len)) {
 	rb_str_buf_cat2(str, "\"");
-    }
-    rb_str_buf_append(str, sym);
-    if (should_be_quoted) {
+	rb_str_buf_append(str, sym);
 	rb_str_buf_cat2(str, "\"");
     }
+    else {
+	rb_str_buf_append(str, sym);
+    }
 
     return str;
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090325/00247758/attachment.html>


More information about the macruby-changes mailing list