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