diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-25 12:50:12 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-25 12:50:12 +0000 |
commit | 3a783ba707eadf0ddad102e348e43968d434486c (patch) | |
tree | 801d979c9ab825f11496e113029ae3c35535ce1c | |
parent | dc059544721929209e1e02f018c88ee1d95588b5 (diff) | |
download | ruby-3a783ba707eadf0ddad102e348e43968d434486c.tar.gz |
* string.c (rb_str_buf_cat_ascii): use rb_enc_cr_str_buf_cat.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | string.c | 44 |
2 files changed, 28 insertions, 20 deletions
@@ -1,3 +1,7 @@ +Fri Jan 25 21:49:36 2008 Tanaka Akira <akr@fsij.org> + + * string.c (rb_str_buf_cat_ascii): use rb_enc_cr_str_buf_cat. + Fri Jan 25 19:38:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> * common.mk (version.$(OBJEXT)): depends on $(srcdir)/revision.h. @@ -1116,26 +1116,6 @@ rb_str_cat2(VALUE str, const char *ptr) return rb_str_cat(str, ptr, strlen(ptr)); } -VALUE -rb_str_buf_cat_ascii(VALUE str, const char *ptr) -{ - rb_encoding *enc = rb_enc_get(str); - if (rb_enc_asciicompat(enc)) { - return rb_str_buf_cat(str, ptr, strlen(ptr)); - } - else { - char *buf = ALLOCA_N(char, rb_enc_mbmaxlen(enc)); - while (*ptr) { - int c = (unsigned char)*ptr; - int len = rb_enc_codelen(c, enc); - rb_enc_mbcput(c, buf, enc); - rb_str_buf_cat(str, buf, len); - ptr++; - } - return str; - } -} - static VALUE rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len, int ptr_encindex, int ptr_cr, int *ptr_cr_ret) @@ -1257,6 +1237,30 @@ rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *ptr_enc) } VALUE +rb_str_buf_cat_ascii(VALUE str, const char *ptr) +{ + /* ptr must reference NUL terminated ASCII string. */ + int encindex = ENCODING_GET(str); + rb_encoding *enc = rb_enc_from_index(encindex); + if (rb_enc_asciicompat(enc)) { + return rb_enc_cr_str_buf_cat(str, ptr, strlen(ptr), + encindex, ENC_CODERANGE_7BIT, 0); + } + else { + char *buf = ALLOCA_N(char, rb_enc_mbmaxlen(enc)); + while (*ptr) { + int c = (unsigned char)*ptr; + int len = rb_enc_codelen(c, enc); + rb_enc_mbcput(c, buf, enc); + rb_enc_cr_str_buf_cat(str, buf, len, + encindex, ENC_CODERANGE_VALID, 0); + ptr++; + } + return str; + } +} + +VALUE rb_str_buf_append(VALUE str, VALUE str2) { int str2_cr; |