summaryrefslogtreecommitdiffstats
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
commite627646ccac0c122b422b201af87597bf47f53a1 (patch)
treeb43e02b6dca6c0a18852fcf55bc7468da5b349da /regex.c
parent32bb6645bdc6dfcdb2b7e68705dc3a1696d186f4 (diff)
downloadruby-e627646ccac0c122b422b201af87597bf47f53a1.tar.gz
ruby-e627646ccac0c122b422b201af87597bf47f53a1.tar.xz
ruby-e627646ccac0c122b422b201af87597bf47f53a1.zip
* regex.c (re_adjust_startpos): fix for SJIS.
* regex.c (mbc_startpos): ditto. git-svn-id: http://svn.ruby-lang.org/repos/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 eb14a38a4..e3e84ae16 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;
}