summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-03-26 09:07:28 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-03-26 09:07:28 +0000
commitcdde29b924f3f310382d059938b0c94e209fced7 (patch)
tree789b492f0f5c6dfa2132f3baea1fd8388840bc46
parent9eee63661b39bb2832af4878922ac57674a2a4a7 (diff)
String#dump
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--eval.c3
-rw-r--r--ext/curses/curses.c2
-rw-r--r--lib/delegate.rb2
-rw-r--r--string.c89
5 files changed, 100 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index eb3fdf1ae58..b7827bc5e17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Mar 26 11:51:09 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * string.c (str_dump): new method.
+
+ * eval.c (block_pass): block argument can be nil, which means no
+ block is supplied for the method.
+
Wed Mar 25 08:12:07 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* numeric.c (flo_modulo): caused SEGV if left operand is not a
diff --git a/eval.c b/eval.c
index 3a68e48a369..1fe013ffe74 100644
--- a/eval.c
+++ b/eval.c
@@ -4708,6 +4708,9 @@ block_pass(self, node)
volatile int orphan;
volatile int safe = safe_level;
+ if (NIL_P(block)) {
+ return rb_eval(self, node->nd_iter);
+ }
if (obj_is_kind_of(block, cMethod)) {
block = method_proc(block);
}
diff --git a/ext/curses/curses.c b/ext/curses/curses.c
index 89ed2966a02..7826450e8cc 100644
--- a/ext/curses/curses.c
+++ b/ext/curses/curses.c
@@ -2,7 +2,7 @@
* ext/curses/curses.c
*
* by MAEDA Shugo (ender@pic-internet.or.jp)
- * modified by Yukihiro Matsumoto (matz@ruby.club.or.jp)
+ * modified by Yukihiro Matsumoto (matz@netlab.co.jp)
*/
#ifdef HAVE_NCURSES_H
diff --git a/lib/delegate.rb b/lib/delegate.rb
index a9809d046d9..04c824401a6 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -20,7 +20,7 @@ class Delegator
end
for method in obj.methods
next if preserved.include? method
- eval "def self.#{method}(*args); __getobj__.__send__ :#{method}, *args; end"
+ eval "def self.#{method}(*args); __getobj__.__send__(:#{method}, *args){|x|yield}; end"
end
end
diff --git a/string.c b/string.c
index 3e31a1e2472..6a1165ce1ed 100644
--- a/string.c
+++ b/string.c
@@ -1423,7 +1423,7 @@ str_inspect(str)
*b++ = '\\';
*b++ = 'f';
}
- else if (c == '\13') {
+ else if (c == '\013') {
CHECK(2);
*b++ = '\\';
*b++ = 'v';
@@ -1449,6 +1449,92 @@ str_inspect(str)
return str_new(buf, b - buf);
}
+VALUE
+str_dump(str)
+ VALUE str;
+{
+ int len;
+ UCHAR *p, *pend;
+ UCHAR *q, *qend;
+ VALUE result;
+
+ len = 2; /* "" */
+ p = RSTRING(str)->ptr; pend = p + RSTRING(str)->len;
+ while (p < pend) {
+ UCHAR c = *p++;
+ switch (c) {
+ case '"': case '\'':
+ case '\n': case '\r':
+ case '\t': case '\f':
+ case '\013': case '\007': case '\033':
+ len += 2;
+ break;
+
+ default:
+ if (isascii(c) && isprint(c)) {
+ len++;
+ }
+ else {
+ len += 4; /* \nnn */
+ }
+ break;
+ }
+ }
+
+ result = str_new(0, len);
+ p = RSTRING(str)->ptr; pend = p + RSTRING(str)->len;
+ q = RSTRING(result)->ptr; qend = q + len;
+
+ *q++ = '"';
+ while (p < pend) {
+ UCHAR c = *p++;
+
+ if (c == '"' || c == '\\') {
+ *q++ = '\\';
+ *q++ = c;
+ }
+ else if (isascii(c) && isprint(c)) {
+ *q++ = c;
+ }
+ else if (c == '\n') {
+ *q++ = '\\';
+ *q++ = 'n';
+ }
+ else if (c == '\r') {
+ *q++ = '\\';
+ *q++ = 'r';
+ }
+ else if (c == '\t') {
+ *q++ = '\\';
+ *q++ = 't';
+ }
+ else if (c == '\f') {
+ *q++ = '\\';
+ *q++ = 'f';
+ }
+ else if (c == '\13') {
+ *q++ = '\\';
+ *q++ = 'v';
+ }
+ else if (c == '\007') {
+ *q++ = '\\';
+ *q++ = 'a';
+ }
+ else if (c == 033) {
+ *q++ = '\\';
+ *q++ = 'e';
+ }
+ else {
+ *q++ = '\\';
+ sprintf(q, "%03o", c);
+ q += 3;
+ }
+ }
+ *q++ = '"';
+
+ return result;
+}
+
static VALUE
str_upcase_bang(str)
VALUE str;
@@ -2544,6 +2630,7 @@ Init_String()
rb_define_method(cString, "to_f", str_to_f, 0);
rb_define_method(cString, "to_s", str_to_s, 0);
rb_define_method(cString, "inspect", str_inspect, 0);
+ rb_define_method(cString, "dump", str_dump, 0);
rb_define_method(cString, "upcase", str_upcase, 0);
rb_define_method(cString, "downcase", str_downcase, 0);