diff options
author | nyamatongwe <unknown> | 2010-03-25 12:10:59 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2010-03-25 12:10:59 +0000 |
commit | 295013083c4e9454656c0e94ab977057ee55ea11 (patch) | |
tree | 661dd867b477a189c846fada99399ba9a61bc191 /src/Editor.cxx | |
parent | 9f6eff4d795ec5cef078a432b89744f5542a1ade (diff) | |
download | scintilla-mirror-295013083c4e9454656c0e94ab977057ee55ea11.tar.gz |
New case insensitive searching implementation uses objects implementing
the CaseFolder interface to fold both search text and document text
so they can be compared with a simple strcmp.
A simple table based folder CaseFolderTable is used for 8 bit encodings
and maps input bytes to folded bytes. For multi-byte encodings
except for UTF-8 a null (output same as input) CaseFolderTable is used.
For UTF-8, more complex subclasses are used which call platform APIs
to perform the folding.
Folding is approximately to lower case although this differs between
platforms.
Diffstat (limited to 'src/Editor.cxx')
-rw-r--r-- | src/Editor.cxx | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 4bdbecda8..e5623b542 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -13,6 +13,7 @@ #include <string> #include <vector> #include <algorithm> +#include <memory> // With Borland C++ 5.5, including <string> includes Windows.h leading to defining // FindText to FindTextA which makes calls here to Document::FindText fail. @@ -5309,6 +5310,31 @@ void Editor::Indent(bool forwards) { } } +class CaseFolderASCII : public CaseFolderTable { +public: + CaseFolderASCII() { + StandardASCII(); + } + ~CaseFolderASCII() { + } + virtual size_t Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) { + if (lenMixed > sizeFolded) { + return 0; + } else { + for (size_t i=0; i<lenMixed; i++) { + folded[i] = mapping[static_cast<unsigned char>(mixed[i])]; + } + return lenMixed; + } + } +}; + + +CaseFolder *Editor::CaseFolderForEncoding() { + // Simple default that only maps ASCII upper case to lower case. + return new CaseFolderASCII(); +} + /** * Search of a text in the document, in the given range. * @return The position of the found text, -1 if not found. @@ -5320,13 +5346,15 @@ long Editor::FindText( Sci_TextToFind *ft = reinterpret_cast<Sci_TextToFind *>(lParam); int lengthFound = istrlen(ft->lpstrText); + std::auto_ptr<CaseFolder> pcf(CaseFolderForEncoding()); int pos = pdoc->FindText(ft->chrg.cpMin, ft->chrg.cpMax, ft->lpstrText, (wParam & SCFIND_MATCHCASE) != 0, (wParam & SCFIND_WHOLEWORD) != 0, (wParam & SCFIND_WORDSTART) != 0, (wParam & SCFIND_REGEXP) != 0, wParam, - &lengthFound); + &lengthFound, + pcf.get()); if (pos != -1) { ft->chrgText.cpMin = pos; ft->chrgText.cpMax = pos + lengthFound; @@ -5363,6 +5391,7 @@ long Editor::SearchText( const char *txt = reinterpret_cast<char *>(lParam); int pos; int lengthFound = istrlen(txt); + std::auto_ptr<CaseFolder> pcf(CaseFolderForEncoding()); if (iMessage == SCI_SEARCHNEXT) { pos = pdoc->FindText(searchAnchor, pdoc->Length(), txt, (wParam & SCFIND_MATCHCASE) != 0, @@ -5370,7 +5399,8 @@ long Editor::SearchText( (wParam & SCFIND_WORDSTART) != 0, (wParam & SCFIND_REGEXP) != 0, wParam, - &lengthFound); + &lengthFound, + pcf.get()); } else { pos = pdoc->FindText(searchAnchor, 0, txt, (wParam & SCFIND_MATCHCASE) != 0, @@ -5378,9 +5408,9 @@ long Editor::SearchText( (wParam & SCFIND_WORDSTART) != 0, (wParam & SCFIND_REGEXP) != 0, wParam, - &lengthFound); + &lengthFound, + pcf.get()); } - if (pos != -1) { SetSelection(pos, pos + lengthFound); } @@ -5411,13 +5441,16 @@ std::string Editor::CaseMapString(const std::string &s, int caseMapping) { */ long Editor::SearchInTarget(const char *text, int length) { int lengthFound = length; + + std::auto_ptr<CaseFolder> pcf(CaseFolderForEncoding()); int pos = pdoc->FindText(targetStart, targetEnd, text, (searchFlags & SCFIND_MATCHCASE) != 0, (searchFlags & SCFIND_WHOLEWORD) != 0, (searchFlags & SCFIND_WORDSTART) != 0, (searchFlags & SCFIND_REGEXP) != 0, searchFlags, - &lengthFound); + &lengthFound, + pcf.get()); if (pos != -1) { targetStart = pos; targetEnd = pos + lengthFound; |