]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: search.cpp | |
3 | // Purpose: search engine | |
4 | // Author: Vaclav Slavik | |
69941f05 | 5 | // RCS-ID: $Id$ |
5526e819 VS |
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 | ||
8ec2b484 | 29 | #include "wx/html/helpdata.h" |
5526e819 VS |
30 | |
31 | ||
32 | ||
33 | //-------------------------------------------------------------------------------- | |
34 | // wxSearchEngine | |
35 | //-------------------------------------------------------------------------------- | |
36 | ||
37 | void wxSearchEngine::LookFor(const wxString& keyword) | |
38 | { | |
2776d7c3 VS |
39 | if (m_Keyword) delete[] m_Keyword; |
40 | m_Keyword = new char[keyword.Length() + 1]; | |
5526e819 VS |
41 | strcpy(m_Keyword, keyword.c_str()); |
42 | for (int i = strlen(m_Keyword) - 1; i >= 0; i--) | |
43 | if ((m_Keyword[i] >= 'A') && (m_Keyword[i] <= 'Z')) | |
44 | m_Keyword[i] += 'a' - '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; | |
259d1674 | 54 | int lng = stream ->GetSize(); |
5526e819 VS |
55 | int wrd = strlen(m_Keyword); |
56 | bool found = FALSE; | |
2776d7c3 | 57 | char *buf = new char[lng + 1]; |
5526e819 VS |
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 | ||
2776d7c3 | 70 | delete[] buf; |
5526e819 VS |
71 | return found; |
72 | } | |
73 | ||
74 | #endif |