summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-25 08:52:32 (GMT)
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-25 08:52:32 (GMT)
commit6be6666fba64ccad17b789ed54eade1443b53d23 (patch)
tree9bf347a8df5e99cad9ca0454c17f1af879ff4271 /re.c
parent6c00e17706eeee9f7a99c6129e1e0afcd586cac5 (diff)
* re.c (rb_reg_to_s): convert closing parenthes to the target encoding
if it is ASCII incompatible encoding. [ruby-core:56063] [Bug #8650] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/re.c b/re.c
index e5cc79d..dd40918 100644
--- a/re.c
+++ b/re.c
@@ -597,8 +597,30 @@ rb_reg_to_s(VALUE re)
}
rb_str_buf_cat2(str, ":");
- rb_reg_expr_str(str, (char*)ptr, len, enc, NULL);
- rb_str_buf_cat2(str, ")");
+ if (rb_enc_asciicompat(enc)) {
+ rb_reg_expr_str(str, (char*)ptr, len, enc, NULL);
+ rb_str_buf_cat2(str, ")");
+ }
+ else {
+ const char *s, *e;
+ char *paren;
+ ptrdiff_t n;
+ rb_str_buf_cat2(str, ")");
+ rb_enc_associate(str, rb_usascii_encoding());
+ str = rb_str_encode(str, rb_enc_from_encoding(enc), 0, Qnil);
+
+ /* backup encoded ")" to paren */
+ s = RSTRING_PTR(str);
+ e = RSTRING_END(str);
+ s = rb_enc_left_char_head(s, e-1, e, enc);
+ n = e - s;
+ paren = ALLOCA_N(char, n);
+ memcpy(paren, s, n);
+ rb_str_resize(str, RSTRING_LEN(str) - n);
+
+ rb_reg_expr_str(str, (char*)ptr, len, enc, NULL);
+ rb_str_buf_cat(str, paren, n);
+ }
rb_enc_copy(str, re);
OBJ_INFECT(str, re);