From 2c2e6ee432bcbdb2e28005021ea2eb42c871c440 Mon Sep 17 00:00:00 2001 From: akr Date: Fri, 25 Jan 2008 07:35:27 +0000 Subject: * include/ruby/intern.h (rb_str_buf_cat_ascii): declared. * string.c (rb_str_buf_cat_ascii): defined. * re.c (rb_reg_s_union): use rb_str_buf_cat_ascii to support ASCII incompatible encoding. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'string.c') diff --git a/string.c b/string.c index 3ac56b56c..4b2706653 100644 --- a/string.c +++ b/string.c @@ -1116,6 +1116,26 @@ 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) -- cgit