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

string.c: UTF-8 string function

* string.c (rb_utf8_str_new, rb_utf8_str_new_cstr): make UTF-8
  string.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-09-18 14:51:08 +00:00
parent c825eee9ea
commit 1495c2f8e9
2 changed files with 25 additions and 0 deletions

View file

@ -707,6 +707,8 @@ VALUE rb_str_buf_new2(const char*);
VALUE rb_str_tmp_new(long);
VALUE rb_usascii_str_new(const char*, long);
VALUE rb_usascii_str_new_cstr(const char*);
VALUE rb_utf8_str_new(const char*, long);
VALUE rb_utf8_str_new_cstr(const char*);
void rb_str_free(VALUE);
void rb_str_shared_replace(VALUE, VALUE);
VALUE rb_str_buf_append(VALUE, VALUE);
@ -787,6 +789,12 @@ VALUE rb_str_scrub(VALUE, VALUE);
rb_usascii_str_new((str), (long)strlen(str)) : \
rb_usascii_str_new_cstr(str); \
})
#define rb_utf8_str_new_cstr(str) __extension__ ( \
{ \
(__builtin_constant_p(str)) ? \
rb_utf8_str_new((str), (long)strlen(str)) : \
rb_utf8_str_new_cstr(str); \
})
#define rb_external_str_new_cstr(str) __extension__ ( \
{ \
(__builtin_constant_p(str)) ? \

View file

@ -34,6 +34,7 @@
#undef rb_str_new_cstr
#undef rb_tainted_str_new_cstr
#undef rb_usascii_str_new_cstr
#undef rb_utf8_str_new_cstr
#undef rb_enc_str_new_cstr
#undef rb_external_str_new_cstr
#undef rb_locale_str_new_cstr
@ -588,6 +589,14 @@ rb_usascii_str_new(const char *ptr, long len)
return str;
}
VALUE
rb_utf8_str_new(const char *ptr, long len)
{
VALUE str = str_new(rb_cString, ptr, len);
rb_enc_associate_index(str, rb_utf8_encindex());
return str;
}
VALUE
rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
{
@ -615,6 +624,14 @@ rb_usascii_str_new_cstr(const char *ptr)
return str;
}
VALUE
rb_utf8_str_new_cstr(const char *ptr)
{
VALUE str = rb_str_new_cstr(ptr);
rb_enc_associate_index(str, rb_utf8_encindex());
return str;
}
VALUE
rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
{