diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | include/ruby/intern.h | 1 | ||||
-rw-r--r-- | re.c | 5 | ||||
-rw-r--r-- | string.c | 20 |
4 files changed, 34 insertions, 1 deletions
@@ -1,3 +1,12 @@ +Fri Jan 25 16:31:47 2008 Tanaka Akira <akr@fsij.org> + + * 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. + Fri Jan 25 16:11:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> * ruby.c (process_options, load_file, rb_load_file): propagates script diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 1f531a71c5..e552c1f0e0 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -504,6 +504,7 @@ void rb_str_shared_replace(VALUE, VALUE); VALUE rb_str_buf_append(VALUE, VALUE); VALUE rb_str_buf_cat(VALUE, const char*, long); VALUE rb_str_buf_cat2(VALUE, const char*); +VALUE rb_str_buf_cat_ascii(VALUE, const char*); VALUE rb_obj_as_string(VALUE); VALUE rb_check_string_type(VALUE); VALUE rb_str_dup(VALUE); @@ -2668,7 +2668,7 @@ rb_reg_s_union(VALUE self, VALUE args0) VALUE e = rb_ary_entry(args0, i); if (0 < i) - rb_str_buf_cat2(source, "|"); /* xxx: UTF-16 */ + rb_str_buf_cat_ascii(source, "|"); v = rb_check_regexp_type(e); if (!NIL_P(v)) { @@ -2726,6 +2726,9 @@ rb_reg_s_union(VALUE self, VALUE args0) } } + if (i == 0) { + rb_enc_copy(source, v); + } rb_str_append(source, v); } @@ -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) |