diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-30 02:56:29 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-30 02:56:29 +0000 |
commit | 8458e709ab4fd1c095b6281fe74f44e4dd4090d5 (patch) | |
tree | b01fb5f3a1f6ec905318cb293e14f82b15db29d8 /string.c | |
parent | c3c215e28a1995b138b84c1000c68850b2395578 (diff) |
string.c: rb_str_initialize
* string.c (rb_str_initialize): new function to (re)initialize a
string with data and encoding. extracted from
rb_external_str_new_with_enc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -932,6 +932,15 @@ rb_str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len, ecflags, ecopts); } +VALUE +rb_str_initialize(VALUE str, const char *ptr, long len, rb_encoding *enc) +{ + STR_SET_LEN(str, 0); + rb_enc_associate(str, enc); + rb_str_cat(str, ptr, len); + return str; +} + static VALUE str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len, rb_encoding *from, rb_encoding *to, @@ -1024,9 +1033,7 @@ rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *eenc) /* when the conversion failed for some reason, just ignore the * default_internal and result in the given encoding as-is. */ if (NIL_P(rb_str_cat_conv_enc_opts(str, 0, ptr, len, eenc, 0, Qnil))) { - STR_SET_LEN(str, 0); - rb_enc_associate(str, eenc); - rb_str_cat(str, ptr, len); + rb_str_initialize(str, ptr, len, eenc); } return str; } |