diff --git a/NEWS b/NEWS index acf414caa2..f1f7e66758 100644 --- a/NEWS +++ b/NEWS @@ -105,3 +105,5 @@ with all sufficient information, see the ChangeLog file. * struct RSymbol added. This represents a dynamic symbol as object in Ruby's heaps. + +* rb_str_cat_cstr() added. This is same as `rb_str_cat2()`. diff --git a/README.EXT b/README.EXT index b36273723d..6ba0e6fec6 100644 --- a/README.EXT +++ b/README.EXT @@ -208,6 +208,7 @@ rb_str_cat(VALUE str, const char *ptr, long len) :: Appends len bytes of data from ptr to the Ruby string. rb_str_cat2(VALUE str, const char* ptr) :: +rb_str_cat_cstr(VALUE str, const char* ptr) :: Appends C string ptr to Ruby string str. This function is equivalent to rb_str_cat(str, ptr, strlen(ptr)). diff --git a/README.EXT.ja b/README.EXT.ja index d18b81b58e..5a0073e977 100644 --- a/README.EXT.ja +++ b/README.EXT.ja @@ -234,6 +234,7 @@ rb_str_cat(VALUE str, const char *ptr, long len) Rubyの文字列strにlenバイトの文字列ptrを追加する. rb_str_cat2(VALUE str, const char* ptr) +rb_str_cat_cstr(VALUE str, const char* ptr) Rubyの文字列strにCの文字列ptrを追加する.この関数の機能は rb_str_cat(str, ptr, strlen(ptr))と同等である. diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 26b880e022..c69d378f62 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -727,6 +727,7 @@ VALUE rb_str_freeze(VALUE); void rb_str_set_len(VALUE, long); VALUE rb_str_resize(VALUE, long); VALUE rb_str_cat(VALUE, const char*, long); +VALUE rb_str_cat_cstr(VALUE, const char*); VALUE rb_str_cat2(VALUE, const char*); VALUE rb_str_append(VALUE, VALUE); VALUE rb_str_concat(VALUE, VALUE); @@ -798,17 +799,11 @@ VALUE rb_str_scrub(VALUE, VALUE); (str), (long)strlen(str)) : \ rb_str_buf_new_cstr(str); \ }) -#define rb_str_buf_cat2(str, ptr) __extension__ ( \ -{ \ - (__builtin_constant_p(ptr)) ? \ - rb_str_buf_cat((str), (ptr), (long)strlen(ptr)) : \ - rb_str_buf_cat2((str), (ptr)); \ -}) -#define rb_str_cat2(str, ptr) __extension__ ( \ +#define rb_str_cat_cstr(str, ptr) __extension__ ( \ { \ (__builtin_constant_p(ptr)) ? \ rb_str_cat((str), (ptr), (long)strlen(ptr)) : \ - rb_str_cat2((str), (ptr)); \ + rb_str_cat_cstr((str), (ptr)); \ }) #define rb_exc_new_cstr(klass, ptr) __extension__ ( \ { \ @@ -824,6 +819,9 @@ VALUE rb_str_scrub(VALUE, VALUE); #define rb_tainted_str_new2 rb_tainted_str_new_cstr #define rb_str_buf_new2 rb_str_buf_new_cstr #define rb_usascii_str_new2 rb_usascii_str_new_cstr +#define rb_str_buf_cat rb_str_cat +#define rb_str_buf_cat2 rb_str_cat_cstr +#define rb_str_cat2 rb_str_cat_cstr /* struct.c */ VALUE rb_struct_new(VALUE, ...); VALUE rb_struct_define(const char*, ...); diff --git a/string.c b/string.c index 3ad5eedbd1..3845430cec 100644 --- a/string.c +++ b/string.c @@ -38,8 +38,10 @@ #undef rb_locale_str_new_cstr #undef rb_str_dup_frozen #undef rb_str_buf_new_cstr +#undef rb_str_buf_cat #undef rb_str_buf_cat2 #undef rb_str_cat2 +#undef rb_str_cat_cstr static VALUE rb_str_clear(VALUE str); @@ -2048,7 +2050,7 @@ str_buf_cat(VALUE str, const char *ptr, long len) #define str_buf_cat2(str, ptr) str_buf_cat((str), (ptr), strlen(ptr)) VALUE -rb_str_buf_cat(VALUE str, const char *ptr, long len) +rb_str_cat(VALUE str, const char *ptr, long len) { if (len == 0) return str; if (len < 0) { @@ -2058,13 +2060,14 @@ rb_str_buf_cat(VALUE str, const char *ptr, long len) } VALUE -rb_str_buf_cat2(VALUE str, const char *ptr) +rb_str_cat_cstr(VALUE str, const char *ptr) { return rb_str_buf_cat(str, ptr, strlen(ptr)); } -RUBY_ALIAS_FUNCTION(rb_str_cat(VALUE str, const char *ptr, long len), rb_str_buf_cat, (str, ptr, len)) -RUBY_ALIAS_FUNCTION(rb_str_cat2(VALUE str, const char *ptr), rb_str_buf_cat2, (str, ptr)) +RUBY_ALIAS_FUNCTION(rb_str_buf_cat(VALUE str, const char *ptr, long len), rb_str_cat, (str, ptr, len)) +RUBY_ALIAS_FUNCTION(rb_str_buf_cat2(VALUE str, const char *ptr), rb_str_cat_cstr, (str, ptr)) +RUBY_ALIAS_FUNCTION(rb_str_cat2(VALUE str, const char *ptr), rb_str_cat_cstr, (str, ptr)) static VALUE rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len,