1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlHelpData
4 // Notes: Based on htmlhelp.cpp, implementing a monolithic
5 // HTML Help controller class, by Vaclav Slavik
6 // Author: Harm van der Heijden and Vaclav Slavik
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
31 #include "wx/html/helpdata.h"
32 #include "wx/tokenzr.h"
33 #include "wx/wfstream.h"
34 #include "wx/busyinfo.h"
35 #include "wx/encconv.h"
36 #include "wx/fontmap.h"
38 #include "wx/html/htmlpars.h"
39 #include "wx/html/htmldefs.h"
41 #include "wx/arrimpl.cpp"
42 WX_DEFINE_OBJARRAY(wxHtmlBookRecArray
)
44 //-----------------------------------------------------------------------------
45 // static helper functions
46 //-----------------------------------------------------------------------------
48 // Reads one line, stores it into buf and returns pointer to new line or NULL.
49 static char* ReadLine(char *line
, char *buf
)
51 char *writeptr
= buf
, *readptr
= line
;
53 while (*readptr
!= 0 && *readptr
!= '\r' && *readptr
!= '\n') *(writeptr
++) = *(readptr
++);
55 while (*readptr
== '\r' || *readptr
== '\n') readptr
++;
56 if (*readptr
== 0) return NULL
;
62 static int LINKAGEMODE
IndexCompareFunc(const void *a
, const void *b
)
64 return wxStrcmp(((wxHtmlContentsItem
*)a
) -> m_Name
, ((wxHtmlContentsItem
*)b
) -> m_Name
);
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
72 class HP_Parser
: public wxHtmlParser
75 void AddText(const char* WXUNUSED(text
)) { }
76 wxObject
* GetProduct() { return NULL
; }
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
84 class HP_TagHandler
: public wxHtmlTagHandler
87 wxString m_Name
, m_Page
;
91 wxHtmlContentsItem
*m_Items
;
93 wxHtmlBookRecord
*m_Book
;
96 HP_TagHandler(wxHtmlBookRecord
*b
) : wxHtmlTagHandler() {m_Book
= b
; m_Items
= NULL
; m_ItemsCnt
= 0; m_Name
= m_Page
= wxEmptyString
; m_Level
= 0; m_ID
= -1; }
97 wxString
GetSupportedTags() { return wxT("UL,OBJECT,PARAM"); }
98 bool HandleTag(const wxHtmlTag
& tag
);
99 void WriteOut(wxHtmlContentsItem
*& array
, int& size
);
100 void ReadIn(wxHtmlContentsItem
* array
, int size
);
104 bool HP_TagHandler::HandleTag(const wxHtmlTag
& tag
)
106 if (tag
.GetName() == wxT("UL")) {
112 else if (tag
.GetName() == wxT("OBJECT")) {
113 m_Name
= m_Page
= wxEmptyString
;
116 if (!m_Page
.IsEmpty())
117 /* should be 'if (tag.GetParam("TYPE") == "text/sitemap")'
118 but this works fine. Valid HHW's file may contain only two
121 <OBJECT type="text/site properties">
122 <param name="ImageType" value="Folder">
127 <OBJECT type="text/sitemap">
128 <param name="Name" value="main page">
129 <param name="Local" value="another.htm">
132 We're interested in the latter. !m_Page.IsEmpty() is valid
133 condition because text/site properties does not contain Local param
136 if (m_ItemsCnt
% wxHTML_REALLOC_STEP
== 0)
137 m_Items
= (wxHtmlContentsItem
*) realloc(m_Items
, (m_ItemsCnt
+ wxHTML_REALLOC_STEP
) * sizeof(wxHtmlContentsItem
));
138 m_Items
[m_ItemsCnt
].m_Level
= m_Level
;
139 m_Items
[m_ItemsCnt
].m_ID
= m_ID
;
140 m_Items
[m_ItemsCnt
].m_Page
= new wxChar
[m_Page
.Length() + 1];
141 wxStrcpy(m_Items
[m_ItemsCnt
].m_Page
, m_Page
.c_str());
142 m_Items
[m_ItemsCnt
].m_Name
= new wxChar
[m_Name
.Length() + 1];
143 wxStrcpy(m_Items
[m_ItemsCnt
].m_Name
, m_Name
.c_str());
144 m_Items
[m_ItemsCnt
].m_Book
= m_Book
;
151 if (m_Name
== wxEmptyString
&& tag
.GetParam(wxT("NAME")) == wxT("Name")) m_Name
= tag
.GetParam(wxT("VALUE"));
152 if (tag
.GetParam(wxT("NAME")) == wxT("Local")) m_Page
= tag
.GetParam(wxT("VALUE"));
153 if (tag
.GetParam(wxT("NAME")) == wxT("ID")) tag
.ScanParam(wxT("VALUE"), wxT("%i"), &m_ID
);
160 void HP_TagHandler::WriteOut(wxHtmlContentsItem
*& array
, int& size
)
168 void HP_TagHandler::ReadIn(wxHtmlContentsItem
* array
, int size
)
177 //-----------------------------------------------------------------------------
179 //-----------------------------------------------------------------------------
181 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpData
, wxObject
)
183 wxHtmlHelpData::wxHtmlHelpData()
185 m_TempPath
= wxEmptyString
;
193 wxHtmlHelpData::~wxHtmlHelpData()
197 m_BookRecords
.Empty();
199 for (i
= 0; i
< m_ContentsCnt
; i
++) {
200 delete[] m_Contents
[i
].m_Page
;
201 delete[] m_Contents
[i
].m_Name
;
206 for (i
= 0; i
< m_IndexCnt
; i
++) {
207 delete[] m_Index
[i
].m_Page
;
208 delete[] m_Index
[i
].m_Name
;
214 bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
, const wxString
& indexfile
, const wxString
& contentsfile
)
222 HP_TagHandler
*handler
= new HP_TagHandler(book
);
223 parser
.AddTagHandler(handler
);
225 f
= ( contentsfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(contentsfile
) );
227 sz
= f
-> GetStream() -> GetSize();
228 buf
= new char[sz
+ 1];
230 f
-> GetStream() -> Read(buf
, sz
);
232 handler
-> ReadIn(m_Contents
, m_ContentsCnt
);
234 handler
-> WriteOut(m_Contents
, m_ContentsCnt
);
238 wxLogError(_("Cannot open contents file: %s"), contentsfile
.mb_str());
240 f
= ( indexfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(indexfile
) );
242 sz
= f
-> GetStream() -> GetSize();
243 buf
= new char[sz
+ 1];
245 f
-> GetStream() -> Read(buf
, sz
);
247 handler
-> ReadIn(m_Index
, m_IndexCnt
);
249 handler
-> WriteOut(m_Index
, m_IndexCnt
);
252 else if (!indexfile
.IsEmpty())
253 wxLogError(_("Cannot open index file: %s"), indexfile
.mb_str());
262 #define READ_STRING(f, s, lng) { char tmpc; for (int i = 0; i < lng; i++) { f -> Read(&tmpc, 1); s[i] = (wxChar)tmpc;} }
263 #define WRITE_STRING(f, s, lng) { char tmpc; for (int i = 0; i < lng; i++) { tmpc = (char)s[i]; f -> Write(&tmpc, 1);} }
267 #define READ_STRING(f, s, lng) f -> Read(s, lng * sizeof(char));
268 #define WRITE_STRING(f, s, lng) f -> Write(s, lng * sizeof(char));
273 #define CURRENT_CACHED_BOOK_VERSION 1
275 bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
)
281 /* load header - version info : */
283 f
-> Read(&x
, sizeof(x
));
284 version
= wxINT32_SWAP_ON_BE(x
);
286 if (version
!= CURRENT_CACHED_BOOK_VERSION
)
288 wxLogError(_("Incorrect version of HTML help book"));
290 // NOTE: when adding new version, please ensure backward compatibility!
293 /* load contents : */
295 f
-> Read(&x
, sizeof(x
));
297 m_ContentsCnt
+= wxINT32_SWAP_ON_BE(x
);
298 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
,
299 (m_ContentsCnt
/ wxHTML_REALLOC_STEP
+ 1) *
300 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
301 for (i
= st
; i
< m_ContentsCnt
; i
++) {
302 f
-> Read(&x
, sizeof(x
));
303 m_Contents
[i
].m_Level
= wxINT32_SWAP_ON_BE(x
);
304 f
-> Read(&x
, sizeof(x
));
305 m_Contents
[i
].m_ID
= wxINT32_SWAP_ON_BE(x
);
306 f
-> Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
307 m_Contents
[i
].m_Name
= new wxChar
[x
];
308 READ_STRING(f
, m_Contents
[i
].m_Name
, x
);
309 f
-> Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
310 m_Contents
[i
].m_Page
= new wxChar
[x
];
311 READ_STRING(f
, m_Contents
[i
].m_Page
, x
);
312 m_Contents
[i
].m_Book
= book
;
317 f
-> Read(&x
, sizeof(x
));
319 m_IndexCnt
+= wxINT32_SWAP_ON_BE(x
);
320 m_Index
= (wxHtmlContentsItem
*) realloc(m_Index
, (m_IndexCnt
/ wxHTML_REALLOC_STEP
+ 1) *
321 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
322 for (i
= st
; i
< m_IndexCnt
; i
++) {
323 f
-> Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
324 m_Index
[i
].m_Name
= new wxChar
[x
];
325 READ_STRING(f
, m_Index
[i
].m_Name
, x
);
326 f
-> Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
327 m_Index
[i
].m_Page
= new wxChar
[x
];
328 READ_STRING(f
, m_Index
[i
].m_Page
, x
);
329 m_Index
[i
].m_Book
= book
;
335 bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
)
340 /* save header - version info : */
342 x
= wxINT32_SWAP_ON_BE(CURRENT_CACHED_BOOK_VERSION
);
343 f
-> Write(&x
, sizeof(x
));
345 /* save contents : */
348 for (i
= 0; i
< m_ContentsCnt
; i
++) if (m_Contents
[i
].m_Book
== book
&& m_Contents
[i
].m_Level
> 0) x
++;
349 x
= wxINT32_SWAP_ON_BE(x
);
350 f
-> Write(&x
, sizeof(x
));
351 for (i
= 0; i
< m_ContentsCnt
; i
++) {
352 if (m_Contents
[i
].m_Book
!= book
|| m_Contents
[i
].m_Level
== 0) continue;
353 x
= wxINT32_SWAP_ON_BE(m_Contents
[i
].m_Level
);
354 f
-> Write(&x
, sizeof(x
));
355 x
= wxINT32_SWAP_ON_BE(m_Contents
[i
].m_ID
);
356 f
-> Write(&x
, sizeof(x
));
357 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Contents
[i
].m_Name
) + 1);
358 f
-> Write(&x
, sizeof(x
));
359 WRITE_STRING(f
, m_Contents
[i
].m_Name
, x
);
360 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Contents
[i
].m_Page
) + 1);
361 f
-> Write(&x
, sizeof(x
));
362 WRITE_STRING(f
, m_Contents
[i
].m_Page
, x
);
368 for (i
= 0; i
< m_IndexCnt
; i
++) if (m_Index
[i
].m_Book
== book
&& m_Index
[i
].m_Level
> 0) x
++;
369 x
= wxINT32_SWAP_ON_BE(x
);
370 f
-> Write(&x
, sizeof(x
));
371 for (i
= 0; i
< m_IndexCnt
; i
++) {
372 if (m_Index
[i
].m_Book
!= book
|| m_Index
[i
].m_Level
== 0) continue;
373 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Index
[i
].m_Name
) + 1);
374 f
-> Write(&x
, sizeof(x
));
375 WRITE_STRING(f
, m_Index
[i
].m_Name
, x
);
376 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Index
[i
].m_Page
) + 1);
377 f
-> Write(&x
, sizeof(x
));
378 WRITE_STRING(f
, m_Index
[i
].m_Page
, x
);
384 void wxHtmlHelpData::SetTempDir(const wxString
& path
)
386 if (path
== wxEmptyString
) m_TempPath
= path
;
388 if (wxIsAbsolutePath(path
)) m_TempPath
= path
;
389 else m_TempPath
= wxGetCwd() + _T("/") + path
;
391 if (m_TempPath
[m_TempPath
.Length() - 1] != _T('/'))
392 m_TempPath
<< _T('/');
398 static wxString
SafeFileName(const wxString
& s
)
401 res
.Replace(wxT("#"), wxT("_"));
402 res
.Replace(wxT(":"), wxT("_"));
403 res
.Replace(wxT("\\"), wxT("_"));
404 res
.Replace(wxT("/"), wxT("_"));
408 bool wxHtmlHelpData::AddBookParam(const wxFSFile
& bookfile
,
409 wxFontEncoding encoding
,
410 const wxString
& title
, const wxString
& contfile
,
411 const wxString
& indexfile
, const wxString
& deftopic
,
412 const wxString
& path
)
416 wxHtmlBookRecord
*bookr
;
418 int IndexOld
= m_IndexCnt
,
419 ContentsOld
= m_ContentsCnt
;
421 if (! path
.IsEmpty())
422 fsys
.ChangePathTo(path
, TRUE
);
424 bookr
= new wxHtmlBookRecord(fsys
.GetPath(), title
, deftopic
);
426 if (m_ContentsCnt
% wxHTML_REALLOC_STEP
== 0)
427 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
, (m_ContentsCnt
+ wxHTML_REALLOC_STEP
) * sizeof(wxHtmlContentsItem
));
428 m_Contents
[m_ContentsCnt
].m_Level
= 0;
429 m_Contents
[m_ContentsCnt
].m_ID
= 0;
430 m_Contents
[m_ContentsCnt
].m_Page
= new wxChar
[deftopic
.Length() + 1];
431 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Page
, deftopic
.c_str());
432 m_Contents
[m_ContentsCnt
].m_Name
= new wxChar
[title
.Length() + 1];
433 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Name
, title
.c_str());
434 m_Contents
[m_ContentsCnt
].m_Book
= bookr
;
436 // store the contents index for later
437 int cont_start
= m_ContentsCnt
++;
439 // Try to find cached binary versions:
440 // 1. save file as book, but with .hhp.cached extension
441 // 2. same as 1. but in temp path
442 // 3. otherwise or if cache load failed, load it from MS.
444 fi
= fsys
.OpenFile(bookfile
.GetLocation() + wxT(".cached"));
447 fi
-> GetModificationTime() < bookfile
.GetModificationTime() ||
448 !LoadCachedBook(bookr
, fi
-> GetStream()))
450 if (fi
!= NULL
) delete fi
;
451 fi
= fsys
.OpenFile(m_TempPath
+ wxFileNameFromPath(bookfile
.GetLocation()) + wxT(".cached"));
452 if (m_TempPath
== wxEmptyString
|| fi
== NULL
||
453 fi
-> GetModificationTime() < bookfile
.GetModificationTime() ||
454 !LoadCachedBook(bookr
, fi
-> GetStream()))
456 LoadMSProject(bookr
, fsys
, indexfile
, contfile
);
457 if (m_TempPath
!= wxEmptyString
)
459 wxFileOutputStream
*outs
= new wxFileOutputStream(m_TempPath
+
460 SafeFileName(wxFileNameFromPath(bookfile
.GetLocation())) + wxT(".cached"));
461 SaveCachedBook(bookr
, outs
);
467 if (fi
!= NULL
) delete fi
;
469 // Now store the contents range
470 bookr
->SetContentsRange(cont_start
, m_ContentsCnt
);
472 // Convert encoding, if neccessary:
473 if (encoding
!= wxFONTENCODING_SYSTEM
)
475 wxFontEncodingArray a
= wxEncodingConverter::GetPlatformEquivalents(encoding
);
476 if (a
.GetCount() != 0 && a
[0] != encoding
)
479 wxEncodingConverter conv
;
480 conv
.Init(encoding
, a
[0]);
482 for (i
= IndexOld
; i
< m_IndexCnt
; i
++)
483 conv
.Convert(m_Index
[i
].m_Name
);
484 for (i
= ContentsOld
; i
< m_ContentsCnt
; i
++)
485 conv
.Convert(m_Contents
[i
].m_Name
);
489 m_BookRecords
.Add(bookr
);
491 qsort(m_Index
, m_IndexCnt
, sizeof(wxHtmlContentsItem
), IndexCompareFunc
);
497 bool wxHtmlHelpData::AddBook(const wxString
& book
)
499 if (book
.Right(4).Lower() == wxT(".zip") ||
500 book
.Right(4).Lower() == wxT(".htb") /*html book*/)
507 s
= fsys
.FindFirst(book
+ wxT("#zip:") + wxT("*.hhp"), wxFILE
);
510 if (AddBook(s
)) rt
= TRUE
;
526 char *buff
, *lineptr
;
529 wxString title
= _("noname"),
531 start
= wxEmptyString
,
532 contents
= wxEmptyString
,
533 index
= wxEmptyString
,
534 charset
= wxEmptyString
;
536 if (wxIsAbsolutePath(book
)) bookFull
= book
;
537 else bookFull
= wxGetCwd() + "/" + book
;
539 fi
= fsys
.OpenFile(bookFull
);
542 wxLogError(_("Cannot open HTML help book: %s"), bookFull
.mb_str());
545 fsys
.ChangePathTo(bookFull
);
546 s
= fi
-> GetStream();
548 buff
= new char[sz
+ 1];
554 lineptr
= ReadLine(lineptr
, linebuf
);
556 if (strstr(linebuf
, "Title=") == linebuf
)
557 title
= linebuf
+ strlen("Title=");
558 if (strstr(linebuf
, "Default topic=") == linebuf
)
559 start
= linebuf
+ strlen("Default topic=");
560 if (strstr(linebuf
, "Index file=") == linebuf
)
561 index
= linebuf
+ strlen("Index file=");
562 if (strstr(linebuf
, "Contents file=") == linebuf
)
563 contents
= linebuf
+ strlen("Contents file=");
564 if (strstr(linebuf
, "Charset=") == linebuf
)
565 charset
= linebuf
+ strlen("Charset=");
566 } while (lineptr
!= NULL
);
570 if (charset
== wxEmptyString
) enc
= wxFONTENCODING_SYSTEM
;
571 else enc
= wxTheFontMapper
-> CharsetToEncoding(charset
);
572 bool rtval
= AddBookParam(*fi
, enc
,
573 title
, contents
, index
, start
, fsys
.GetPath());
579 wxString
wxHtmlHelpData::FindPageByName(const wxString
& x
)
585 wxString
url(wxEmptyString
);
587 /* 1. try to open given file: */
589 cnt
= m_BookRecords
.GetCount();
590 for (i
= 0; i
< cnt
; i
++) {
591 f
= fsys
.OpenFile(m_BookRecords
[i
].GetBasePath() + x
);
593 url
= m_BookRecords
[i
].GetBasePath() + x
;
600 /* 2. try to find a book: */
602 for (i
= 0; i
< cnt
; i
++) {
603 if (m_BookRecords
[i
].GetTitle() == x
) {
604 url
= m_BookRecords
[i
].GetBasePath() + m_BookRecords
[i
].GetStart();
609 /* 3. try to find in contents: */
612 for (i
= 0; i
< cnt
; i
++) {
613 if (wxStrcmp(m_Contents
[i
].m_Name
, x
) == 0) {
614 url
= m_Contents
[i
].m_Book
-> GetBasePath() + m_Contents
[i
].m_Page
;
620 /* 4. try to find in index: */
623 for (i
= 0; i
< cnt
; i
++) {
624 if (wxStrcmp(m_Index
[i
].m_Name
, x
) == 0) {
625 url
= m_Index
[i
].m_Book
-> GetBasePath() + m_Index
[i
].m_Page
;
633 wxString
wxHtmlHelpData::FindPageById(int id
)
636 wxString
url(wxEmptyString
);
638 for (i
= 0; i
< m_ContentsCnt
; i
++) {
639 if (m_Contents
[i
].m_ID
== id
) {
640 url
= m_Contents
[i
].m_Book
-> GetBasePath() + m_Contents
[i
].m_Page
;
648 //----------------------------------------------------------------------------------
649 // wxHtmlSearchStatus functions
650 //----------------------------------------------------------------------------------
652 wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData
* data
, const wxString
& keyword
,
653 bool case_sensitive
, bool whole_words_only
,
654 const wxString
& book
)
658 wxHtmlBookRecord
* bookr
= NULL
;
659 if (book
!= wxEmptyString
) {
660 // we have to search in a specific book. Find it first
661 int i
, cnt
= data
->m_BookRecords
.GetCount();
662 for (i
= 0; i
< cnt
; i
++)
663 if (data
->m_BookRecords
[i
].GetTitle() == book
) {
664 bookr
= &(data
->m_BookRecords
[i
]);
665 m_CurIndex
= bookr
->GetContentsStart();
666 m_MaxIndex
= bookr
->GetContentsEnd();
669 // check; we won't crash if the book doesn't exist, but it's Bad Anyway.
673 // no book specified; search all books
675 m_MaxIndex
= m_Data
->m_ContentsCnt
;
677 m_Engine
.LookFor(keyword
, case_sensitive
, whole_words_only
);
678 m_Active
= (m_CurIndex
< m_MaxIndex
);
682 bool wxHtmlSearchStatus::Search()
685 int i
= m_CurIndex
; // shortcut
690 // sanity check. Illegal use, but we'll try to prevent a crash anyway
695 m_Name
= wxEmptyString
;
696 m_ContentsItem
= NULL
;
697 thepage
= m_Data
->m_Contents
[i
].m_Page
;
699 m_Active
= (++m_CurIndex
< m_MaxIndex
);
700 // check if it is same page with different anchor:
701 if (m_LastPage
!= NULL
)
704 for (p1
= thepage
, p2
= m_LastPage
;
705 *p1
!= 0 && *p1
!= _T('#') && *p1
== *p2
; p1
++, p2
++) {}
707 m_LastPage
= thepage
;
709 if (*p1
== 0 || *p1
== _T('#'))
712 else m_LastPage
= thepage
;
715 file
= fsys
.OpenFile(m_Data
->m_Contents
[i
].m_Book
-> GetBasePath() + thepage
);
718 if (m_Engine
.Scan(file
-> GetStream())) {
719 m_Name
= m_Data
->m_Contents
[i
].m_Name
;
720 m_ContentsItem
= m_Data
->m_Contents
+ i
;
735 //--------------------------------------------------------------------------------
737 //--------------------------------------------------------------------------------
739 void wxSearchEngine::LookFor(const wxString
& keyword
, bool case_sensitive
, bool whole_words_only
)
741 m_CaseSensitive
= case_sensitive
;
742 m_WholeWords
= whole_words_only
;
743 if (m_Keyword
) delete[] m_Keyword
;
744 m_Keyword
= new wxChar
[keyword
.Length() + 1];
745 wxStrcpy(m_Keyword
, keyword
.c_str());
747 if (!m_CaseSensitive
)
748 for (int i
= wxStrlen(m_Keyword
) - 1; i
>= 0; i
--)
749 if ((m_Keyword
[i
] >= wxT('A')) && (m_Keyword
[i
] <= wxT('Z')))
750 m_Keyword
[i
] += wxT('a') - wxT('A');
755 #define WHITESPACE(c) (c == ' ' || c == '\n' || c == '\r' || c == '\t')
757 bool wxSearchEngine::Scan(wxInputStream
*stream
)
759 wxASSERT_MSG(m_Keyword
!= NULL
, wxT("wxSearchEngine::LookFor must be called before scanning!"));
762 int lng
= stream
->GetSize();
763 int wrd
= wxStrlen(m_Keyword
);
765 char *buf
= new char[lng
+ 1];
766 stream
-> Read(buf
, lng
);
769 if (!m_CaseSensitive
)
770 for (i
= 0; i
< lng
; i
++)
771 if ((buf
[i
] >= 'A') && (buf
[i
] <= 'Z')) buf
[i
] += 'a' - 'A';
775 for (i
= 0; i
< lng
- wrd
; i
++) {
776 if (WHITESPACE(buf
[i
])) continue;
778 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
779 if (j
== wrd
&& WHITESPACE(buf
[i
+ j
])) {found
= TRUE
; break; }
785 for (i
= 0; i
< lng
- wrd
; i
++) {
787 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
788 if (j
== wrd
) {found
= TRUE
; break; }