1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* string.c (str_mod_check, str_nth, str_offset): consitfied.

* string.c (rb_str_dump): dump in ASCII-8BIT always.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-01-23 02:53:28 +00:00
parent 3b6f862b3a
commit 0c8106ded6
2 changed files with 19 additions and 14 deletions

View file

@ -1,3 +1,9 @@
Wed Jan 23 11:53:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (str_mod_check, str_nth, str_offset): consitfied.
* string.c (rb_str_dump): dump in ASCII-8BIT always.
Wed Jan 23 10:18:10 2008 Yukihiro Matsumoto <matz@ruby-lang.org> Wed Jan 23 10:18:10 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval_method.c (rb_export_method): set ruby_vm_redefined_flag for * eval_method.c (rb_export_method): set ruby_vm_redefined_flag for

View file

@ -228,7 +228,7 @@ int rb_enc_str_asciionly_p(VALUE str)
} }
static inline void static inline void
str_mod_check(VALUE s, char *p, long len) str_mod_check(VALUE s, const char *p, long len)
{ {
if (RSTRING_PTR(s) != p || RSTRING_LEN(s) != len){ if (RSTRING_PTR(s) != p || RSTRING_LEN(s) != len){
rb_raise(rb_eRuntimeError, "string modified"); rb_raise(rb_eRuntimeError, "string modified");
@ -839,19 +839,19 @@ rb_str_s_try_convert(VALUE dummy, VALUE str)
} }
static char* static char*
str_nth(char *p, char *e, int nth, rb_encoding *enc, int singlebyte) str_nth(const char *p, const char *e, int nth, rb_encoding *enc, int singlebyte)
{ {
if (singlebyte) if (singlebyte)
p += nth; p += nth;
else else
p = rb_enc_nth(p, e, nth, enc); p = rb_enc_nth(p, e, nth, enc);
if (!p) return 0; if (!p) return 0;
if (p > e) return e; if (p > e) p = e;
return p; return (char *)p;
} }
static int static int
str_offset(char *p, char *e, int nth, rb_encoding *enc, int singlebyte) str_offset(const char *p, const char *e, int nth, rb_encoding *enc, int singlebyte)
{ {
const char *pp = str_nth(p, e, nth, enc, singlebyte); const char *pp = str_nth(p, e, nth, enc, singlebyte);
if (!pp) return e - p; if (!pp) return e - p;
@ -3263,16 +3263,15 @@ VALUE
rb_str_dump(VALUE str) rb_str_dump(VALUE str)
{ {
rb_encoding *enc0 = rb_enc_get(str); rb_encoding *enc0 = rb_enc_get(str);
rb_encoding *enc = rb_enc_from_index(0);
long len; long len;
char *p, *pend; const char *p, *pend;
char *q, *qend; char *q, *qend;
VALUE result; VALUE result;
len = 2; /* "" */ len = 2; /* "" */
p = RSTRING_PTR(str); pend = p + RSTRING_LEN(str); p = RSTRING_PTR(str); pend = p + RSTRING_LEN(str);
while (p < pend) { while (p < pend) {
char c = *p++; unsigned char c = *p++;
switch (c) { switch (c) {
case '"': case '\\': case '"': case '\\':
case '\n': case '\r': case '\n': case '\r':
@ -3286,11 +3285,11 @@ rb_str_dump(VALUE str)
break; break;
default: default:
if (rb_enc_isprint(c, enc)) { if (ISPRINT(c)) {
len++; len++;
} }
else { else {
len += 4; /* \nnn */ len += 4; /* \xNN */
} }
break; break;
} }
@ -3306,7 +3305,7 @@ rb_str_dump(VALUE str)
*q++ = '"'; *q++ = '"';
while (p < pend) { while (p < pend) {
char c = *p++; unsigned char c = *p++;
if (c == '"' || c == '\\') { if (c == '"' || c == '\\') {
*q++ = '\\'; *q++ = '\\';
@ -3348,19 +3347,19 @@ rb_str_dump(VALUE str)
*q++ = '\\'; *q++ = '\\';
*q++ = 'e'; *q++ = 'e';
} }
else if (rb_enc_isprint(c, enc)) { else if (ISPRINT(c)) {
*q++ = c; *q++ = c;
} }
else { else {
*q++ = '\\'; *q++ = '\\';
sprintf(q, "x%02X", c&0xff); sprintf(q, "x%02X", c);
q += 3; q += 3;
} }
} }
*q++ = '"'; *q++ = '"';
if (!rb_enc_asciicompat(enc0)) { if (!rb_enc_asciicompat(enc0)) {
sprintf(q, ".force_encoding(\"%s\")", enc0->name); sprintf(q, ".force_encoding(\"%s\")", enc0->name);
enc0 = enc; enc0 = rb_enc_from_index(0);
} }
OBJ_INFECT(result, str); OBJ_INFECT(result, str);