+ // check if it is same page with different anchor:
+ if (!m_LastPage.empty())
+ {
+ const wxChar *p1, *p2;
+ for (p1 = thepage.c_str(), p2 = m_LastPage.c_str();
+ *p1 != 0 && *p1 != _T('#') && *p1 == *p2; p1++, p2++) {}
+
+ m_LastPage = thepage;
+
+ if (*p1 == 0 || *p1 == _T('#'))
+ return false;
+ }
+ else m_LastPage = thepage;
+
+ wxFileSystem fsys;
+ file = fsys.OpenFile(m_Data->m_contents[i].book->GetFullPath(thepage));
+ if (file)
+ {
+ if (m_Engine.Scan(*file))
+ {
+ m_Name = m_Data->m_contents[i].name;
+ m_CurItem = &m_Data->m_contents[i];
+ found = true;
+ }
+ delete file;
+ }
+ return found;
+}
+
+
+
+
+
+
+
+
+//--------------------------------------------------------------------------------
+// wxHtmlSearchEngine
+//--------------------------------------------------------------------------------
+
+void wxHtmlSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only)
+{
+ m_CaseSensitive = case_sensitive;
+ m_WholeWords = whole_words_only;
+ m_Keyword = keyword;
+
+ if (!m_CaseSensitive)
+ m_Keyword.LowerCase();
+}
+
+
+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.empty(), wxT("wxHtmlSearchEngine::LookFor must be called before scanning!"));
+
+ int i, j;
+ int wrd = m_Keyword.Length();
+ bool found = false;
+ wxHtmlFilterHTML filter;
+ wxString tmp = filter.ReadFile(file);
+ int lng = tmp.length();
+ const wxChar *buf = tmp.c_str();
+
+ if (!m_CaseSensitive)
+ tmp.LowerCase();
+
+ const wxChar *kwd = m_Keyword.c_str();
+
+ if (m_WholeWords)
+ {
+ for (i = 0; i < lng - wrd; i++)
+ {
+ if (WHITESPACE(buf[i])) continue;
+ j = 0;
+ while ((j < wrd) && (buf[i + j] == kwd[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] == kwd[j])) j++;
+ if (j == wrd) { found = true; break; }
+ }
+ }
+