[前][次][番号順一覧][スレッド一覧]

ruby-changes:9186

From: matz <ko1@a...>
Date: Sat, 13 Dec 2008 17:09:35 +0900 (JST)
Subject: [ruby-changes:9186] Ruby:r20723 (trunk): * string.c (sym_inspect): quote if symbol contains non-printable

matz	2008-12-13 17:09:23 +0900 (Sat, 13 Dec 2008)

  New Revision: 20723

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20723

  Log:
    * string.c (sym_inspect): quote if symbol contains non-printable
      characters.  [ruby-dev:37398]

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 20722)
+++ ChangeLog	(revision 20723)
@@ -14,6 +14,9 @@
 	* string.c (sym_equal): remove documentation error "Otherwise,
 	  compares them as strings".  [ruby-dev:37398]
 
+	* string.c (sym_inspect): quote if symbol contains non-printable
+	  characters.  [ruby-dev:37398]
+
 Sat Dec 13 14:24:38 2008  Yuki Sonoda (Yugui)  <yugui@y...>
 
 	* test/ruby/enc/test_utf16.rb: feature changed in r20626.
Index: string.c
===================================================================
--- string.c	(revision 20722)
+++ string.c	(revision 20723)
@@ -6826,6 +6826,19 @@
 }
 
 
+static int
+sym_printable(const char *s, rb_encoding *enc)
+{
+    const char *send = s + strlen(s);
+    while (s) {
+	int c = rb_enc_codepoint(s, send, enc);
+	int n = rb_enc_codelen(c, enc);
+	if (!rb_enc_isprint(c, enc)) return Qfalse;
+	s += n;
+    }
+    return Qtrue;
+}
+
 /*
  *  call-seq:
  *     sym.inspect    => string
@@ -6848,7 +6861,8 @@
     RSTRING_PTR(str)[0] = ':';
     memcpy(RSTRING_PTR(str)+1, RSTRING_PTR(sym), RSTRING_LEN(sym));
     if (RSTRING_LEN(sym) != strlen(RSTRING_PTR(sym)) ||
-	!rb_enc_symname_p(RSTRING_PTR(sym), enc)) {
+	!rb_enc_symname_p(RSTRING_PTR(sym), enc) ||
+	!sym_printable(RSTRING_PTR(sym), enc)) {
 	str = rb_str_inspect(str);
 	strncpy(RSTRING_PTR(str), ":\"", 2);
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]