1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1999-12-06 09:04:03 +00:00
parent 4263bb432a
commit dee96209bf
23 changed files with 177 additions and 82 deletions

37
regex.c
View file

@ -396,6 +396,7 @@ re_set_syntax(syntax)
long syntax;
{
/* obsolete */
return 0;
}
@ -2272,9 +2273,9 @@ re_compile_pattern(pattern, size, bufp)
}
if (!(bufp->options & RE_OPTIMIZE_NO_BM)) {
bufp->must_skip = (int *) xmalloc((1 << BYTEWIDTH)*sizeof(int));
bm_init_skip(bufp->must_skip, bufp->must+1,
bm_init_skip(bufp->must_skip, (unsigned char*)bufp->must+1,
(unsigned char)bufp->must[0],
MAY_TRANSLATE()?translate:0);
(unsigned char*)(MAY_TRANSLATE()?translate:0));
}
}
@ -2626,6 +2627,7 @@ re_compile_fastmap(bufp)
fastmap[translate[p[2]]] = 2;
else
fastmap[p[2]] = 2;
bufp->options |= RE_OPTIMIZE_BMATCH;
}
else if (TRANSLATE_P())
fastmap[translate[p[1]]] = 1;
@ -2828,8 +2830,10 @@ re_compile_fastmap(bufp)
while (beg <= end) {
/* NOTE: Charset for multi-byte chars might contain
single-byte chars. We must reject them. */
if (c < 0x100)
if (c < 0x100) {
fastmap[beg] = 2;
bufp->options |= RE_OPTIMIZE_BMATCH;
}
else if (ismbchar(beg))
fastmap[beg] = 1;
beg++;
@ -2950,6 +2954,33 @@ re_search(bufp, string, size, startpos, range, regs)
re_compile_fastmap(bufp);
}
/* Adjust startpos for mbc string */
if (current_mbctype && startpos>0 && !(bufp->options&RE_OPTIMIZE_BMATCH)) {
int i = 0;
if (range > 0) {
while (i<size) {
i += mbclen(string[i]);
if (startpos <= i) {
startpos = i;
break;
}
}
}
else {
int w;
while (i<size) {
w = mbclen(string[i]);
if (startpos < i + w) {
startpos = i;
break;
}
i += w;
}
}
}
/* If the search isn't to be a backwards one, don't waste time in a
search for a pattern that must be anchored. */
if (bufp->used>0) {