* string.c (rb_setup_fake_str): setup fake string from C pointer,
  length, and encoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-08-16 03:36:47 +00:00
Родитель a669514e63
Коммит 3636e08858
3 изменённых файлов: 15 добавлений и 19 удалений

Просмотреть файл

@ -893,6 +893,9 @@ size_t rb_strftime(char *s, size_t maxsize, const char *format, rb_encoding *enc
/* string.c */
VALUE rb_fstring(VALUE);
VALUE rb_fstring_new(const char *ptr, long len);
#ifdef RUBY_ENCODING_H
VALUE rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb_encoding *enc);
#endif
int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p);
int rb_str_symname_p(VALUE);
VALUE rb_str_quote_unprintable(VALUE);

Просмотреть файл

@ -247,6 +247,12 @@ setup_fake_str(struct RString *fake_str, const char *name, long len, int encidx)
return (VALUE)fake_str;
}
VALUE
rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb_encoding *enc)
{
return setup_fake_str(fake_str, name, len, rb_enc_to_index(enc));
}
VALUE
rb_fstring_new(const char *ptr, long len)
{

Просмотреть файл

@ -410,17 +410,6 @@ must_be_dynamic_symbol(VALUE x)
}
}
static VALUE
setup_fake_str(struct RString *fake_str, const char *name, long len)
{
fake_str->basic.flags = T_STRING|RSTRING_NOEMBED;
RBASIC_SET_CLASS_RAW((VALUE)fake_str, rb_cString);
fake_str->as.heap.len = len;
fake_str->as.heap.ptr = (char *)name;
fake_str->as.heap.aux.capa = len;
return (VALUE)fake_str;
}
static VALUE
dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding * const enc)
{
@ -527,8 +516,7 @@ rb_intern_cstr_without_pindown(const char *name, long len, rb_encoding *enc)
{
st_data_t id;
struct RString fake_str;
VALUE str = setup_fake_str(&fake_str, name, len);
rb_enc_associate(str, enc);
VALUE str = rb_setup_fake_str(&fake_str, name, len, enc);
OBJ_FREEZE(str);
if (st_lookup(global_symbols.str_id, str, &id)) {
@ -1045,8 +1033,7 @@ rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
{
ID id;
struct RString fake_str;
const VALUE name = setup_fake_str(&fake_str, ptr, len);
rb_enc_associate(name, enc);
const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
sym_check_asciionly(name);
@ -1069,8 +1056,7 @@ rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
{
VALUE sym;
struct RString fake_str;
const VALUE name = setup_fake_str(&fake_str, ptr, len);
rb_enc_associate(name, enc);
const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
sym_check_asciionly(name);
@ -1095,8 +1081,9 @@ attrsetname_to_attr(VALUE name)
ID id;
struct RString fake_str;
/* make local name by chopping '=' */
const VALUE localname = setup_fake_str(&fake_str, RSTRING_PTR(name), RSTRING_LEN(name) - 1);
rb_enc_copy(localname, name);
const VALUE localname = rb_setup_fake_str(&fake_str,
RSTRING_PTR(name), RSTRING_LEN(name) - 1,
rb_enc_get(name));
OBJ_FREEZE(localname);
if ((id = lookup_str_id(localname)) != 0) {