diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | internal.h | 9 | ||||
-rw-r--r-- | string.c | 7 |
3 files changed, 20 insertions, 1 deletions
@@ -1,4 +1,7 @@ -Wed Jun 24 12:47:14 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> +Wed Jun 24 12:49:11 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * string.c (rb_fstring_cstr): new function to make a fstring from + a string literal. * internal.h (rb_fstring_lit): new macro to make a fstring from a string literal. diff --git a/internal.h b/internal.h index 7b085cee31..32ad346e07 100644 --- a/internal.h +++ b/internal.h @@ -1091,6 +1091,15 @@ VALUE rb_fstring(VALUE); VALUE rb_fstring_new(const char *ptr, long len); #define rb_fstring_lit(str) rb_fstring_new((str), rb_strlen_lit(str)) #define rb_fstring_literal(str) rb_fstring_lit(str) +VALUE rb_fstring_cstr(const char *str); +#if defined(__GNUC__) && !defined(__PCC__) +#define rb_fstring_cstr(str) __extension__ ( \ +{ \ + (__builtin_constant_p(str)) ? \ + rb_fstring_new((str), (long)strlen(str)) : \ + rb_fstring_cstr(str); \ +}) +#endif int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p); int rb_str_symname_p(VALUE); VALUE rb_str_quote_unprintable(VALUE); @@ -46,6 +46,7 @@ #undef rb_str_buf_cat2 #undef rb_str_cat2 #undef rb_str_cat_cstr +#undef rb_fstring_cstr static VALUE rb_str_clear(VALUE str); @@ -303,6 +304,12 @@ rb_fstring_new(const char *ptr, long len) return rb_fstring(setup_fake_str(&fake_str, ptr, len, ENCINDEX_US_ASCII)); } +VALUE +rb_fstring_cstr(const char *ptr) +{ + return rb_fstring_new(ptr, strlen(ptr)); +} + static int fstring_set_class_i(st_data_t key, st_data_t val, st_data_t arg) { |