Skip to content

Commit

Permalink
fix regex error message
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Jul 22, 2017
1 parent df64327 commit 2fee9ed
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 28 deletions.
4 changes: 4 additions & 0 deletions far/changelog
@@ -1,3 +1,7 @@
drkns 22.07.2017 13:25:18 +0000 - build 4992

1. С форума: Ошибочная индикация позиции ошибки в регэкспе

drkns 21.07.2017 19:29:12 +0000 - build 4991

1. Уточнение 4989.
Expand Down
6 changes: 2 additions & 4 deletions far/editor.cpp
Expand Up @@ -3430,18 +3430,16 @@ bool Editor::Search(bool Next)

auto CurPtr = FindAllReferences? FirstLine() : m_it_CurLine, TmpPtr = CurPtr;

string strSlash(strSearchStr);
InsertRegexpQuote(strSlash);
std::vector<RegExpMatch> m;
MatchHash hm;
RegExp re;

if (Regexp)
{
// Q: что важнее: опция диалога или опция RegExp`а?
if (!re.Compile(strSlash.data(), OP_PERLSTYLE|OP_OPTIMIZE|(!Case?OP_IGNORECASE:0)))
if (!re.Compile(strSearchStr.data(), OP_OPTIMIZE | (Case? 0 : OP_IGNORECASE)))
{
ReCompileErrorMessage(re, strSlash);
ReCompileErrorMessage(re, strSearchStr);
return false; //BUGBUG
}
m.resize(re.GetBracketsCount() * 2);
Expand Down
6 changes: 2 additions & 4 deletions far/help.cpp
Expand Up @@ -1896,18 +1896,16 @@ void Help::Search(const os::fs::file& HelpFile,uintptr_t nCodePage)
GetFileString GetStr(HelpFile, nCodePage);
string strCurTopic, strEntryName, strReadStr;

string strSlash(strLastSearchStr);
InsertRegexpQuote(strSlash);
std::vector<RegExpMatch> m;
MatchHash hm;
RegExp re;

if (LastSearchRegexp)
{
// Q: что важнее: опция диалога или опция RegExp`а?
if (!re.Compile(strSlash.data(), OP_PERLSTYLE|OP_OPTIMIZE|(!LastSearchCase?OP_IGNORECASE:0)))
if (!re.Compile(strLastSearchStr.data(), OP_OPTIMIZE | (LastSearchCase? 0 : OP_IGNORECASE)))
{
ReCompileErrorMessage(re, strSlash);
ReCompileErrorMessage(re, strLastSearchStr);
return; //BUGBUG
}

Expand Down
12 changes: 0 additions & 12 deletions far/strmix.cpp
Expand Up @@ -138,18 +138,6 @@ string& InsertQuote(string &strStr)
return InsertCustomQuote(strStr,L'\"');
}

string& InsertRegexpQuote(string &strStr)
{
//выражение вида /regexp/i не дополняем слешами
if (!strStr.empty() && strStr[0] != L'/')
{
strStr.insert(0, 1, L'/');
strStr += L'/';
}

return strStr;
}

string &QuoteSpace(string &strStr)
{
if (strStr.find_first_of(Global->Opt->strQuotedSymbols) != string::npos)
Expand Down
1 change: 0 additions & 1 deletion far/strmix.hpp
Expand Up @@ -60,7 +60,6 @@ inline string InsertQuote(string&& strStr) { InsertQuote(strStr); return strStr;
string& Unquote(string &strStr);
inline string Unquote(string&& strStr) { Unquote(strStr); return strStr; }

string& InsertRegexpQuote(string& strStr);
void UnquoteExternal(string &strStr);
string& RemoveLeadingSpaces(string &strStr);
string& RemoveTrailingSpaces(string &strStr);
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4991)m4_dnl
m4_define(BUILD,4992)m4_dnl
10 changes: 4 additions & 6 deletions far/viewer.cpp
Expand Up @@ -3429,16 +3429,15 @@ void Viewer::Search(int Next,int FirstChar)
sd.ch_size = getCharSize();
sd.search_text = strSearchStr.data();

InsertQuote(strMsgStr);

if (SearchRegexp)
{
WholeWords = false;
searcher = (ReverseSearch ? &Viewer::search_regex_backward : &Viewer::search_regex_forward);
InsertRegexpQuote(strMsgStr);
string strSlash = strSearchStr;
InsertRegexpQuote(strSlash);
if (!sd.InitRegEx(strSlash, OP_PERLSTYLE | OP_OPTIMIZE | (Case ? 0 : OP_IGNORECASE)))
if (!sd.InitRegEx(strSearchStr, OP_OPTIMIZE | (Case ? 0 : OP_IGNORECASE)))
{
ReCompileErrorMessage(*sd.pRex, strSlash);
ReCompileErrorMessage(*sd.pRex, strSearchStr);
return; // wrong regular expression...
}
sd.RexMatchCount = sd.pRex->GetBracketsCount();
Expand All @@ -3447,7 +3446,6 @@ void Viewer::Search(int Next,int FirstChar)
else
{
searcher = (ReverseSearch ? &Viewer::search_text_backward : &Viewer::search_text_forward);
InsertQuote(strMsgStr);
}
}

Expand Down

0 comments on commit 2fee9ed

Please sign in to comment.