ruby-changes:3743
From: ko1@a...
Date: Fri, 25 Jan 2008 16:35:45 +0900 (JST)
Subject: [ruby-changes:3743] akr - Ruby:r15232 (trunk): * include/ruby/intern.h (rb_str_buf_cat_ascii): declared.
akr 2008-01-25 16:35:27 +0900 (Fri, 25 Jan 2008) New Revision: 15232 Modified files: trunk/ChangeLog trunk/include/ruby/intern.h trunk/re.c trunk/string.c Log: * 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. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=15232&r2=15231&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15232&r2=15231&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=15232&r2=15231&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/intern.h?r1=15232&r2=15231&diff_format=u Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 15231) +++ include/ruby/intern.h (revision 15232) @@ -504,6 +504,7 @@ 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); Index: re.c =================================================================== --- re.c (revision 15231) +++ re.c (revision 15232) @@ -2668,7 +2668,7 @@ 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 @@ } } + if (i == 0) { + rb_enc_copy(source, v); + } rb_str_append(source, v); } Index: ChangeLog =================================================================== --- ChangeLog (revision 15231) +++ ChangeLog (revision 15232) @@ -1,3 +1,12 @@ +Fri Jan 25 16:31:47 2008 Tanaka Akira <akr@f...> + + * 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@r...> * ruby.c (process_options, load_file, rb_load_file): propagates script Index: string.c =================================================================== --- string.c (revision 15231) +++ string.c (revision 15232) @@ -1116,6 +1116,26 @@ 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/