From 5669902126ec202d2cb482e6d15c0c28bc6025cd Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 3 Sep 2013 13:03:54 +0000 Subject: 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 --- include/ruby/encoding.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/ruby') diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index ebd9cfd262..e0dc66dec7 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -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 */ -- cgit v1.2.3