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"
25 #if wxUSE_HTML && wxUSE_STREAMS
32 #include "wx/html/helpdata.h"
33 #include "wx/tokenzr.h"
34 #include "wx/wfstream.h"
35 #include "wx/busyinfo.h"
36 #include "wx/encconv.h"
37 #include "wx/fontmap.h"
39 #include "wx/html/htmlpars.h"
40 #include "wx/html/htmldefs.h"
41 #include "wx/filename.h"
43 #include "wx/arrimpl.cpp"
44 WX_DEFINE_OBJARRAY(wxHtmlBookRecArray
)
46 //-----------------------------------------------------------------------------
47 // static helper functions
48 //-----------------------------------------------------------------------------
50 // Reads one line, stores it into buf and returns pointer to new line or NULL.
51 static char* ReadLine(char *line
, char *buf
)
53 char *writeptr
= buf
, *readptr
= line
;
55 while (*readptr
!= 0 && *readptr
!= '\r' && *readptr
!= '\n') *(writeptr
++) = *(readptr
++);
57 while (*readptr
== '\r' || *readptr
== '\n') readptr
++;
58 if (*readptr
== 0) return NULL
;
64 static int LINKAGEMODE
IndexCompareFunc(const void *a
, const void *b
)
66 return wxStrcmp(((wxHtmlContentsItem
*)a
)->m_Name
, ((wxHtmlContentsItem
*)b
)->m_Name
);
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
74 class HP_Parser
: public wxHtmlParser
77 void AddText(const char* WXUNUSED(text
)) { }
78 wxObject
* GetProduct() { return NULL
; }
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
86 class HP_TagHandler
: public wxHtmlTagHandler
89 wxString m_Name
, m_Page
;
93 wxHtmlContentsItem
*m_Items
;
95 wxHtmlBookRecord
*m_Book
;
98 HP_TagHandler(wxHtmlBookRecord
*b
) : wxHtmlTagHandler()
99 { m_Book
= b
; m_Items
= NULL
; m_ItemsCnt
= 0; m_Name
= m_Page
= wxEmptyString
;
100 m_Level
= 0; m_ID
= -1; }
101 wxString
GetSupportedTags() { return wxT("UL,OBJECT,PARAM"); }
102 bool HandleTag(const wxHtmlTag
& tag
);
103 void WriteOut(wxHtmlContentsItem
*& array
, int& size
);
104 void ReadIn(wxHtmlContentsItem
* array
, int size
);
108 bool HP_TagHandler::HandleTag(const wxHtmlTag
& tag
)
110 if (tag
.GetName() == wxT("UL"))
117 else if (tag
.GetName() == wxT("OBJECT"))
119 m_Name
= m_Page
= wxEmptyString
;
123 if (!m_Page
.IsEmpty())
124 /* Valid HHW's file may contain only two object tags:
126 <OBJECT type="text/site properties">
127 <param name="ImageType" value="Folder">
132 <OBJECT type="text/sitemap">
133 <param name="Name" value="main page">
134 <param name="Local" value="another.htm">
137 We're interested in the latter. !m_Page.IsEmpty() is valid
138 condition because text/site properties does not contain Local param
141 if (tag
.GetParam(wxT("TYPE")) == wxT("text/sitemap"))
143 if (m_ItemsCnt
% wxHTML_REALLOC_STEP
== 0)
144 m_Items
= (wxHtmlContentsItem
*) realloc(m_Items
,
145 (m_ItemsCnt
+ wxHTML_REALLOC_STEP
) *
146 sizeof(wxHtmlContentsItem
));
148 m_Items
[m_ItemsCnt
].m_Level
= m_Level
;
149 m_Items
[m_ItemsCnt
].m_ID
= m_ID
;
150 m_Items
[m_ItemsCnt
].m_Page
= new wxChar
[m_Page
.Length() + 1];
151 wxStrcpy(m_Items
[m_ItemsCnt
].m_Page
, m_Page
.c_str());
152 m_Items
[m_ItemsCnt
].m_Name
= new wxChar
[m_Name
.Length() + 1];
153 wxStrcpy(m_Items
[m_ItemsCnt
].m_Name
, m_Name
.c_str());
154 m_Items
[m_ItemsCnt
].m_Book
= m_Book
;
162 if (m_Name
== wxEmptyString
&& tag
.GetParam(wxT("NAME")) == wxT("Name"))
163 m_Name
= tag
.GetParam(wxT("VALUE"));
164 if (tag
.GetParam(wxT("NAME")) == wxT("Local"))
165 m_Page
= tag
.GetParam(wxT("VALUE"));
166 if (tag
.GetParam(wxT("NAME")) == wxT("ID"))
167 tag
.GetParamAsInt(wxT("VALUE"), &m_ID
);
174 void HP_TagHandler::WriteOut(wxHtmlContentsItem
*& array
, int& size
)
182 void HP_TagHandler::ReadIn(wxHtmlContentsItem
* array
, int size
)
191 //-----------------------------------------------------------------------------
193 //-----------------------------------------------------------------------------
195 wxString
wxHtmlBookRecord::GetFullPath(const wxString
&page
) const
197 if (wxIsAbsolutePath(page
))
200 return m_BasePath
+ page
;
205 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpData
, wxObject
)
207 wxHtmlHelpData::wxHtmlHelpData()
209 m_TempPath
= wxEmptyString
;
217 wxHtmlHelpData::~wxHtmlHelpData()
221 m_BookRecords
.Empty();
224 for (i
= 0; i
< m_ContentsCnt
; i
++)
226 delete[] m_Contents
[i
].m_Page
;
227 delete[] m_Contents
[i
].m_Name
;
233 for (i
= 0; i
< m_IndexCnt
; i
++)
235 delete[] m_Index
[i
].m_Page
;
236 delete[] m_Index
[i
].m_Name
;
242 bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
, const wxString
& indexfile
, const wxString
& contentsfile
)
250 HP_TagHandler
*handler
= new HP_TagHandler(book
);
251 parser
.AddTagHandler(handler
);
253 f
= ( contentsfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(contentsfile
) );
256 sz
= f
->GetStream()->GetSize();
257 buf
= new char[sz
+ 1];
259 f
->GetStream()->Read(buf
, sz
);
261 handler
->ReadIn(m_Contents
, m_ContentsCnt
);
263 handler
->WriteOut(m_Contents
, m_ContentsCnt
);
267 wxLogError(_("Cannot open contents file: %s"), contentsfile
.c_str());
269 f
= ( indexfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(indexfile
) );
272 sz
= f
->GetStream()->GetSize();
273 buf
= new char[sz
+ 1];
275 f
->GetStream()->Read(buf
, sz
);
277 handler
->ReadIn(m_Index
, m_IndexCnt
);
279 handler
->WriteOut(m_Index
, m_IndexCnt
);
282 else if (!indexfile
.IsEmpty())
283 wxLogError(_("Cannot open index file: %s"), indexfile
.c_str());
292 #define READ_STRING(f, s, lng) { char tmpc; for (int i = 0; i < lng; i++) { f->Read(&tmpc, 1); s[i] = (wxChar)tmpc;} }
293 #define WRITE_STRING(f, s, lng) { char tmpc; for (int i = 0; i < lng; i++) { tmpc = (char)s[i]; f->Write(&tmpc, 1);} }
297 #define READ_STRING(f, s, lng) f->Read(s, lng * sizeof(char));
298 #define WRITE_STRING(f, s, lng) f->Write(s, lng * sizeof(char));
303 #define CURRENT_CACHED_BOOK_VERSION 1
305 bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
)
311 /* load header - version info : */
313 f
->Read(&x
, sizeof(x
));
314 version
= wxINT32_SWAP_ON_BE(x
);
316 if (version
!= CURRENT_CACHED_BOOK_VERSION
)
318 wxLogError(_("Incorrect version of HTML help book"));
320 // NOTE: when adding new version, please ensure backward compatibility!
323 /* load contents : */
325 f
->Read(&x
, sizeof(x
));
327 m_ContentsCnt
+= wxINT32_SWAP_ON_BE(x
);
328 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
,
329 (m_ContentsCnt
/ wxHTML_REALLOC_STEP
+ 1) *
330 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
331 for (i
= st
; i
< m_ContentsCnt
; i
++)
333 f
->Read(&x
, sizeof(x
));
334 m_Contents
[i
].m_Level
= wxINT32_SWAP_ON_BE(x
);
335 f
->Read(&x
, sizeof(x
));
336 m_Contents
[i
].m_ID
= wxINT32_SWAP_ON_BE(x
);
337 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
338 m_Contents
[i
].m_Name
= new wxChar
[x
];
339 READ_STRING(f
, m_Contents
[i
].m_Name
, x
);
340 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
341 m_Contents
[i
].m_Page
= new wxChar
[x
];
342 READ_STRING(f
, m_Contents
[i
].m_Page
, x
);
343 m_Contents
[i
].m_Book
= book
;
348 f
->Read(&x
, sizeof(x
));
350 m_IndexCnt
+= wxINT32_SWAP_ON_BE(x
);
351 m_Index
= (wxHtmlContentsItem
*) realloc(m_Index
, (m_IndexCnt
/ wxHTML_REALLOC_STEP
+ 1) *
352 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
353 for (i
= st
; i
< m_IndexCnt
; i
++)
355 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
356 m_Index
[i
].m_Name
= new wxChar
[x
];
357 READ_STRING(f
, m_Index
[i
].m_Name
, x
);
358 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
359 m_Index
[i
].m_Page
= new wxChar
[x
];
360 READ_STRING(f
, m_Index
[i
].m_Page
, x
);
361 m_Index
[i
].m_Book
= book
;
367 bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
)
372 /* save header - version info : */
374 x
= wxINT32_SWAP_ON_BE(CURRENT_CACHED_BOOK_VERSION
);
375 f
->Write(&x
, sizeof(x
));
377 /* save contents : */
380 for (i
= 0; i
< m_ContentsCnt
; i
++) if (m_Contents
[i
].m_Book
== book
&& m_Contents
[i
].m_Level
> 0) x
++;
381 x
= wxINT32_SWAP_ON_BE(x
);
382 f
->Write(&x
, sizeof(x
));
383 for (i
= 0; i
< m_ContentsCnt
; i
++)
385 if (m_Contents
[i
].m_Book
!= book
|| m_Contents
[i
].m_Level
== 0) continue;
386 x
= wxINT32_SWAP_ON_BE(m_Contents
[i
].m_Level
);
387 f
->Write(&x
, sizeof(x
));
388 x
= wxINT32_SWAP_ON_BE(m_Contents
[i
].m_ID
);
389 f
->Write(&x
, sizeof(x
));
390 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Contents
[i
].m_Name
) + 1);
391 f
->Write(&x
, sizeof(x
));
392 WRITE_STRING(f
, m_Contents
[i
].m_Name
, x
);
393 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Contents
[i
].m_Page
) + 1);
394 f
->Write(&x
, sizeof(x
));
395 WRITE_STRING(f
, m_Contents
[i
].m_Page
, x
);
401 for (i
= 0; i
< m_IndexCnt
; i
++) if (m_Index
[i
].m_Book
== book
&& m_Index
[i
].m_Level
> 0) x
++;
402 x
= wxINT32_SWAP_ON_BE(x
);
403 f
->Write(&x
, sizeof(x
));
404 for (i
= 0; i
< m_IndexCnt
; i
++)
406 if (m_Index
[i
].m_Book
!= book
|| m_Index
[i
].m_Level
== 0) continue;
407 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Index
[i
].m_Name
) + 1);
408 f
->Write(&x
, sizeof(x
));
409 WRITE_STRING(f
, m_Index
[i
].m_Name
, x
);
410 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Index
[i
].m_Page
) + 1);
411 f
->Write(&x
, sizeof(x
));
412 WRITE_STRING(f
, m_Index
[i
].m_Page
, x
);
418 void wxHtmlHelpData::SetTempDir(const wxString
& path
)
420 if (path
== wxEmptyString
) m_TempPath
= path
;
423 if (wxIsAbsolutePath(path
)) m_TempPath
= path
;
424 else m_TempPath
= wxGetCwd() + _T("/") + path
;
426 if (m_TempPath
[m_TempPath
.Length() - 1] != _T('/'))
427 m_TempPath
<< _T('/');
433 static wxString
SafeFileName(const wxString
& s
)
436 res
.Replace(wxT("#"), wxT("_"));
437 res
.Replace(wxT(":"), wxT("_"));
438 res
.Replace(wxT("\\"), wxT("_"));
439 res
.Replace(wxT("/"), wxT("_"));
443 bool wxHtmlHelpData::AddBookParam(const wxFSFile
& bookfile
,
444 wxFontEncoding encoding
,
445 const wxString
& title
, const wxString
& contfile
,
446 const wxString
& indexfile
, const wxString
& deftopic
,
447 const wxString
& path
)
451 wxHtmlBookRecord
*bookr
;
453 int IndexOld
= m_IndexCnt
,
454 ContentsOld
= m_ContentsCnt
;
456 if (! path
.IsEmpty())
457 fsys
.ChangePathTo(path
, TRUE
);
459 bookr
= new wxHtmlBookRecord(fsys
.GetPath(), title
, deftopic
);
461 if (m_ContentsCnt
% wxHTML_REALLOC_STEP
== 0)
462 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
, (m_ContentsCnt
+ wxHTML_REALLOC_STEP
) * sizeof(wxHtmlContentsItem
));
463 m_Contents
[m_ContentsCnt
].m_Level
= 0;
464 m_Contents
[m_ContentsCnt
].m_ID
= 0;
465 m_Contents
[m_ContentsCnt
].m_Page
= new wxChar
[deftopic
.Length() + 1];
466 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Page
, deftopic
.c_str());
467 m_Contents
[m_ContentsCnt
].m_Name
= new wxChar
[title
.Length() + 1];
468 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Name
, title
.c_str());
469 m_Contents
[m_ContentsCnt
].m_Book
= bookr
;
471 // store the contents index for later
472 int cont_start
= m_ContentsCnt
++;
474 // Try to find cached binary versions:
475 // 1. save file as book, but with .hhp.cached extension
476 // 2. same as 1. but in temp path
477 // 3. otherwise or if cache load failed, load it from MS.
479 fi
= fsys
.OpenFile(bookfile
.GetLocation() + wxT(".cached"));
482 fi
->GetModificationTime() < bookfile
.GetModificationTime() ||
483 !LoadCachedBook(bookr
, fi
->GetStream()))
485 if (fi
!= NULL
) delete fi
;
486 fi
= fsys
.OpenFile(m_TempPath
+ wxFileNameFromPath(bookfile
.GetLocation()) + wxT(".cached"));
487 if (m_TempPath
== wxEmptyString
|| fi
== NULL
||
488 fi
->GetModificationTime() < bookfile
.GetModificationTime() ||
489 !LoadCachedBook(bookr
, fi
->GetStream()))
491 LoadMSProject(bookr
, fsys
, indexfile
, contfile
);
492 if (m_TempPath
!= wxEmptyString
)
494 wxFileOutputStream
*outs
= new wxFileOutputStream(m_TempPath
+
495 SafeFileName(wxFileNameFromPath(bookfile
.GetLocation())) + wxT(".cached"));
496 SaveCachedBook(bookr
, outs
);
502 if (fi
!= NULL
) delete fi
;
504 // Now store the contents range
505 bookr
->SetContentsRange(cont_start
, m_ContentsCnt
);
507 // Convert encoding, if neccessary:
508 if (encoding
!= wxFONTENCODING_SYSTEM
)
510 wxFontEncodingArray a
= wxEncodingConverter::GetPlatformEquivalents(encoding
);
511 if (a
.GetCount() != 0 && a
[0] != encoding
)
514 wxEncodingConverter conv
;
515 conv
.Init(encoding
, a
[0]);
517 for (i
= IndexOld
; i
< m_IndexCnt
; i
++)
518 conv
.Convert(m_Index
[i
].m_Name
);
519 for (i
= ContentsOld
; i
< m_ContentsCnt
; i
++)
520 conv
.Convert(m_Contents
[i
].m_Name
);
524 m_BookRecords
.Add(bookr
);
526 qsort(m_Index
, m_IndexCnt
, sizeof(wxHtmlContentsItem
), IndexCompareFunc
);
532 bool wxHtmlHelpData::AddBook(const wxString
& book
)
534 if (book
.Right(4).Lower() == wxT(".zip") ||
535 book
.Right(4).Lower() == wxT(".htb") /*html book*/)
542 s
= fsys
.FindFirst(book
+ wxT("#zip:") + wxT("*.hhp"), wxFILE
);
545 if (AddBook(s
)) rt
= TRUE
;
561 char *buff
, *lineptr
;
564 wxString title
= _("noname"),
566 start
= wxEmptyString
,
567 contents
= wxEmptyString
,
568 index
= wxEmptyString
,
569 charset
= wxEmptyString
;
572 if (wxIsAbsolutePath(book
)) bookFull
= book
;
573 else bookFull
= wxGetCwd() + book
; // no slash or dot
574 wxFileName
fn( bookFull
);
575 bookFull
= fn
.GetFullPath( wxPATH_UNIX
);
577 if (wxIsAbsolutePath(book
)) bookFull
= book
;
578 else bookFull
= wxGetCwd() + "/" + book
;
581 fi
= fsys
.OpenFile(bookFull
);
584 wxLogError(_("Cannot open HTML help book: %s"), bookFull
.c_str());
587 fsys
.ChangePathTo(bookFull
);
590 buff
= new char[sz
+ 1];
596 lineptr
= ReadLine(lineptr
, linebuf
);
598 if (strstr(linebuf
, "Title=") == linebuf
)
599 title
= linebuf
+ strlen("Title=");
600 if (strstr(linebuf
, "Default topic=") == linebuf
)
601 start
= linebuf
+ strlen("Default topic=");
602 if (strstr(linebuf
, "Index file=") == linebuf
)
603 index
= linebuf
+ strlen("Index file=");
604 if (strstr(linebuf
, "Contents file=") == linebuf
)
605 contents
= linebuf
+ strlen("Contents file=");
606 if (strstr(linebuf
, "Charset=") == linebuf
)
607 charset
= linebuf
+ strlen("Charset=");
608 } while (lineptr
!= NULL
);
612 if (charset
== wxEmptyString
) enc
= wxFONTENCODING_SYSTEM
;
613 else enc
= wxTheFontMapper
->CharsetToEncoding(charset
);
614 bool rtval
= AddBookParam(*fi
, enc
,
615 title
, contents
, index
, start
, fsys
.GetPath());
621 wxString
wxHtmlHelpData::FindPageByName(const wxString
& x
)
627 wxString
url(wxEmptyString
);
629 /* 1. try to open given file: */
631 cnt
= m_BookRecords
.GetCount();
632 for (i
= 0; i
< cnt
; i
++)
634 f
= fsys
.OpenFile(m_BookRecords
[i
].GetFullPath(x
));
637 url
= m_BookRecords
[i
].GetFullPath(x
);
644 /* 2. try to find a book: */
646 for (i
= 0; i
< cnt
; i
++)
648 if (m_BookRecords
[i
].GetTitle() == x
)
650 url
= m_BookRecords
[i
].GetFullPath(m_BookRecords
[i
].GetStart());
655 /* 3. try to find in contents: */
658 for (i
= 0; i
< cnt
; i
++)
660 if (wxStrcmp(m_Contents
[i
].m_Name
, x
) == 0)
662 url
= m_Contents
[i
].GetFullPath();
668 /* 4. try to find in index: */
671 for (i
= 0; i
< cnt
; i
++)
673 if (wxStrcmp(m_Index
[i
].m_Name
, x
) == 0)
675 url
= m_Index
[i
].GetFullPath();
683 wxString
wxHtmlHelpData::FindPageById(int id
)
686 wxString
url(wxEmptyString
);
688 for (i
= 0; i
< m_ContentsCnt
; i
++)
690 if (m_Contents
[i
].m_ID
== id
)
692 url
= m_Contents
[i
].GetFullPath();
700 //----------------------------------------------------------------------------------
701 // wxHtmlSearchStatus functions
702 //----------------------------------------------------------------------------------
704 wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData
* data
, const wxString
& keyword
,
705 bool case_sensitive
, bool whole_words_only
,
706 const wxString
& book
)
710 wxHtmlBookRecord
* bookr
= NULL
;
711 if (book
!= wxEmptyString
)
713 // we have to search in a specific book. Find it first
714 int i
, cnt
= data
->m_BookRecords
.GetCount();
715 for (i
= 0; i
< cnt
; i
++)
716 if (data
->m_BookRecords
[i
].GetTitle() == book
)
718 bookr
= &(data
->m_BookRecords
[i
]);
719 m_CurIndex
= bookr
->GetContentsStart();
720 m_MaxIndex
= bookr
->GetContentsEnd();
723 // check; we won't crash if the book doesn't exist, but it's Bad Anyway.
728 // no book specified; search all books
730 m_MaxIndex
= m_Data
->m_ContentsCnt
;
732 m_Engine
.LookFor(keyword
, case_sensitive
, whole_words_only
);
733 m_Active
= (m_CurIndex
< m_MaxIndex
);
737 bool wxHtmlSearchStatus::Search()
740 int i
= m_CurIndex
; // shortcut
746 // sanity check. Illegal use, but we'll try to prevent a crash anyway
751 m_Name
= wxEmptyString
;
752 m_ContentsItem
= NULL
;
753 thepage
= m_Data
->m_Contents
[i
].m_Page
;
755 m_Active
= (++m_CurIndex
< m_MaxIndex
);
756 // check if it is same page with different anchor:
757 if (m_LastPage
!= NULL
)
760 for (p1
= thepage
, p2
= m_LastPage
;
761 *p1
!= 0 && *p1
!= _T('#') && *p1
== *p2
; p1
++, p2
++) {}
763 m_LastPage
= thepage
;
765 if (*p1
== 0 || *p1
== _T('#'))
768 else m_LastPage
= thepage
;
771 file
= fsys
.OpenFile(m_Data
->m_Contents
[i
].m_Book
->GetFullPath(thepage
));
774 if (m_Engine
.Scan(file
->GetStream()))
776 m_Name
= m_Data
->m_Contents
[i
].m_Name
;
777 m_ContentsItem
= m_Data
->m_Contents
+ i
;
792 //--------------------------------------------------------------------------------
794 //--------------------------------------------------------------------------------
796 void wxSearchEngine::LookFor(const wxString
& keyword
, bool case_sensitive
, bool whole_words_only
)
798 m_CaseSensitive
= case_sensitive
;
799 m_WholeWords
= whole_words_only
;
800 if (m_Keyword
) delete[] m_Keyword
;
801 m_Keyword
= new wxChar
[keyword
.Length() + 1];
802 wxStrcpy(m_Keyword
, keyword
.c_str());
804 if (!m_CaseSensitive
)
806 for (int i
= wxStrlen(m_Keyword
) - 1; i
>= 0; i
--)
808 if ((m_Keyword
[i
] >= wxT('A')) && (m_Keyword
[i
] <= wxT('Z')))
809 m_Keyword
[i
] += wxT('a') - wxT('A');
816 #define WHITESPACE(c) (c == ' ' || c == '\n' || c == '\r' || c == '\t')
818 bool wxSearchEngine::Scan(wxInputStream
*stream
)
820 wxASSERT_MSG(m_Keyword
!= NULL
, wxT("wxSearchEngine::LookFor must be called before scanning!"));
823 int lng
= stream
->GetSize();
824 int wrd
= wxStrlen(m_Keyword
);
826 char *buf
= new char[lng
+ 1];
827 stream
->Read(buf
, lng
);
830 if (!m_CaseSensitive
)
831 for (i
= 0; i
< lng
; i
++)
832 if ((buf
[i
] >= 'A') && (buf
[i
] <= 'Z')) buf
[i
] += 'a' - 'A';
836 for (i
= 0; i
< lng
- wrd
; i
++)
838 if (WHITESPACE(buf
[i
])) continue;
840 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
841 if (j
== wrd
&& WHITESPACE(buf
[i
+ j
])) { found
= TRUE
; break; }
847 for (i
= 0; i
< lng
- wrd
; i
++)
850 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
851 if (j
== wrd
) { found
= TRUE
; break; }