summaryrefslogtreecommitdiffstats
path: root/re.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-06 09:25:09 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-06 09:25:09 +0000
commit00efba139bf1b991879f3d37dab5bb5e66595a33 (patch)
tree9bc30b9b9b1e796388684dbeef0dd2076c1052f3 /re.c
parent7907d9d0b2c53e8799ddd2dfd7cae17dab927885 (diff)
downloadruby-00efba139bf1b991879f3d37dab5bb5e66595a33.tar.gz
ruby-00efba139bf1b991879f3d37dab5bb5e66595a33.tar.xz
ruby-00efba139bf1b991879f3d37dab5bb5e66595a33.zip
* include/ruby/encoding.h (rb_enc_str_buf_cat): declared.
* string.c (coderange_scan): extracted from rb_enc_str_coderange. (rb_enc_str_coderange): use coderange_scan. (rb_str_shared_replace): copy encoding and coderange. (rb_enc_str_buf_cat): new function for linear complexity string accumulation with encoding. (rb_str_sub_bang): don't conflict substituted part and replacement. (str_gsub): use rb_enc_str_buf_cat. (rb_str_clear): clear coderange. * re.c (rb_reg_regsub): use rb_enc_str_buf_cat. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/re.c b/re.c
index 50fa341d1..8fd80628b 100644
--- a/re.c
+++ b/re.c
@@ -2795,17 +2795,18 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
VALUE val = 0;
char *p, *s, *e;
int no, clen;
- rb_encoding *enc = rb_enc_check(str, src);
+ rb_encoding *str_enc = rb_enc_get(str);
+ rb_encoding *src_enc = rb_enc_get(src);
p = s = RSTRING_PTR(str);
e = s + RSTRING_LEN(str);
while (s < e) {
- int c = rb_enc_ascget(s, e, &clen, enc);
+ int c = rb_enc_ascget(s, e, &clen, str_enc);
char *ss;
if (c == -1) {
- s += mbclen(s, e, enc);
+ s += mbclen(s, e, str_enc);
continue;
}
ss = s;
@@ -2816,12 +2817,12 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
if (!val) {
val = rb_str_buf_new(ss-p);
}
- rb_str_buf_cat(val, p, ss-p);
+ rb_enc_str_buf_cat(val, p, ss-p, str_enc);
- c = rb_enc_ascget(s, e, &clen, enc);
+ c = rb_enc_ascget(s, e, &clen, str_enc);
if (c == -1) {
- s += mbclen(s, e, enc);
- rb_str_buf_cat(val, ss, s-ss);
+ s += mbclen(s, e, str_enc);
+ rb_enc_str_buf_cat(val, ss, s-ss, str_enc);
continue;
}
s += clen;
@@ -2839,14 +2840,14 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
break;
case 'k':
- if (s < e && rb_enc_ascget(s, e, &clen, enc) == '<') {
+ if (s < e && rb_enc_ascget(s, e, &clen, str_enc) == '<') {
char *name, *name_end;
name_end = name = s + clen;
while (name_end < e) {
- c = rb_enc_ascget(name_end, e, &clen, enc);
+ c = rb_enc_ascget(name_end, e, &clen, str_enc);
if (c == '>') break;
- name_end += c == -1 ? mbclen(name_end, e, enc) : clen;
+ name_end += c == -1 ? mbclen(name_end, e, str_enc) : clen;
}
if (name_end < e) {
no = name_to_backref_number(regs, regexp, name, name_end);
@@ -2858,7 +2859,7 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
}
}
- rb_str_buf_cat(val, ss, s-ss);
+ rb_enc_str_buf_cat(val, ss, s-ss, str_enc);
continue;
case '0':
@@ -2867,11 +2868,11 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
break;
case '`':
- rb_str_buf_cat(val, RSTRING_PTR(src), BEG(0));
+ rb_enc_str_buf_cat(val, RSTRING_PTR(src), BEG(0), src_enc);
continue;
case '\'':
- rb_str_buf_cat(val, RSTRING_PTR(src)+END(0), RSTRING_LEN(src)-END(0));
+ rb_enc_str_buf_cat(val, RSTRING_PTR(src)+END(0), RSTRING_LEN(src)-END(0), src_enc);
continue;
case '+':
@@ -2881,26 +2882,25 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
break;
case '\\':
- rb_str_buf_cat(val, s-clen, clen);
+ rb_enc_str_buf_cat(val, s-clen, clen, str_enc);
continue;
default:
- rb_str_buf_cat(val, ss, s-ss);
+ rb_enc_str_buf_cat(val, ss, s-ss, str_enc);
continue;
}
if (no >= 0) {
if (no >= regs->num_regs) continue;
if (BEG(no) == -1) continue;
- rb_str_buf_cat(val, RSTRING_PTR(src)+BEG(no), END(no)-BEG(no));
+ rb_enc_str_buf_cat(val, RSTRING_PTR(src)+BEG(no), END(no)-BEG(no), src_enc);
}
}
if (!val) return str;
if (p < e) {
- rb_str_buf_cat(val, p, e-p);
+ rb_enc_str_buf_cat(val, p, e-p, str_enc);
}
- rb_enc_associate(val, enc);
return val;
}