diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-20 08:28:51 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-20 08:28:51 +0000 |
commit | 861095398453d08ed3b104c1f3bad4d970552fab (patch) | |
tree | d3c9cc8b01c7cdbdd51c7b122bc3ef6eddb76f34 /string.c | |
parent | 869a0bb90a901b11a8683d251f1b36e5a82729cd (diff) |
1.1b8pre2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@85 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 37 |
1 files changed, 19 insertions, 18 deletions
@@ -898,14 +898,15 @@ str_sub_s(str, pat, val, once) repl = reg_regsub(val, str, regs); str_cat(result, RSTRING(repl)->ptr, RSTRING(repl)->len); if (BEG(0) == END(0)) { + int len = ismbchar(RSTRING(str)->ptr[END(0)])?2:1; /* * Always consume at least one character of the input string * in order to prevent infinite loops. */ if (RSTRING(str)->len > END(0)) { - str_cat(result, RSTRING(str)->ptr+END(0), 1); + str_cat(result, RSTRING(str)->ptr+END(0), len); } - offset = END(0)+1; + offset = END(0)+len; } else { offset = END(0); @@ -970,27 +971,30 @@ str_sub_iter_s(str, pat, once) result = str_new(0,0); n = 0; offset = 0; while ((beg=reg_search(pat, str, offset, 0)) >= 0) { - n++; - null = 0; + n++; + regs = RMATCH(backref_get())->regs; str_cat(result, RSTRING(str)->ptr+offset, beg-offset); - regs = RMATCH(backref_get())->regs; - if (END(0) == offset) { - null = 1; - offset = END(0)+1; + val = obj_as_string(rb_yield(reg_nth_match(0, backref_get()))); + str_cat(result, RSTRING(val)->ptr, RSTRING(val)->len); + + if (BEG(0) == END(0)) { + int len = ismbchar(RSTRING(str)->ptr[END(0)])?2:1; + + /* + * Always consume at least one character of the input string + * in order to prevent infinite loops. + */ + if (RSTRING(str)->len > END(0)) { + str_cat(result, RSTRING(str)->ptr+END(0), len); + } + offset = END(0)+len; } else { offset = END(0); } - val = rb_yield(reg_nth_match(0, backref_get())); - val = obj_as_string(val); - str_cat(result, RSTRING(val)->ptr, RSTRING(val)->len); - if (null && RSTRING(str)->len) { - str_cat(result, RSTRING(str)->ptr+offset-1, 1); - } - if (once) break; if (offset >= STRLEN(str)) break; } @@ -2506,7 +2510,4 @@ Init_String() rb_define_global_function("split", f_split, -1); pr_str = rb_intern("to_s"); - - /* Fix-up initialize ordering */ - RCLASS(eGlobalExit)->super = cString; } |