]> git.saurik.com Git - wxWidgets.git/blob - src/html/search.cpp
fixed the menu bug introduced by the previous commit
[wxWidgets.git] / src / html / search.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: search.cpp
3 // Purpose: search engine
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #include "wx/defs.h"
19 #if wxUSE_HTML
20
21 #ifdef __BORDLANDC__
22 #pragma hdrstop
23 #endif
24
25 #ifndef WXPRECOMP
26 #endif
27
28 #include "wx/html/helpdata.h"
29
30
31 //--------------------------------------------------------------------------------
32 // wxSearchEngine
33 //--------------------------------------------------------------------------------
34
35 void wxSearchEngine::LookFor(const wxString& keyword)
36 {
37 if (m_Keyword) delete[] m_Keyword;
38 m_Keyword = new wxChar[keyword.Length() + 1];
39 wxStrcpy(m_Keyword, keyword.c_str());
40 for (int i = wxStrlen(m_Keyword) - 1; i >= 0; i--)
41 if ((m_Keyword[i] >= wxT('A')) && (m_Keyword[i] <= wxT('Z')))
42 m_Keyword[i] += wxT('a') - wxT('A');
43 }
44
45
46
47 bool wxSearchEngine::Scan(wxInputStream *stream)
48 {
49 wxASSERT_MSG(m_Keyword != NULL, _("wxSearchEngine::LookFor must be called before scanning!"));
50
51 int i, j;
52 int lng = stream ->GetSize();
53 int wrd = wxStrlen(m_Keyword);
54 bool found = FALSE;
55 char *buf = new char[lng + 1];
56 stream -> Read(buf, lng);
57 buf[lng] = 0;
58
59 for (i = 0; i < lng; i++)
60 if ((buf[i] >= 'A') && (buf[i] <= 'Z')) buf[i] += 'a' - 'A';
61
62 for (i = 0; i < lng - wrd; i++) {
63 j = 0;
64 while ((j < wrd) && (buf[i + j] == m_Keyword[j])) j++;
65 if (j == wrd) {found = TRUE; break;}
66 }
67
68 delete[] buf;
69 return found;
70 }
71
72 #endif