23
25
TextFileSearcher* TextFileSearcher::BuildTextFileSearcher(const wxString& searchText,
29
TextFileSearcher* pFileSearcher = NULL;
32
pFileSearcher = new TextFileSearcherRegEx(searchText, matchCase, matchWordBegin, matchWord);
36
pFileSearcher = new TextFileSearcherText(searchText, matchCase, matchWordBegin, matchWord);
39
// Tests if construction is OK
40
wxString errorMessage(wxEmptyString);
41
if ( pFileSearcher && !pFileSearcher->IsOk(&errorMessage) )
31
TextFileSearcher* pFileSearcher = NULL;
34
pFileSearcher = new TextFileSearcherRegEx(searchText, matchCase, matchWordBegin, matchWord);
38
pFileSearcher = new TextFileSearcherText(searchText, matchCase, matchWordBegin, matchWord);
41
// Tests if construction is OK
42
wxString errorMessage(wxEmptyString);
43
if ( pFileSearcher && !pFileSearcher->IsOk(&errorMessage) )
51
53
TextFileSearcher::eFileSearcherReturn TextFileSearcher::FindInFile(const wxString& filePath, wxArrayString &foundLines)
53
eFileSearcherReturn success=idStringNotFound;
56
// Tests file existence
57
if ( !wxFileName::FileExists(filePath) )
59
// We skip missing files without alerting user.
60
// If a file has disappeared, it is not our problem.
61
// cbMessageBox( filePath + _T(" does not exist."), _T("Error"), wxICON_ERROR);
62
return idFileNotFound;
66
if ( !m_TextFile.Open(filePath, wxConvFile) )
68
return idFileOpenError;
71
// Tests all file lines
72
for ( size_t i = 0; i < m_TextFile.GetLineCount(); ++i )
74
line = m_TextFile.GetLine(i);
75
if ( MatchLine(line) )
77
success=idStringFound;
78
// An interesting line is found. We clean and add it to the provided array
79
line.Replace(_T("\t"), _T(" "));
80
line.Replace(_T("\r"), _T(" "));
81
line.Replace(_T("\n"), _T(" "));
85
foundLines.Add(wxString::Format(wxT("%d"), i + 1));
55
eFileSearcherReturn success=idStringNotFound;
59
if(wxFileName::GetSize(filePath) != 0)
61
// Tests file size and existence
62
if ( !wxFileName::FileExists(filePath) )
64
// We skip missing files without alerting user.
65
// If a file has disappeared, it is not our problem.
66
// cbMessageBox( filePath + _T(" does not exist."), _T("Error"), wxICON_ERROR);
67
return idFileNotFound;
71
EncodingDetector enc(filePath, false);
74
// return idFileOpenError;
75
return idFileNotFound;
77
wxFontEncoding fe = enc.GetFontEncoding();
79
if ( fe == wxFONTENCODING_UTF7 )
82
if ( !m_TextFile.Open(filePath, conv) )
84
return idFileOpenError;
87
else if ( fe == wxFONTENCODING_UTF8 )
90
if ( !m_TextFile.Open(filePath, conv) )
92
return idFileOpenError;
95
else if ( fe == wxFONTENCODING_UTF16BE )
98
if ( !m_TextFile.Open(filePath, conv) )
100
return idFileOpenError;
103
else if ( fe == wxFONTENCODING_UTF16LE )
105
wxMBConvUTF16LE conv;
106
if ( !m_TextFile.Open(filePath, conv) )
108
return idFileOpenError;
111
else if ( fe == wxFONTENCODING_UTF32BE )
113
wxMBConvUTF32BE conv;
114
if ( !m_TextFile.Open(filePath, conv) )
116
return idFileOpenError;
119
else if ( fe == wxFONTENCODING_UTF32LE )
121
wxMBConvUTF32LE conv;
122
if ( !m_TextFile.Open(filePath, conv) )
124
return idFileOpenError;
130
if ( !m_TextFile.Open(filePath, conv) )
132
return idFileOpenError;
138
// Tests all file lines
139
for ( size_t i = 0; i < m_TextFile.GetLineCount(); ++i )
141
line = m_TextFile.GetLine(i);
142
if ( MatchLine(line) )
144
success=idStringFound;
145
// An interesting line is found. We clean and add it to the provided array
146
line.Replace(_T("\t"), _T(" "));
147
line.Replace(_T("\r"), _T(" "));
148
line.Replace(_T("\n"), _T(" "));
152
foundLines.Add(wxString::Format(wxT("%d"), i + 1));
153
foundLines.Add(line);
97
164
bool TextFileSearcher::IsOk(wxString* WXUNUSED(pErrorMessage))