diff options
-rw-r--r-- | gtk/makefile | 7 | ||||
-rw-r--r-- | gtk/scintilla.mak | 8 | ||||
-rw-r--r-- | src/Document.cxx | 155 | ||||
-rw-r--r-- | src/Document.h | 4 | ||||
-rw-r--r-- | src/Editor.cxx | 30 | ||||
-rw-r--r-- | vcbuild/SciLexer.dsp | 4 | ||||
-rw-r--r-- | win32/makefile | 12 | ||||
-rw-r--r-- | win32/scintilla.mak | 8 |
8 files changed, 151 insertions, 77 deletions
diff --git a/gtk/makefile b/gtk/makefile index 77d7225e3..7ee7a70db 100644 --- a/gtk/makefile +++ b/gtk/makefile @@ -35,7 +35,7 @@ all: $(COMPLIB) $(LEXOBJS) $(COMPLIB): DocumentAccessor.o WindowAccessor.o KeyWords.o Document.o CallTip.o \ ScintillaBase.o ContractionState.o Editor.o PropSet.o PlatGTK.o \ KeyMap.o LineMarker.o ScintillaGTK.o CellBuffer.o ViewStyle.o \ - Style.o Indicator.o AutoComplete.o + PosRegExp.o Style.o Indicator.o AutoComplete.o $(AR) rc $@ $^ AutoComplete.o: AutoComplete.cxx Platform.h AutoComplete.h @@ -43,8 +43,8 @@ CallTip.o: CallTip.cxx Platform.h CallTip.h CellBuffer.o: CellBuffer.cxx Platform.h Scintilla.h WinDefs.h \ CellBuffer.h ContractionState.o: ContractionState.cxx Platform.h ContractionState.h -Document.o: Document.cxx Platform.h Scintilla.h WinDefs.h CellBuffer.h \ - Document.h +Document.o: Document.cxx Platform.h Scintilla.h WinDefs.h PosRegExp.h \
+ CellBuffer.h Document.h DocumentAccessor.o: DocumentAccessor.cxx Platform.h PropSet.h SString.h \ Accessor.h DocumentAccessor.h Scintilla.h WinDefs.h Editor.o: Editor.cxx Platform.h Scintilla.h WinDefs.h \ @@ -80,6 +80,7 @@ LexVB.o: LexVB.cxx Platform.h PropSet.h SString.h \ LineMarker.o: LineMarker.cxx Platform.h Scintilla.h WinDefs.h \ LineMarker.h PlatGTK.o: PlatGTK.cxx Platform.h Scintilla.h ScintillaWidget.h WinDefs.h +PosRegExp.o: PosRegExp.cxx PosRegExp.h PropSet.o: PropSet.cxx Platform.h PropSet.h SString.h SciTEBase.o: SciTEBase.cxx Platform.h WinDefs.h SciTE.h PropSet.h \ SString.h Accessor.h KeyWords.h Scintilla.h SciLexer.h SciTEBase.h diff --git a/gtk/scintilla.mak b/gtk/scintilla.mak index 6398b4122..0d813f63a 100644 --- a/gtk/scintilla.mak +++ b/gtk/scintilla.mak @@ -107,6 +107,7 @@ SOBJS=\ $(DIR_O)\KeyMap.obj \ $(DIR_O)\LineMarker.obj \ $(DIR_O)\PlatGTK.obj \ + $(DIR_O)\PosRegExp.obj \ $(DIR_O)\ScintillaBase.obj \ $(DIR_O)\ScintillaGTK.obj \ $(DIR_O)\Style.obj \ @@ -138,6 +139,7 @@ LOBJS=\ $(DIR_O)\KeyWords.obj \ $(DIR_O)\LineMarker.obj \ $(DIR_O)\PlatGTK.obj \ + $(DIR_O)\PosRegExp.obj \ $(DIR_O)\PropSet.obj \ $(DIR_O)\ScintillaBaseL.obj \ $(DIR_O)\ScintillaGTKL.obj \ @@ -203,8 +205,8 @@ $(DIR_O)\CellBuffer.obj: ..\src\CellBuffer.cxx ..\include\Platform.h ..\include\ $(DIR_O)\ContractionState.obj: ..\src\ContractionState.cxx ..\include\Platform.h ..\src\ContractionState.h -$(DIR_O)\Document.obj: ..\src\Document.cxx ..\include\Platform.h ..\include\Scintilla.h ..\src\CellBuffer.h \ - ..\src\Document.h +$(DIR_O)\Document.obj: ..\src\Document.cxx ..\include\Platform.h ..\include\Scintilla.h ..\include\PosRegExp.h \ + ..\src\CellBuffer.h ..\src\Document.h $(DIR_O)\DocumentAccessor.obj: ..\src\DocumentAccessor.cxx ..\include\Platform.h ..\include\PropSet.h ..\include\Accessor.h ..\src\DocumentAccessor.h ..\include\Scintilla.h @@ -253,6 +255,8 @@ $(DIR_O)\LineMarker.obj: ..\src\LineMarker.cxx ..\include\Platform.h ..\include\ $(DIR_O)\PlatWin.obj: PlatWin.cxx ..\include\Platform.h PlatformRes.h ..\src\UniConversion.h +$(DIR_O)\PosRegExp.obj: ..\src\PosRegExp.cxx ..\include\PosRegExp.h + $(DIR_O)\PropSet.obj: ..\src\PropSet.cxx ..\include\Platform.h ..\include\PropSet.h $(DIR_O)\ScintillaBase.obj: ..\src\ScintillaBase.cxx ..\include\Platform.h ..\include\Scintilla.h \ diff --git a/src/Document.cxx b/src/Document.cxx index 6be928cf7..babe25bcf 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -16,6 +16,7 @@ #include "SVector.h" #include "CellBuffer.h" #include "Document.h" +#include "PosRegExp.h" // This is ASCII specific but is safe with chars >= 0x80 inline bool isspacechar(unsigned char ch) { @@ -742,70 +743,118 @@ bool Document::IsWordAt(int start, int end) { return IsWordStartAt(start) && IsWordEndAt(end); } +char Document::DocCharAt(int pos, void *param) { + return reinterpret_cast<Document*>(param)->CharAt(pos); +} + // Find text in document, supporting both forward and backward // searches (just pass minPos > maxPos to do a backward search) // Has not been tested with backwards DBCS searches yet. long Document::FindText(int minPos, int maxPos, const char *s, - bool caseSensitive, bool word, bool wordStart) { - bool forward = minPos <= maxPos; - int increment = forward ? 1 : -1; - - // Range endpoints should not be inside DBCS characters, but just in case, move them. - int startPos = MovePositionOutsideChar(minPos, increment, false); - int endPos = MovePositionOutsideChar(maxPos, increment, false); - - // Compute actual search ranges needed - int lengthFind = strlen(s); - int endSearch = endPos; - if (startPos <= endPos) { - endSearch = endPos - lengthFind + 1; - } - //Platform::DebugPrintf("Find %d %d %s %d\n", startPos, endPos, ft->lpstrText, lengthFind); - char firstChar = s[0]; - if (!caseSensitive) - firstChar = static_cast<char>(toupper(firstChar)); - int pos = startPos; - while (forward ? (pos < endSearch) : (pos >= endSearch)) { - char ch = CharAt(pos); - if (caseSensitive) { - if (ch == firstChar) { - bool found = true; - for (int posMatch = 1; posMatch < lengthFind && found; posMatch++) { - ch = CharAt(pos + posMatch); - if (ch != s[posMatch]) - found = false; - } - if (found) { - if ((!word && !wordStart) || - word && IsWordAt(pos, pos + lengthFind) || - wordStart && IsWordStartAt(pos)) - return pos; - } - } + bool caseSensitive, bool word, bool wordStart, bool regExp, + int *length) { + if (regExp) { + char *pat = new char[strlen(s) + 4]; + if (!pat) + return -1; + + strcpy(pat, "/"); + int startPos; + int endPos; + + if (minPos <= maxPos) { + startPos = minPos; + endPos = maxPos; } else { - if (toupper(ch) == firstChar) { - bool found = true; - for (int posMatch = 1; posMatch < lengthFind && found; posMatch++) { - ch = CharAt(pos + posMatch); - if (toupper(ch) != toupper(s[posMatch])) - found = false; + startPos = maxPos; + endPos = minPos; + } + + // Range endpoints should not be inside DBCS characters, but just in case, move them. + startPos = MovePositionOutsideChar(startPos, 1, false); + endPos = MovePositionOutsideChar(endPos, 1, false); + + strcat(pat, s); + strcat(pat, "/"); + PosRegExp re; + if (!caseSensitive) + strcat(pat, "i"); + if (!re.SetExpr(pat)) { + delete []pat; + return -1; + } + re.param = this; + re.CharAt = DocCharAt; + SMatches matches; + if (!re.Parse(startPos, 0, endPos, &matches)) { + delete []pat; + return -1; + } + *length = matches.e[0] - matches.s[0]; + delete []pat; + return matches.s[0]; + } else { + + bool forward = minPos <= maxPos; + int increment = forward ? 1 : -1; + + // Range endpoints should not be inside DBCS characters, but just in case, move them. + int startPos = MovePositionOutsideChar(minPos, increment, false); + int endPos = MovePositionOutsideChar(maxPos, increment, false); + + // Compute actual search ranges needed + int lengthFind = strlen(s); + int endSearch = endPos; + if (startPos <= endPos) { + endSearch = endPos - lengthFind + 1; + } + //Platform::DebugPrintf("Find %d %d %s %d\n", startPos, endPos, ft->lpstrText, lengthFind); + char firstChar = s[0]; + if (!caseSensitive) + firstChar = static_cast<char>(toupper(firstChar)); + int pos = startPos; + while (forward ? (pos < endSearch) : (pos >= endSearch)) { + char ch = CharAt(pos); + if (caseSensitive) { + if (ch == firstChar) { + bool found = true; + for (int posMatch = 1; posMatch < lengthFind && found; posMatch++) { + ch = CharAt(pos + posMatch); + if (ch != s[posMatch]) + found = false; + } + if (found) { + if ((!word && !wordStart) || + word && IsWordAt(pos, pos + lengthFind) || + wordStart && IsWordStartAt(pos)) + return pos; + } } - if (found) { - if ((!word && !wordStart) || - word && IsWordAt(pos, pos + lengthFind) || - wordStart && IsWordStartAt(pos)) - return pos; + } else { + if (toupper(ch) == firstChar) { + bool found = true; + for (int posMatch = 1; posMatch < lengthFind && found; posMatch++) { + ch = CharAt(pos + posMatch); + if (toupper(ch) != toupper(s[posMatch])) + found = false; + } + if (found) { + if ((!word && !wordStart) || + word && IsWordAt(pos, pos + lengthFind) || + wordStart && IsWordStartAt(pos)) + return pos; + } } } - } - pos += increment; - if (dbcsCodePage) { - // Ensure trying to match from start of character - pos = MovePositionOutsideChar(pos, increment, false); + pos += increment; + if (dbcsCodePage) { + // Ensure trying to match from start of character + pos = MovePositionOutsideChar(pos, increment, false); + } } } //Platform::DebugPrintf("Not found\n"); - return - 1; + return -1; } int Document::LinesTotal() { diff --git a/src/Document.h b/src/Document.h index 4b0b9b1db..cfb131608 100644 --- a/src/Document.h +++ b/src/Document.h @@ -173,7 +173,7 @@ public: int NextWordStart(int pos, int delta); int Length() { return cb.Length(); } long FindText(int minPos, int maxPos, const char *s, - bool caseSensitive, bool word, bool wordStart); + bool caseSensitive, bool word, bool wordStart, bool regExp, int *length); long FindText(int iMessage, unsigned long wParam, long lParam); int LinesTotal(); @@ -196,6 +196,8 @@ public: const WatcherWithUserData *GetWatchers() const { return watchers; } int GetLenWatchers() const { return lenWatchers; } + static char DocCharAt(int pos, void *param); + bool IsWordPartSeparator(char ch); int WordPartLeft(int pos); int WordPartRight(int pos); diff --git a/src/Editor.cxx b/src/Editor.cxx index afc127c07..479157e39 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2458,13 +2458,17 @@ void Editor::Indent(bool forwards) { long Editor::FindText(unsigned int iMessage, unsigned long wParam, long lParam) { TextToFind *ft = reinterpret_cast<TextToFind *>(lParam); + int lengthFound = strlen(ft->lpstrText); int pos = pdoc->FindText(ft->chrg.cpMin, ft->chrg.cpMax, ft->lpstrText, - wParam & SCFIND_MATCHCASE, wParam & SCFIND_WHOLEWORD, - wParam & SCFIND_WORDSTART); + wParam & SCFIND_MATCHCASE, + wParam & SCFIND_WHOLEWORD, + wParam & SCFIND_WORDSTART, + wParam & SCFIND_REGEXP, + &lengthFound); if (pos != -1) { if (iMessage != EM_FINDTEXT) { ft->chrgText.cpMin = pos; - ft->chrgText.cpMax = pos + strlen(ft->lpstrText); + ft->chrgText.cpMax = pos + lengthFound; } } return pos; @@ -2489,21 +2493,25 @@ void Editor::SearchAnchor() { long Editor::SearchText(unsigned int iMessage, unsigned long wParam, long lParam) { const char *txt = reinterpret_cast<char *>(lParam); int pos; - + int lengthFound = strlen(txt); if (iMessage == SCI_SEARCHNEXT) { pos = pdoc->FindText(searchAnchor, pdoc->Length(), txt, - wParam & SCFIND_MATCHCASE, - wParam & SCFIND_WHOLEWORD, - wParam & SCFIND_WORDSTART); + wParam & SCFIND_MATCHCASE, + wParam & SCFIND_WHOLEWORD, + wParam & SCFIND_WORDSTART, + wParam & SCFIND_REGEXP, + &lengthFound); } else { pos = pdoc->FindText(searchAnchor, 0, txt, - wParam & SCFIND_MATCHCASE, - wParam & SCFIND_WHOLEWORD, - wParam & SCFIND_WORDSTART); + wParam & SCFIND_MATCHCASE, + wParam & SCFIND_WHOLEWORD, + wParam & SCFIND_WORDSTART, + wParam & SCFIND_REGEXP, + &lengthFound); } if (pos != -1) { - SetSelection(pos, pos + strlen(txt)); + SetSelection(pos, pos + lengthFound); } return pos; diff --git a/vcbuild/SciLexer.dsp b/vcbuild/SciLexer.dsp index 6ff3245c7..1631607f0 100644 --- a/vcbuild/SciLexer.dsp +++ b/vcbuild/SciLexer.dsp @@ -186,6 +186,10 @@ SOURCE=..\win32\PlatWin.cxx # End Source File # Begin Source File +SOURCE=..\src\PosRegExp.cxx +# End Source File +# Begin Source File + SOURCE=..\src\PropSet.cxx # End Source File # Begin Source File diff --git a/win32/makefile b/win32/makefile index 8874825cd..b0e5d0609 100644 --- a/win32/makefile +++ b/win32/makefile @@ -39,15 +39,16 @@ LEXOBJS = LexAVE.o LexConf.o LexCPP.o LexHTML.o LexLua.o LexOthers.o \ SOBJS = ScintillaWin.o ScintillaBase.o Editor.o Document.o \ ContractionState.o CellBuffer.o CallTip.o \ - ScintRes.o PlatWin.o KeyMap.o Indicator.o LineMarker.o Style.o \ - ViewStyle.o AutoComplete.o UniConversion.o + ScintRes.o PlatWin.o KeyMap.o Indicator.o LineMarker.o PosRegExp.o \ + Style.o ViewStyle.o AutoComplete.o UniConversion.o $(COMPONENT): $(SOBJS) $(DLLWRAP) --target i386-mingw32 -o $@ $(SOBJS) $(LDFLAGS) -s --relocatable LOBJS = ScintillaWinL.o ScintillaBaseL.o Editor.o Document.o \ ContractionState.o CellBuffer.o CallTip.o \ - ScintRes.o PlatWin.o KeyMap.o Indicator.o LineMarker.o Style.o ViewStyle.o \ - AutoComplete.o UniConversion.o KeyWords.o DocumentAccessor.o PropSet.o $(LEXOBJS) + ScintRes.o PlatWin.o KeyMap.o Indicator.o LineMarker.o PosRegExp.o \ + Style.o ViewStyle.o AutoComplete.o UniConversion.o KeyWords.o \ + DocumentAccessor.o PropSet.o $(LEXOBJS) $(LEXCOMPONENT): $(LOBJS) $(DLLWRAP) --target i386-mingw32 -o $@ $(LOBJS) $(LDFLAGS) -s --relocatable @@ -55,8 +56,9 @@ AutoComplete.o: AutoComplete.cxx Platform.h AutoComplete.h CallTip.o: CallTip.cxx Platform.h CallTip.h CellBuffer.o: CellBuffer.cxx Platform.h Scintilla.h CellBuffer.h ContractionState.o: ContractionState.cxx Platform.h ContractionState.h -Document.o: Document.cxx Platform.h Scintilla.h CellBuffer.h \ +Document.o: Document.cxx Platform.h Scintilla.h PosRegExp.h CellBuffer.h \ Document.h +PosRegExp.o: PosRegExp.cxx PosRegExp.h DocumentAccessor.o: DocumentAccessor.cxx Platform.h PropSet.h \ SString.h Accessor.h DocumentAccessor.h Scintilla.h Editor.o: Editor.cxx Platform.h Scintilla.h ContractionState.h \ diff --git a/win32/scintilla.mak b/win32/scintilla.mak index fdf3c3865..3e3dbcf1a 100644 --- a/win32/scintilla.mak +++ b/win32/scintilla.mak @@ -95,6 +95,7 @@ SOBJS=\ $(DIR_O)\KeyMap.obj \ $(DIR_O)\LineMarker.obj \ $(DIR_O)\PlatWin.obj \ + $(DIR_O)\PosRegExp.obj \ $(DIR_O)\ScintillaBase.obj \ $(DIR_O)\ScintillaWin.obj \ $(DIR_O)\Style.obj \ @@ -127,6 +128,7 @@ LOBJS=\ $(DIR_O)\KeyWords.obj \ $(DIR_O)\LineMarker.obj \ $(DIR_O)\PlatWin.obj \ + $(DIR_O)\PosRegExp.obj \ $(DIR_O)\PropSet.obj \ $(DIR_O)\ScintillaBaseL.obj \ $(DIR_O)\ScintillaWinL.obj \ @@ -186,8 +188,8 @@ $(DIR_O)\CellBuffer.obj: ..\src\CellBuffer.cxx ..\include\Platform.h ..\include\ $(DIR_O)\ContractionState.obj: ..\src\ContractionState.cxx ..\include\Platform.h ..\src\ContractionState.h -$(DIR_O)\Document.obj: ..\src\Document.cxx ..\include\Platform.h ..\include\Scintilla.h ..\src\CellBuffer.h \ - ..\src\Document.h +$(DIR_O)\Document.obj: ..\src\Document.cxx ..\include\Platform.h ..\include\Scintilla.h \ + ..\include\PosRegExp.h ..\src\CellBuffer.h ..\src\Document.h $(DIR_O)\DocumentAccessor.obj: ..\src\DocumentAccessor.cxx ..\include\Platform.h ..\include\PropSet.h \ ..\include\SString.h ..\include\Accessor.h ..\src\DocumentAccessor.h ..\include\Scintilla.h @@ -252,6 +254,8 @@ $(DIR_O)\LineMarker.obj: ..\src\LineMarker.cxx ..\include\Platform.h ..\include\ $(DIR_O)\PlatWin.obj: PlatWin.cxx ..\include\Platform.h PlatformRes.h ..\src\UniConversion.h +$(DIR_O)\PosRegExp.obj: ..\src\PosRegExp.cxx ..\include\PosRegExp.h + $(DIR_O)\PropSet.obj: ..\src\PropSet.cxx ..\include\Platform.h ..\include\PropSet.h \ ..\include\SString.h |