summaryrefslogtreecommitdiff
path: root/regex.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-30 07:00:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-30 07:00:58 +0000
commitae2d54d91dc805ea7c8e4af82e8a434d722eab33 (patch)
treeb43e02b6dca6c0a18852fcf55bc7468da5b349da /regex.c
parent7ddde51c68b572b2a94a4946d2bf9b7d0e12a65a (diff)
* regex.c (re_adjust_startpos): fix for SJIS.
* regex.c (mbc_startpos): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2032 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/regex.c b/regex.c
index eb14a38..e3e84ae 100644
--- a/regex.c
+++ b/regex.c
@@ -3080,11 +3080,17 @@ re_adjust_startpos(bufp, string, size, startpos, range)
if (current_mbctype && startpos>0 && !(bufp->options&RE_OPTIMIZE_BMATCH)) {
int i = mbc_startpos(string, startpos);
- if (i < startpos && range > 0) {
- startpos = i + mbclen(string[i]);
- }
- else {
- startpos = i;
+ if (i < startpos) {
+ if (range > 0) {
+ startpos = i + mbclen(string[i]);
+ }
+ else {
+ int len = mbclen(string[i]);
+ if (i + len <= startpos)
+ startpos = i + len;
+ else
+ startpos = i;
+ }
}
}
return startpos;
@@ -4570,10 +4576,16 @@ mbc_startpos(string, pos)
switch (current_mbctype) {
case MBCTYPE_EUC:
- case MBCTYPE_SJIS:
- /* double byte char only */
return i + ((pos - i) & ~1);
+
+ case MBCTYPE_SJIS:
+ while (i + (w = mbclen(string[i])) < pos) {
+ i += w;
+ }
+ return i;
+
case MBCTYPE_UTF8:
+ return i;
default:
return pos;
}