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@587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1999-12-14 06:50:43 +00:00
parent c18d3740a9
commit 9d228b13de
34 changed files with 649 additions and 508 deletions

67
regex.c
View file

@ -2922,6 +2922,47 @@ re_compile_fastmap(bufp)
FREE_AND_RETURN_VOID(stackb);
}
/* adjust startpos value to the position between characters. */
int
re_adjust_startpos(bufp, string, size, startpos, range)
struct re_pattern_buffer *bufp;
const char *string;
int size, startpos, range;
{
/* Update the fastmap now if not correct already. */
if (!bufp->fastmap_accurate) {
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;
}
}
}
return startpos;
}
/* Using the compiled pattern in BUFP->buffer, first tries to match
STRING, starting first at index STARTPOS, then at STARTPOS + 1, and
@ -2954,32 +2995,6 @@ 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. */