mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
String#dump
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9eee63661b
commit
cdde29b924
5 changed files with 100 additions and 3 deletions
|
@ -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>
|
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
|
* numeric.c (flo_modulo): caused SEGV if left operand is not a
|
||||||
|
|
3
eval.c
3
eval.c
|
@ -4708,6 +4708,9 @@ block_pass(self, node)
|
||||||
volatile int orphan;
|
volatile int orphan;
|
||||||
volatile int safe = safe_level;
|
volatile int safe = safe_level;
|
||||||
|
|
||||||
|
if (NIL_P(block)) {
|
||||||
|
return rb_eval(self, node->nd_iter);
|
||||||
|
}
|
||||||
if (obj_is_kind_of(block, cMethod)) {
|
if (obj_is_kind_of(block, cMethod)) {
|
||||||
block = method_proc(block);
|
block = method_proc(block);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* ext/curses/curses.c
|
* ext/curses/curses.c
|
||||||
*
|
*
|
||||||
* by MAEDA Shugo (ender@pic-internet.or.jp)
|
* 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
|
#ifdef HAVE_NCURSES_H
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Delegator
|
||||||
end
|
end
|
||||||
for method in obj.methods
|
for method in obj.methods
|
||||||
next if preserved.include? method
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
89
string.c
89
string.c
|
@ -1423,7 +1423,7 @@ str_inspect(str)
|
||||||
*b++ = '\\';
|
*b++ = '\\';
|
||||||
*b++ = 'f';
|
*b++ = 'f';
|
||||||
}
|
}
|
||||||
else if (c == '\13') {
|
else if (c == '\013') {
|
||||||
CHECK(2);
|
CHECK(2);
|
||||||
*b++ = '\\';
|
*b++ = '\\';
|
||||||
*b++ = 'v';
|
*b++ = 'v';
|
||||||
|
@ -1449,6 +1449,92 @@ str_inspect(str)
|
||||||
return str_new(buf, b - buf);
|
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
|
static VALUE
|
||||||
str_upcase_bang(str)
|
str_upcase_bang(str)
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
@ -2544,6 +2630,7 @@ Init_String()
|
||||||
rb_define_method(cString, "to_f", str_to_f, 0);
|
rb_define_method(cString, "to_f", str_to_f, 0);
|
||||||
rb_define_method(cString, "to_s", str_to_s, 0);
|
rb_define_method(cString, "to_s", str_to_s, 0);
|
||||||
rb_define_method(cString, "inspect", str_inspect, 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, "upcase", str_upcase, 0);
|
||||||
rb_define_method(cString, "downcase", str_downcase, 0);
|
rb_define_method(cString, "downcase", str_downcase, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue