void SearchThread::DoSearchLine(const wxString& line, const int lineNum, const int lineOffset, const wxString& fileName, const SearchData* data, const wxString& findWhat, const wxArrayString& filters, TextStatesPtr statesPtr) { wxString modLine = line; if(!data->IsMatchCase()) { modLine.MakeLower(); } int pos = 0; int col = 0; int iCorrectedCol = 0; int iCorrectedLen = 0; while(pos != wxNOT_FOUND) { pos = modLine.Find(findWhat); if(pos != wxNOT_FOUND) { col += pos; // Pipe support bool allFiltersOK = true; if(!filters.IsEmpty()) { // Apply the filters for(size_t i = 0; i < filters.size() && allFiltersOK; ++i) { allFiltersOK = (modLine.Find(filters.Item(i)) != wxNOT_FOUND); } } // Pipe filtes OK? if(!allFiltersOK) return; // we have a match if(data->IsMatchWholeWord()) { // make sure that the word before is not in the wordChars map if((pos > 0) && (m_wordCharsMap.find(modLine.GetChar(pos - 1)) != m_wordCharsMap.end())) { if(!AdjustLine(modLine, pos, findWhat)) { break; } else { col += (int)findWhat.Length(); continue; } } // if we have more characters to the right, make sure that the first char does not match any // in the wordCharsMap if(pos + findWhat.Length() <= modLine.Length()) { wxChar nextCh = modLine.GetChar(pos + findWhat.Length()); if(m_wordCharsMap.find(nextCh) != m_wordCharsMap.end()) { if(!AdjustLine(modLine, pos, findWhat)) { break; } else { col += (int)findWhat.Length(); continue; } } } } // Notify our match // correct search Pos and Length owing to non plain ASCII multibyte characters iCorrectedCol = clUTF8Length(line.c_str(), col); iCorrectedLen = clUTF8Length(findWhat.c_str(), findWhat.Length()); SearchResult result; result.SetPosition(lineOffset + col); result.SetColumnInChars(col); result.SetColumn(iCorrectedCol); result.SetLineNumber(lineNum); result.SetPattern(line); result.SetFileName(fileName); result.SetLenInChars((int)findWhat.Length()); result.SetLen(iCorrectedLen); result.SetFindWhat(data->GetFindString()); result.SetFlags(data->m_flags); int position(wxNOT_FOUND); bool canAdd(true); if(statesPtr) { position = statesPtr->LineToPos(lineNum - 1); position += iCorrectedCol; } // Make sure our match is not on a comment if(statesPtr && position != wxNOT_FOUND && data->GetSkipComments()) { if(statesPtr->states.size() > (size_t)position) { short state = statesPtr->states.at(position).state; if(state == CppWordScanner::STATE_CPP_COMMENT || state == CppWordScanner::STATE_C_COMMENT) { canAdd = false; } } } if(statesPtr && position != wxNOT_FOUND && data->GetSkipStrings()) { if(statesPtr->states.size() > (size_t)position) { short state = statesPtr->states.at(position).state; if(state == CppWordScanner::STATE_DQ_STRING || state == CppWordScanner::STATE_SINGLE_STRING) { canAdd = false; } } } result.SetMatchState(CppWordScanner::STATE_NORMAL); if(canAdd && statesPtr && position != wxNOT_FOUND && data->GetColourComments()) { // set the match state if(statesPtr->states.size() > (size_t)position) { short state = statesPtr->states.at(position).state; if(state == CppWordScanner::STATE_C_COMMENT || state == CppWordScanner::STATE_CPP_COMMENT) { result.SetMatchState(state); } } } if(canAdd) { m_results.push_back(result); m_summary.SetNumMatchesFound(m_summary.GetNumMatchesFound() + 1); } if(!AdjustLine(modLine, pos, findWhat)) { break; } col += (int)findWhat.Length(); } } }
void SearchThread::DoSearchLineRE(const wxString& line, const int lineNum, const int lineOffset, const wxString& fileName, const SearchData* data, TextStatesPtr statesPtr) { wxRegEx& re = GetRegex(data->GetFindString(), data->IsMatchCase()); size_t col = 0; int iCorrectedCol = 0; int iCorrectedLen = 0; wxString modLine = line; if(re.IsValid()) { while(re.Matches(modLine)) { size_t start, len; re.GetMatch(&start, &len); col += start; // Notify our match // correct search Pos and Length owing to non plain ASCII multibyte characters iCorrectedCol = clUTF8Length(line.c_str(), col); iCorrectedLen = clUTF8Length(line.c_str(), col + len) - iCorrectedCol; SearchResult result; result.SetPosition(lineOffset + col); result.SetColumnInChars((int)col); result.SetColumn(iCorrectedCol); result.SetLineNumber(lineNum); result.SetPattern(line); result.SetFileName(fileName); result.SetLenInChars((int)len); result.SetLen(iCorrectedLen); result.SetFlags(data->m_flags); result.SetFindWhat(data->GetFindString()); // Make sure our match is not on a comment int position(wxNOT_FOUND); bool canAdd(true); if(statesPtr) { position = statesPtr->LineToPos(lineNum - 1); position += iCorrectedCol; } if(statesPtr && position != wxNOT_FOUND && data->GetSkipComments()) { if(statesPtr->states.size() > (size_t)position) { short state = statesPtr->states.at(position).state; if(state == CppWordScanner::STATE_CPP_COMMENT || state == CppWordScanner::STATE_C_COMMENT) { canAdd = false; } } } if(statesPtr && position != wxNOT_FOUND && data->GetSkipStrings()) { if(statesPtr->states.size() > (size_t)position) { short state = statesPtr->states.at(position).state; if(state == CppWordScanner::STATE_DQ_STRING || state == CppWordScanner::STATE_SINGLE_STRING) { canAdd = false; } } } result.SetMatchState(CppWordScanner::STATE_NORMAL); if(canAdd && statesPtr && position != wxNOT_FOUND && data->GetColourComments()) { // set the match state if(statesPtr->states.size() > (size_t)position) { short state = statesPtr->states.at(position).state; if(state == CppWordScanner::STATE_C_COMMENT || state == CppWordScanner::STATE_CPP_COMMENT) { result.SetMatchState(state); } } } if(canAdd) { m_results.push_back(result); m_summary.SetNumMatchesFound(m_summary.GetNumMatchesFound() + 1); } col += len; // adjust the line if(line.Length() - col <= 0) break; modLine = modLine.Right(line.Length() - col); } } }