mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
string.c: rb_enc_str_new_cstr
* string.c (rb_enc_str_new_cstr): new function to create a string from the C-string pointer with the specified encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ad6731b0f9
commit
5669902126
5 changed files with 30 additions and 0 deletions
13
string.c
13
string.c
|
@ -34,6 +34,7 @@
|
|||
#undef rb_str_new_cstr
|
||||
#undef rb_tainted_str_new_cstr
|
||||
#undef rb_usascii_str_new_cstr
|
||||
#undef rb_enc_str_new_cstr
|
||||
#undef rb_external_str_new_cstr
|
||||
#undef rb_locale_str_new_cstr
|
||||
#undef rb_str_dup_frozen
|
||||
|
@ -473,6 +474,18 @@ rb_usascii_str_new_cstr(const char *ptr)
|
|||
return str;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
|
||||
{
|
||||
if (!ptr) {
|
||||
rb_raise(rb_eArgError, "NULL pointer given");
|
||||
}
|
||||
if (rb_enc_mbminlen(enc) != 1) {
|
||||
rb_raise(rb_eArgError, "wchar encoding given");
|
||||
}
|
||||
return rb_enc_str_new(ptr, strlen(ptr), enc);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_tainted_str_new(const char *ptr, long len)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue