зеркало из https://github.com/github/ruby.git
* string.c (rb_str_buf_cat_escaped_char): defined.
Splited from rb_str_inspect. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
7f51312344
Коммит
291809f473
|
@ -1,3 +1,8 @@
|
|||
Sat Jun 5 01:10:12 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_buf_cat_escaped_char): defined.
|
||||
Splited from rb_str_inspect.
|
||||
|
||||
Sat Jun 5 16:39:13 2010 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* .gdbinit (rp): show type name for RTypedData.
|
||||
|
|
53
string.c
53
string.c
|
@ -4078,6 +4078,36 @@ str_cat_char(VALUE str, unsigned int c, rb_encoding *enc)
|
|||
}
|
||||
#endif
|
||||
|
||||
#define CHAR_ESC_LEN 13 /* sizeof(\x{ hex of 32bit unsigned int } \0) */
|
||||
|
||||
int
|
||||
rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p) {
|
||||
char buf[CHAR_ESC_LEN + 1];
|
||||
int l;
|
||||
if (unicode_p) {
|
||||
if (c < 0x7F && ISPRINT(c)) {
|
||||
snprintf(buf, CHAR_ESC_LEN, "%c", c);
|
||||
}
|
||||
else if (c < 0x10000) {
|
||||
snprintf(buf, CHAR_ESC_LEN, "\\u%04X", c);
|
||||
}
|
||||
else {
|
||||
snprintf(buf, CHAR_ESC_LEN, "\\u{%X}", c);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (c < 0x100) {
|
||||
snprintf(buf, CHAR_ESC_LEN, "\\x%02X", c);
|
||||
}
|
||||
else {
|
||||
snprintf(buf, CHAR_ESC_LEN, "\\x{%X}", c);
|
||||
}
|
||||
}
|
||||
l = strlen(buf);
|
||||
rb_str_buf_cat(result, buf, l);
|
||||
return l;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* str.inspect -> string
|
||||
|
@ -4095,7 +4125,6 @@ rb_str_inspect(VALUE str)
|
|||
{
|
||||
rb_encoding *enc = STR_ENC_GET(str);
|
||||
const char *p, *pend, *prev;
|
||||
#define CHAR_ESC_LEN 13 /* sizeof(\x{ hex of 32bit unsigned int } \0) */
|
||||
char buf[CHAR_ESC_LEN + 1];
|
||||
VALUE result = rb_str_buf_new(0);
|
||||
rb_encoding *resenc = rb_default_internal_encoding();
|
||||
|
@ -4165,27 +4194,7 @@ rb_str_inspect(VALUE str)
|
|||
}
|
||||
else {
|
||||
if (p - n > prev) str_buf_cat(result, prev, p - n - prev);
|
||||
if (unicode_p) {
|
||||
if (c < 0x100 && ISPRINT(c)) {
|
||||
snprintf(buf, CHAR_ESC_LEN, "%c", c);
|
||||
}
|
||||
else if (c < 0x10000) {
|
||||
snprintf(buf, CHAR_ESC_LEN, "\\u%04X", c);
|
||||
}
|
||||
else {
|
||||
snprintf(buf, CHAR_ESC_LEN, "\\u{%X}", c);
|
||||
}
|
||||
str_buf_cat(result, buf, strlen(buf));
|
||||
}
|
||||
else {
|
||||
if (c < 0x100) {
|
||||
snprintf(buf, CHAR_ESC_LEN, "\\x%02X", c);
|
||||
}
|
||||
else {
|
||||
snprintf(buf, CHAR_ESC_LEN, "\\x{%X}", c);
|
||||
}
|
||||
str_buf_cat(result, buf, strlen(buf));
|
||||
}
|
||||
rb_str_buf_cat_escaped_char(result, c, unicode_p);
|
||||
prev = p;
|
||||
continue;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче