]>
git.saurik.com Git - wxWidgets.git/blob - src/html/search.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: search engine
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation
15 #include <wx/wxprec.h>
28 #include "wx/html/helpdata.h"
32 //--------------------------------------------------------------------------------
34 //--------------------------------------------------------------------------------
36 void wxSearchEngine::LookFor(const wxString
& keyword
)
38 if (m_Keyword
) delete[] m_Keyword
;
39 m_Keyword
= new char[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';
48 bool wxSearchEngine::Scan(wxInputStream
*stream
)
50 wxASSERT_MSG(m_Keyword
!= NULL
, _("wxSearchEngine::LookFor must be called before scanning!"));
53 int lng
= stream
->GetSize();
54 int wrd
= strlen(m_Keyword
);
56 char *buf
= new char[lng
+ 1];
57 stream
-> Read(buf
, lng
);
60 for (i
= 0; i
< lng
; i
++)
61 if ((buf
[i
] >= 'A') && (buf
[i
] <= 'Z')) buf
[i
] += 'a' - 'A';
63 for (i
= 0; i
< lng
- wrd
; i
++) {
65 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
66 if (j
== wrd
) {found
= TRUE
; break;}