diff options
author | nyamatongwe <devnull@localhost> | 2001-04-06 12:24:21 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2001-04-06 12:24:21 +0000 |
commit | 031fdca93e03464d541a3255a92a7b5603b14a50 (patch) | |
tree | d12c6a496b4c11b3d8f3f3a30689ef9ee1fbf7a0 /src/Document.cxx | |
parent | 529ea750b146c23bd1f8c0ec0b3bbeb64689a736 (diff) | |
download | scintilla-mirror-031fdca93e03464d541a3255a92a7b5603b14a50.tar.gz |
Made regular expression searching work on a line by line basis, made ^ and
$ work, made [set] work, and added a case insensitive option.
Diffstat (limited to 'src/Document.cxx')
-rw-r--r-- | src/Document.cxx | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index 8adf2daf2..4a915314d 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -791,15 +791,12 @@ long Document::FindText(int minPos, int maxPos, const char *s, bool caseSensitive, bool word, bool wordStart, bool regExp, int *length) { if (regExp) { + if (!pre) pre = new RESearch(); if (!pre) return -1; - char *pat = new char[strlen(s) + 1]; - if (!pat) - return -1; - pat[0] = '\0'; int startPos; int endPos; @@ -815,25 +812,42 @@ long Document::FindText(int minPos, int maxPos, const char *s, startPos = MovePositionOutsideChar(startPos, 1, false); endPos = MovePositionOutsideChar(endPos, 1, false); - DocumentIndexer di(this, endPos); - strcat(pat, s); - const char *errmsg = pre->Compile(pat); + const char *errmsg = pre->Compile(s, caseSensitive); if (errmsg) { - delete []pat; return -1; } // Find a variable in a property file: \$(\([A-Za-z0-9_.]+\)) // Replace first '.' with '-' in each property file variable reference: // Search: \$(\([A-Za-z0-9_-]+\)\.\([A-Za-z0-9_.]+\)) // Replace: $(\1-\2) - int success = pre->Execute(di, startPos); + int lineRangeStart = LineFromPosition(startPos); + int lineRangeEnd = LineFromPosition(endPos); int pos = -1; int lenRet = 0; - if (success) { - pos = pre->bopat[0]; - lenRet = pre->eopat[0] - pre->bopat[0]; + char searchEnd = '\0'; + if (*s) + searchEnd = s[strlen(s)-1]; + for (int line=lineRangeStart; line<=lineRangeEnd; line++) { + int startOfLine = LineStart(line); + int endOfLine = LineEnd(line); + if (line == lineRangeStart) { + if ((startPos != startOfLine) && (s[0] == '^')) + continue; // Can't match start of line if start position after start of line + startOfLine = startPos; + } + if (line == lineRangeEnd) { + if ((endPos != endOfLine) && (searchEnd == '$')) + continue; // Can't match end of line if end position before end of line + endOfLine = endPos; + } + DocumentIndexer di(this, endOfLine); + int success = pre->Execute(di, startOfLine); + if (success) { + pos = pre->bopat[0]; + lenRet = pre->eopat[0] - pre->bopat[0]; + break; + } } - delete []pat; *length = lenRet; return pos; |