mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
string.c: remove magic number
* string.c (rb_str_dump): share same string literal instead of a magic number. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6442f02176
commit
1bea5a6127
1 changed files with 3 additions and 2 deletions
5
string.c
5
string.c
|
@ -5483,6 +5483,7 @@ rb_str_dump(VALUE str)
|
||||||
char *q, *qend;
|
char *q, *qend;
|
||||||
VALUE result;
|
VALUE result;
|
||||||
int u8 = (encidx == rb_utf8_encindex());
|
int u8 = (encidx == rb_utf8_encindex());
|
||||||
|
static const char nonascii_suffix[] = ".force_encoding(\"%s\")";
|
||||||
|
|
||||||
len = 2; /* "" */
|
len = 2; /* "" */
|
||||||
p = RSTRING_PTR(str); pend = p + RSTRING_LEN(str);
|
p = RSTRING_PTR(str); pend = p + RSTRING_LEN(str);
|
||||||
|
@ -5521,7 +5522,7 @@ rb_str_dump(VALUE str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!rb_enc_asciicompat(enc)) {
|
if (!rb_enc_asciicompat(enc)) {
|
||||||
len += 19; /* ".force_encoding('')" */
|
len += strlen(nonascii_suffix) - rb_strlen_lit("%s");
|
||||||
len += strlen(enc->name);
|
len += strlen(enc->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5595,7 +5596,7 @@ rb_str_dump(VALUE str)
|
||||||
*q++ = '"';
|
*q++ = '"';
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
if (!rb_enc_asciicompat(enc)) {
|
if (!rb_enc_asciicompat(enc)) {
|
||||||
snprintf(q, qend-q, ".force_encoding(\"%s\")", enc->name);
|
snprintf(q, qend-q, nonascii_suffix, enc->name);
|
||||||
encidx = rb_ascii8bit_encindex();
|
encidx = rb_ascii8bit_encindex();
|
||||||
}
|
}
|
||||||
OBJ_INFECT_RAW(result, str);
|
OBJ_INFECT_RAW(result, str);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue