]>
git.saurik.com Git - wxWidgets.git/blob - src/html/search.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     search engine 
   4 // Author:      Vaclav Slavik 
   6 // Copyright:   (c) 1999 Vaclav Slavik 
   7 // Licence:     wxWindows Licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation 
  16 #include "wx/wxprec.h" 
  28 #include "wx/html/helpdata.h" 
  31 //-------------------------------------------------------------------------------- 
  33 //-------------------------------------------------------------------------------- 
  35 void wxSearchEngine::LookFor(const wxString
& keyword
) 
  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'); 
  47 bool wxSearchEngine::Scan(wxInputStream 
*stream
) 
  49     wxASSERT_MSG(m_Keyword 
!= NULL
, _("wxSearchEngine::LookFor must be called before scanning!")); 
  52     int lng 
= stream 
->GetSize(); 
  53     int wrd 
= wxStrlen(m_Keyword
); 
  55     char *buf 
= new char[lng 
+ 1]; 
  56     stream 
-> Read(buf
, lng
); 
  59     for (i 
= 0; i 
< lng
; i
++) 
  60         if ((buf
[i
] >= 'A') && (buf
[i
] <= 'Z')) buf
[i
] += 'a' - 'A'; 
  62     for (i 
= 0; i 
< lng 
- wrd
; i
++) { 
  64         while ((j 
< wrd
) && (buf
[i 
+ j
] == m_Keyword
[j
])) j
++; 
  65         if (j 
== wrd
) {found 
= TRUE
; break;}