diff options
| author | Neil <nyamatongwe@gmail.com> | 2014-10-02 18:17:13 +1000 | 
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2014-10-02 18:17:13 +1000 | 
| commit | 2603f1e2074b0f880886b533ffc47ecef4fd33f7 (patch) | |
| tree | 53bfaff1eca31d0768f43d0c496c81b551230a2d /src/Editor.cxx | |
| parent | 8c42cc95ae3fbfdb8d4b7e8893c2fee283efe1a6 (diff) | |
| download | scintilla-mirror-2603f1e2074b0f880886b533ffc47ecef4fd33f7.tar.gz | |
Allow using C++11 <regex> for searches as a provisional feature.
Diffstat (limited to 'src/Editor.cxx')
| -rw-r--r-- | src/Editor.cxx | 91 | 
1 files changed, 53 insertions, 38 deletions
| diff --git a/src/Editor.cxx b/src/Editor.cxx index 8748d89c1..80f96a7c8 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -3639,18 +3639,23 @@ long Editor::FindText(  	int lengthFound = istrlen(ft->lpstrText);  	if (!pdoc->HasCaseFolder())  		pdoc->SetCaseFolder(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, -	        static_cast<int>(wParam), -	        &lengthFound); -	if (pos != -1) { -		ft->chrgText.cpMin = pos; -		ft->chrgText.cpMax = pos + lengthFound; +	try { +		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, +			static_cast<int>(wParam), +			&lengthFound); +		if (pos != -1) { +			ft->chrgText.cpMin = pos; +			ft->chrgText.cpMax = pos + lengthFound; +		} +		return pos; +	} catch (RegexError &) { +		errorStatus = SC_STATUS_WARN_REGEX; +		return -1;  	} -	return pos;  }  /** @@ -3684,22 +3689,27 @@ long Editor::SearchText(  	int lengthFound = istrlen(txt);  	if (!pdoc->HasCaseFolder())  		pdoc->SetCaseFolder(CaseFolderForEncoding()); -	if (iMessage == SCI_SEARCHNEXT) { -		pos = pdoc->FindText(searchAnchor, pdoc->Length(), txt, -		        (wParam & SCFIND_MATCHCASE) != 0, -		        (wParam & SCFIND_WHOLEWORD) != 0, -		        (wParam & SCFIND_WORDSTART) != 0, -		        (wParam & SCFIND_REGEXP) != 0, -		        static_cast<int>(wParam), -		        &lengthFound); -	} else { -		pos = pdoc->FindText(searchAnchor, 0, txt, -		        (wParam & SCFIND_MATCHCASE) != 0, -		        (wParam & SCFIND_WHOLEWORD) != 0, -		        (wParam & SCFIND_WORDSTART) != 0, -		        (wParam & SCFIND_REGEXP) != 0, -		        static_cast<int>(wParam), -		        &lengthFound); +	try { +		if (iMessage == SCI_SEARCHNEXT) { +			pos = pdoc->FindText(searchAnchor, pdoc->Length(), txt, +					(wParam & SCFIND_MATCHCASE) != 0, +					(wParam & SCFIND_WHOLEWORD) != 0, +					(wParam & SCFIND_WORDSTART) != 0, +					(wParam & SCFIND_REGEXP) != 0, +					static_cast<int>(wParam), +					&lengthFound); +		} else { +			pos = pdoc->FindText(searchAnchor, 0, txt, +					(wParam & SCFIND_MATCHCASE) != 0, +					(wParam & SCFIND_WHOLEWORD) != 0, +					(wParam & SCFIND_WORDSTART) != 0, +					(wParam & SCFIND_REGEXP) != 0, +					static_cast<int>(wParam), +					&lengthFound); +		} +	} catch (RegexError &) { +		errorStatus = SC_STATUS_WARN_REGEX; +		return -1;  	}  	if (pos != -1) {  		SetSelection(pos, pos + lengthFound); @@ -3734,18 +3744,23 @@ long Editor::SearchInTarget(const char *text, int length) {  	if (!pdoc->HasCaseFolder())  		pdoc->SetCaseFolder(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); -	if (pos != -1) { -		targetStart = pos; -		targetEnd = pos + lengthFound; +	try { +		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); +		if (pos != -1) { +			targetStart = pos; +			targetEnd = pos + lengthFound; +		} +		return pos; +	} catch (RegexError &) { +		errorStatus = SC_STATUS_WARN_REGEX; +		return -1;  	} -	return pos;  }  void Editor::GoToLine(int lineNo) { | 
