+
+
+
+
+
+
+
+//--------------------------------------------------------------------------------
+// wxHtmlSearchEngine
+//--------------------------------------------------------------------------------
+
+void wxHtmlSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only)
+{
+ m_CaseSensitive = case_sensitive;
+ m_WholeWords = whole_words_only;
+ if (m_Keyword) delete[] m_Keyword;
+ m_Keyword = new wxChar[keyword.Length() + 1];
+ wxStrcpy(m_Keyword, keyword.c_str());
+
+ if (!m_CaseSensitive)
+ {
+ for (int i = wxStrlen(m_Keyword) - 1; i >= 0; i--)
+ {
+ if ((m_Keyword[i] >= wxT('A')) && (m_Keyword[i] <= wxT('Z')))
+ m_Keyword[i] += wxT('a') - wxT('A');
+ }
+ }
+}
+
+
+static inline bool WHITESPACE(wxChar c)
+{
+ return c == _T(' ') || c == _T('\n') || c == _T('\r') || c == _T('\t');
+}
+
+bool wxHtmlSearchEngine::Scan(const wxFSFile& file)
+{
+ wxASSERT_MSG(m_Keyword != NULL, wxT("wxHtmlSearchEngine::LookFor must be called before scanning!"));
+
+ int i, j;
+ int wrd = wxStrlen(m_Keyword);
+ bool found = FALSE;
+ wxHtmlFilterHTML filter;
+ wxString tmp = filter.ReadFile(file);
+ int lng = tmp.length();
+ const wxChar *buf = tmp.c_str();
+
+ if (!m_CaseSensitive)
+ for (i = 0; i < lng; i++)
+ tmp[(size_t)i] = (wxChar)wxTolower(tmp[(size_t)i]);
+
+ if (m_WholeWords)
+ {
+ for (i = 0; i < lng - wrd; i++)
+ {
+ if (WHITESPACE(buf[i])) continue;
+ j = 0;
+ while ((j < wrd) && (buf[i + j] == m_Keyword[j])) j++;
+ if (j == wrd && WHITESPACE(buf[i + j])) { found = TRUE; break; }
+ }
+ }
+
+ else
+ {
+ for (i = 0; i < lng - wrd; i++)
+ {
+ j = 0;
+ while ((j < wrd) && (buf[i + j] == m_Keyword[j])) j++;
+ if (j == wrd) { found = TRUE; break; }
+ }
+ }
+
+ return found;
+}
+
+
+