mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05: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
|
@ -1,3 +1,8 @@
|
|||
Tue Sep 3 22:03:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* string.c (rb_enc_str_new_cstr): new function to create a string from
|
||||
the C-string pointer with the specified encoding.
|
||||
|
||||
Tue Sep 3 21:41:37 2013 Akira Matsuda <ronnie@dio.jp>
|
||||
|
||||
* eval.c (Init_eval): Make Module#include and Module#prepend public
|
||||
|
|
|
@ -218,6 +218,7 @@ rb_str_vcatf(VALUE str, const char* format, va_list ap) ::
|
|||
rb_str_cat2(str, rb_vsprintf(format, ap)), respectively.
|
||||
|
||||
rb_enc_str_new(const char *ptr, long len, rb_encoding *enc) ::
|
||||
rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc) ::
|
||||
|
||||
Creates a new Ruby string with the specified encoding.
|
||||
|
||||
|
|
|
@ -245,6 +245,7 @@ rb_str_vcatf(VALUE str, const char* format, va_list ap)
|
|||
rb_str_cat2(str, rb_vsprintf(format, ap)) と同等である.
|
||||
|
||||
rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
|
||||
rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
|
||||
|
||||
指定されたエンコーディングでRubyの文字列を生成する.
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ VALUE rb_enc_associate(VALUE, rb_encoding*);
|
|||
void rb_enc_copy(VALUE dst, VALUE src);
|
||||
|
||||
VALUE rb_enc_str_new(const char*, long, rb_encoding*);
|
||||
VALUE rb_enc_str_new_cstr(const char*, rb_encoding*);
|
||||
VALUE rb_enc_reg_new(const char*, long, rb_encoding*, int);
|
||||
PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char*, ...), 2, 3);
|
||||
VALUE rb_enc_vsprintf(rb_encoding *, const char*, va_list);
|
||||
|
@ -103,6 +104,15 @@ VALUE rb_str_export_to_enc(VALUE, rb_encoding *);
|
|||
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to);
|
||||
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts);
|
||||
|
||||
#if defined(__GNUC__) && !defined(__PCC__)
|
||||
#define rb_enc_str_new_cstr(str, enc) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(str)) ? \
|
||||
rb_enc_str_new((str), (long)strlen(str), (enc)) : \
|
||||
rb_enc_str_new_cstr((str), (enc)); \
|
||||
})
|
||||
#endif
|
||||
|
||||
PRINTF_ARGS(NORETURN(void rb_enc_raise(rb_encoding *, VALUE, const char*, ...)), 3, 4);
|
||||
|
||||
/* index -> rb_encoding */
|
||||
|
|
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…
Reference in a new issue