]> git.saurik.com Git - wxWidgets.git/blob - src/html/search.cpp
unnecessary ClipRects
[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 #include <wx/wx.h>
27 #endif
28
29 #include "wx/html/helpdata.h"
30
31
32
33 //--------------------------------------------------------------------------------
34 // wxSearchEngine
35 //--------------------------------------------------------------------------------
36
37 void wxSearchEngine::LookFor(const wxString& keyword)
38 {
39 if (m_Keyword) delete[] m_Keyword;
40 m_Keyword = new wxChar[keyword.Length() + 1];
41 wxStrcpy(m_Keyword, keyword.c_str());
42 for (int i = wxStrlen(m_Keyword) - 1; i >= 0; i--)
43 if ((m_Keyword[i] >= wxT('A')) && (m_Keyword[i] <= wxT('Z')))
44 m_Keyword[i] += wxT('a') - wxT('A');
45 }
46
47
48
49 bool wxSearchEngine::Scan(wxInputStream *stream)
50 {
51 wxASSERT_MSG(m_Keyword != NULL, _("wxSearchEngine::LookFor must be called before scanning!"));
52
53 int i, j;
54 int lng = stream ->GetSize();
55 int wrd = wxStrlen(m_Keyword);
56 bool found = FALSE;
57 char *buf = new char[lng + 1];
58 stream -> Read(buf, lng);
59 buf[lng] = 0;
60
61 for (i = 0; i < lng; i++)
62 if ((buf[i] >= 'A') && (buf[i] <= 'Z')) buf[i] += 'a' - 'A';
63
64 for (i = 0; i < lng - wrd; i++) {
65 j = 0;
66 while ((j < wrd) && (buf[i + j] == m_Keyword[j])) j++;
67 if (j == wrd) {found = TRUE; break;}
68 }
69
70 delete[] buf;
71 return found;
72 }
73
74 #endif