diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-12-14 06:50:43 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-12-14 06:50:43 +0000 |
commit | 9d228b13deccfdf23f44e2c465f723a2a7b3bcbd (patch) | |
tree | 9a4d769804c389b6b03bbfdf65e8e0a03288c8e8 /regex.c | |
parent | c18d3740a925e8752c3b93acea6087fb0e03be53 (diff) | |
download | ruby-9d228b13deccfdf23f44e2c465f723a2a7b3bcbd.tar.gz |
19991214
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'regex.c')
-rw-r--r-- | regex.c | 61 |
1 files changed, 38 insertions, 23 deletions
@@ -2922,35 +2922,15 @@ re_compile_fastmap(bufp) FREE_AND_RETURN_VOID(stackb); } - -/* Using the compiled pattern in BUFP->buffer, first tries to match - STRING, starting first at index STARTPOS, then at STARTPOS + 1, and - so on. RANGE is the number of places to try before giving up. If - RANGE is negative, it searches backwards, i.e., the starting - positions tried are STARTPOS, STARTPOS - 1, etc. STRING is of SIZE. - In REGS, return the indices of STRING that matched the entire - BUFP->buffer and its contained subexpressions. - - The value returned is the position in the strings at which the match - was found, or -1 if no match was found, or -2 if error (such as - failure stack overflow). */ - +/* adjust startpos value to the position between characters. */ int -re_search(bufp, string, size, startpos, range, regs) +re_adjust_startpos(bufp, string, size, startpos, range) struct re_pattern_buffer *bufp; const char *string; int size, startpos, range; - struct re_registers *regs; { - register char *fastmap = bufp->fastmap; - int val, anchor = 0; - - /* Check for out-of-range starting position. */ - if (startpos < 0 || startpos > size) - return -1; - /* Update the fastmap now if not correct already. */ - if (fastmap && !bufp->fastmap_accurate) { + if (!bufp->fastmap_accurate) { re_compile_fastmap(bufp); } @@ -2980,6 +2960,41 @@ re_search(bufp, string, size, startpos, range, regs) } } } + return startpos; +} + + +/* Using the compiled pattern in BUFP->buffer, first tries to match + STRING, starting first at index STARTPOS, then at STARTPOS + 1, and + so on. RANGE is the number of places to try before giving up. If + RANGE is negative, it searches backwards, i.e., the starting + positions tried are STARTPOS, STARTPOS - 1, etc. STRING is of SIZE. + In REGS, return the indices of STRING that matched the entire + BUFP->buffer and its contained subexpressions. + + The value returned is the position in the strings at which the match + was found, or -1 if no match was found, or -2 if error (such as + failure stack overflow). */ + +int +re_search(bufp, string, size, startpos, range, regs) + struct re_pattern_buffer *bufp; + const char *string; + int size, startpos, range; + struct re_registers *regs; +{ + register char *fastmap = bufp->fastmap; + int val, anchor = 0; + + /* Check for out-of-range starting position. */ + if (startpos < 0 || startpos > size) + return -1; + + /* Update the fastmap now if not correct already. */ + if (fastmap && !bufp->fastmap_accurate) { + re_compile_fastmap(bufp); + } + /* If the search isn't to be a backwards one, don't waste time in a search for a pattern that must be anchored. */ |