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
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()
97 { m_Book
= b
; m_Items
= NULL
; m_ItemsCnt
= 0; m_Name
= m_Page
= wxEmptyString
;
98 m_Level
= 0; m_ID
= -1; }
99 wxString
GetSupportedTags() { return wxT("UL,OBJECT,PARAM"); }
100 bool HandleTag(const wxHtmlTag
& tag
);
101 void WriteOut(wxHtmlContentsItem
*& array
, int& size
);
102 void ReadIn(wxHtmlContentsItem
* array
, int size
);
106 bool HP_TagHandler::HandleTag(const wxHtmlTag
& tag
)
108 if (tag
.GetName() == wxT("UL"))
115 else if (tag
.GetName() == wxT("OBJECT"))
117 m_Name
= m_Page
= wxEmptyString
;
121 if (!m_Page
.IsEmpty())
122 /* Valid HHW's file may contain only two object tags:
124 <OBJECT type="text/site properties">
125 <param name="ImageType" value="Folder">
130 <OBJECT type="text/sitemap">
131 <param name="Name" value="main page">
132 <param name="Local" value="another.htm">
135 We're interested in the latter. !m_Page.IsEmpty() is valid
136 condition because text/site properties does not contain Local param
139 if (tag
.GetParam(wxT("TYPE")) == wxT("text/sitemap"))
141 if (m_ItemsCnt
% wxHTML_REALLOC_STEP
== 0)
142 m_Items
= (wxHtmlContentsItem
*) realloc(m_Items
,
143 (m_ItemsCnt
+ wxHTML_REALLOC_STEP
) *
144 sizeof(wxHtmlContentsItem
));
146 m_Items
[m_ItemsCnt
].m_Level
= m_Level
;
147 m_Items
[m_ItemsCnt
].m_ID
= m_ID
;
148 m_Items
[m_ItemsCnt
].m_Page
= new wxChar
[m_Page
.Length() + 1];
149 wxStrcpy(m_Items
[m_ItemsCnt
].m_Page
, m_Page
.c_str());
150 m_Items
[m_ItemsCnt
].m_Name
= new wxChar
[m_Name
.Length() + 1];
151 wxStrcpy(m_Items
[m_ItemsCnt
].m_Name
, m_Name
.c_str());
152 m_Items
[m_ItemsCnt
].m_Book
= m_Book
;
160 if (m_Name
== wxEmptyString
&& tag
.GetParam(wxT("NAME")) == wxT("Name"))
161 m_Name
= tag
.GetParam(wxT("VALUE"));
162 if (tag
.GetParam(wxT("NAME")) == wxT("Local"))
163 m_Page
= tag
.GetParam(wxT("VALUE"));
164 if (tag
.GetParam(wxT("NAME")) == wxT("ID"))
165 tag
.ScanParam(wxT("VALUE"), wxT("%i"), &m_ID
);
172 void HP_TagHandler::WriteOut(wxHtmlContentsItem
*& array
, int& size
)
180 void HP_TagHandler::ReadIn(wxHtmlContentsItem
* array
, int size
)
189 //-----------------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
193 wxString
wxHtmlBookRecord::GetFullPath(const wxString
&page
) const
195 if (wxIsAbsolutePath(page
))
198 return m_BasePath
+ page
;
203 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpData
, wxObject
)
205 wxHtmlHelpData::wxHtmlHelpData()
207 m_TempPath
= wxEmptyString
;
215 wxHtmlHelpData::~wxHtmlHelpData()
219 m_BookRecords
.Empty();
222 for (i
= 0; i
< m_ContentsCnt
; i
++)
224 delete[] m_Contents
[i
].m_Page
;
225 delete[] m_Contents
[i
].m_Name
;
231 for (i
= 0; i
< m_IndexCnt
; i
++)
233 delete[] m_Index
[i
].m_Page
;
234 delete[] m_Index
[i
].m_Name
;
240 bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
, const wxString
& indexfile
, const wxString
& contentsfile
)
248 HP_TagHandler
*handler
= new HP_TagHandler(book
);
249 parser
.AddTagHandler(handler
);
251 f
= ( contentsfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(contentsfile
) );
254 sz
= f
->GetStream()->GetSize();
255 buf
= new char[sz
+ 1];
257 f
->GetStream()->Read(buf
, sz
);
259 handler
->ReadIn(m_Contents
, m_ContentsCnt
);
261 handler
->WriteOut(m_Contents
, m_ContentsCnt
);
265 wxLogError(_("Cannot open contents file: %s"), contentsfile
.c_str());
267 f
= ( indexfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(indexfile
) );
270 sz
= f
->GetStream()->GetSize();
271 buf
= new char[sz
+ 1];
273 f
->GetStream()->Read(buf
, sz
);
275 handler
->ReadIn(m_Index
, m_IndexCnt
);
277 handler
->WriteOut(m_Index
, m_IndexCnt
);
280 else if (!indexfile
.IsEmpty())
281 wxLogError(_("Cannot open index file: %s"), indexfile
.c_str());
290 #define READ_STRING(f, s, lng) { char tmpc; for (int i = 0; i < lng; i++) { f->Read(&tmpc, 1); s[i] = (wxChar)tmpc;} }
291 #define WRITE_STRING(f, s, lng) { char tmpc; for (int i = 0; i < lng; i++) { tmpc = (char)s[i]; f->Write(&tmpc, 1);} }
295 #define READ_STRING(f, s, lng) f->Read(s, lng * sizeof(char));
296 #define WRITE_STRING(f, s, lng) f->Write(s, lng * sizeof(char));
301 #define CURRENT_CACHED_BOOK_VERSION 1
303 bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
)
309 /* load header - version info : */
311 f
->Read(&x
, sizeof(x
));
312 version
= wxINT32_SWAP_ON_BE(x
);
314 if (version
!= CURRENT_CACHED_BOOK_VERSION
)
316 wxLogError(_("Incorrect version of HTML help book"));
318 // NOTE: when adding new version, please ensure backward compatibility!
321 /* load contents : */
323 f
->Read(&x
, sizeof(x
));
325 m_ContentsCnt
+= wxINT32_SWAP_ON_BE(x
);
326 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
,
327 (m_ContentsCnt
/ wxHTML_REALLOC_STEP
+ 1) *
328 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
329 for (i
= st
; i
< m_ContentsCnt
; i
++)
331 f
->Read(&x
, sizeof(x
));
332 m_Contents
[i
].m_Level
= wxINT32_SWAP_ON_BE(x
);
333 f
->Read(&x
, sizeof(x
));
334 m_Contents
[i
].m_ID
= wxINT32_SWAP_ON_BE(x
);
335 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
336 m_Contents
[i
].m_Name
= new wxChar
[x
];
337 READ_STRING(f
, m_Contents
[i
].m_Name
, x
);
338 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
339 m_Contents
[i
].m_Page
= new wxChar
[x
];
340 READ_STRING(f
, m_Contents
[i
].m_Page
, x
);
341 m_Contents
[i
].m_Book
= book
;
346 f
->Read(&x
, sizeof(x
));
348 m_IndexCnt
+= wxINT32_SWAP_ON_BE(x
);
349 m_Index
= (wxHtmlContentsItem
*) realloc(m_Index
, (m_IndexCnt
/ wxHTML_REALLOC_STEP
+ 1) *
350 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
351 for (i
= st
; i
< m_IndexCnt
; i
++)
353 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
354 m_Index
[i
].m_Name
= new wxChar
[x
];
355 READ_STRING(f
, m_Index
[i
].m_Name
, x
);
356 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
357 m_Index
[i
].m_Page
= new wxChar
[x
];
358 READ_STRING(f
, m_Index
[i
].m_Page
, x
);
359 m_Index
[i
].m_Book
= book
;
365 bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
)
370 /* save header - version info : */
372 x
= wxINT32_SWAP_ON_BE(CURRENT_CACHED_BOOK_VERSION
);
373 f
->Write(&x
, sizeof(x
));
375 /* save contents : */
378 for (i
= 0; i
< m_ContentsCnt
; i
++) if (m_Contents
[i
].m_Book
== book
&& m_Contents
[i
].m_Level
> 0) x
++;
379 x
= wxINT32_SWAP_ON_BE(x
);
380 f
->Write(&x
, sizeof(x
));
381 for (i
= 0; i
< m_ContentsCnt
; i
++)
383 if (m_Contents
[i
].m_Book
!= book
|| m_Contents
[i
].m_Level
== 0) continue;
384 x
= wxINT32_SWAP_ON_BE(m_Contents
[i
].m_Level
);
385 f
->Write(&x
, sizeof(x
));
386 x
= wxINT32_SWAP_ON_BE(m_Contents
[i
].m_ID
);
387 f
->Write(&x
, sizeof(x
));
388 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Contents
[i
].m_Name
) + 1);
389 f
->Write(&x
, sizeof(x
));
390 WRITE_STRING(f
, m_Contents
[i
].m_Name
, x
);
391 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Contents
[i
].m_Page
) + 1);
392 f
->Write(&x
, sizeof(x
));
393 WRITE_STRING(f
, m_Contents
[i
].m_Page
, x
);
399 for (i
= 0; i
< m_IndexCnt
; i
++) if (m_Index
[i
].m_Book
== book
&& m_Index
[i
].m_Level
> 0) x
++;
400 x
= wxINT32_SWAP_ON_BE(x
);
401 f
->Write(&x
, sizeof(x
));
402 for (i
= 0; i
< m_IndexCnt
; i
++)
404 if (m_Index
[i
].m_Book
!= book
|| m_Index
[i
].m_Level
== 0) continue;
405 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Index
[i
].m_Name
) + 1);
406 f
->Write(&x
, sizeof(x
));
407 WRITE_STRING(f
, m_Index
[i
].m_Name
, x
);
408 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Index
[i
].m_Page
) + 1);
409 f
->Write(&x
, sizeof(x
));
410 WRITE_STRING(f
, m_Index
[i
].m_Page
, x
);
416 void wxHtmlHelpData::SetTempDir(const wxString
& path
)
418 if (path
== wxEmptyString
) m_TempPath
= path
;
421 if (wxIsAbsolutePath(path
)) m_TempPath
= path
;
422 else m_TempPath
= wxGetCwd() + _T("/") + path
;
424 if (m_TempPath
[m_TempPath
.Length() - 1] != _T('/'))
425 m_TempPath
<< _T('/');
431 static wxString
SafeFileName(const wxString
& s
)
434 res
.Replace(wxT("#"), wxT("_"));
435 res
.Replace(wxT(":"), wxT("_"));
436 res
.Replace(wxT("\\"), wxT("_"));
437 res
.Replace(wxT("/"), wxT("_"));
441 bool wxHtmlHelpData::AddBookParam(const wxFSFile
& bookfile
,
442 wxFontEncoding encoding
,
443 const wxString
& title
, const wxString
& contfile
,
444 const wxString
& indexfile
, const wxString
& deftopic
,
445 const wxString
& path
)
449 wxHtmlBookRecord
*bookr
;
451 int IndexOld
= m_IndexCnt
,
452 ContentsOld
= m_ContentsCnt
;
454 if (! path
.IsEmpty())
455 fsys
.ChangePathTo(path
, TRUE
);
457 bookr
= new wxHtmlBookRecord(fsys
.GetPath(), title
, deftopic
);
459 if (m_ContentsCnt
% wxHTML_REALLOC_STEP
== 0)
460 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
, (m_ContentsCnt
+ wxHTML_REALLOC_STEP
) * sizeof(wxHtmlContentsItem
));
461 m_Contents
[m_ContentsCnt
].m_Level
= 0;
462 m_Contents
[m_ContentsCnt
].m_ID
= 0;
463 m_Contents
[m_ContentsCnt
].m_Page
= new wxChar
[deftopic
.Length() + 1];
464 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Page
, deftopic
.c_str());
465 m_Contents
[m_ContentsCnt
].m_Name
= new wxChar
[title
.Length() + 1];
466 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Name
, title
.c_str());
467 m_Contents
[m_ContentsCnt
].m_Book
= bookr
;
469 // store the contents index for later
470 int cont_start
= m_ContentsCnt
++;
472 // Try to find cached binary versions:
473 // 1. save file as book, but with .hhp.cached extension
474 // 2. same as 1. but in temp path
475 // 3. otherwise or if cache load failed, load it from MS.
477 fi
= fsys
.OpenFile(bookfile
.GetLocation() + wxT(".cached"));
480 fi
->GetModificationTime() < bookfile
.GetModificationTime() ||
481 !LoadCachedBook(bookr
, fi
->GetStream()))
483 if (fi
!= NULL
) delete fi
;
484 fi
= fsys
.OpenFile(m_TempPath
+ wxFileNameFromPath(bookfile
.GetLocation()) + wxT(".cached"));
485 if (m_TempPath
== wxEmptyString
|| fi
== NULL
||
486 fi
->GetModificationTime() < bookfile
.GetModificationTime() ||
487 !LoadCachedBook(bookr
, fi
->GetStream()))
489 LoadMSProject(bookr
, fsys
, indexfile
, contfile
);
490 if (m_TempPath
!= wxEmptyString
)
492 wxFileOutputStream
*outs
= new wxFileOutputStream(m_TempPath
+
493 SafeFileName(wxFileNameFromPath(bookfile
.GetLocation())) + wxT(".cached"));
494 SaveCachedBook(bookr
, outs
);
500 if (fi
!= NULL
) delete fi
;
502 // Now store the contents range
503 bookr
->SetContentsRange(cont_start
, m_ContentsCnt
);
505 // Convert encoding, if neccessary:
506 if (encoding
!= wxFONTENCODING_SYSTEM
)
508 wxFontEncodingArray a
= wxEncodingConverter::GetPlatformEquivalents(encoding
);
509 if (a
.GetCount() != 0 && a
[0] != encoding
)
512 wxEncodingConverter conv
;
513 conv
.Init(encoding
, a
[0]);
515 for (i
= IndexOld
; i
< m_IndexCnt
; i
++)
516 conv
.Convert(m_Index
[i
].m_Name
);
517 for (i
= ContentsOld
; i
< m_ContentsCnt
; i
++)
518 conv
.Convert(m_Contents
[i
].m_Name
);
522 m_BookRecords
.Add(bookr
);
524 qsort(m_Index
, m_IndexCnt
, sizeof(wxHtmlContentsItem
), IndexCompareFunc
);
530 bool wxHtmlHelpData::AddBook(const wxString
& book
)
532 if (book
.Right(4).Lower() == wxT(".zip") ||
533 book
.Right(4).Lower() == wxT(".htb") /*html book*/)
540 s
= fsys
.FindFirst(book
+ wxT("#zip:") + wxT("*.hhp"), wxFILE
);
543 if (AddBook(s
)) rt
= TRUE
;
559 char *buff
, *lineptr
;
562 wxString title
= _("noname"),
564 start
= wxEmptyString
,
565 contents
= wxEmptyString
,
566 index
= wxEmptyString
,
567 charset
= wxEmptyString
;
569 if (wxIsAbsolutePath(book
)) bookFull
= book
;
570 else bookFull
= wxGetCwd() + "/" + book
;
572 fi
= fsys
.OpenFile(bookFull
);
575 wxLogError(_("Cannot open HTML help book: %s"), bookFull
.c_str());
578 fsys
.ChangePathTo(bookFull
);
581 buff
= new char[sz
+ 1];
587 lineptr
= ReadLine(lineptr
, linebuf
);
589 if (strstr(linebuf
, "Title=") == linebuf
)
590 title
= linebuf
+ strlen("Title=");
591 if (strstr(linebuf
, "Default topic=") == linebuf
)
592 start
= linebuf
+ strlen("Default topic=");
593 if (strstr(linebuf
, "Index file=") == linebuf
)
594 index
= linebuf
+ strlen("Index file=");
595 if (strstr(linebuf
, "Contents file=") == linebuf
)
596 contents
= linebuf
+ strlen("Contents file=");
597 if (strstr(linebuf
, "Charset=") == linebuf
)
598 charset
= linebuf
+ strlen("Charset=");
599 } while (lineptr
!= NULL
);
603 if (charset
== wxEmptyString
) enc
= wxFONTENCODING_SYSTEM
;
604 else enc
= wxTheFontMapper
->CharsetToEncoding(charset
);
605 bool rtval
= AddBookParam(*fi
, enc
,
606 title
, contents
, index
, start
, fsys
.GetPath());
612 wxString
wxHtmlHelpData::FindPageByName(const wxString
& x
)
618 wxString
url(wxEmptyString
);
620 /* 1. try to open given file: */
622 cnt
= m_BookRecords
.GetCount();
623 for (i
= 0; i
< cnt
; i
++)
625 f
= fsys
.OpenFile(m_BookRecords
[i
].GetFullPath(x
));
628 url
= m_BookRecords
[i
].GetFullPath(x
);
635 /* 2. try to find a book: */
637 for (i
= 0; i
< cnt
; i
++)
639 if (m_BookRecords
[i
].GetTitle() == x
)
641 url
= m_BookRecords
[i
].GetFullPath(m_BookRecords
[i
].GetStart());
646 /* 3. try to find in contents: */
649 for (i
= 0; i
< cnt
; i
++)
651 if (wxStrcmp(m_Contents
[i
].m_Name
, x
) == 0)
653 url
= m_Contents
[i
].GetFullPath();
659 /* 4. try to find in index: */
662 for (i
= 0; i
< cnt
; i
++)
664 if (wxStrcmp(m_Index
[i
].m_Name
, x
) == 0)
666 url
= m_Index
[i
].GetFullPath();
674 wxString
wxHtmlHelpData::FindPageById(int id
)
677 wxString
url(wxEmptyString
);
679 for (i
= 0; i
< m_ContentsCnt
; i
++)
681 if (m_Contents
[i
].m_ID
== id
)
683 url
= m_Contents
[i
].GetFullPath();
691 //----------------------------------------------------------------------------------
692 // wxHtmlSearchStatus functions
693 //----------------------------------------------------------------------------------
695 wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData
* data
, const wxString
& keyword
,
696 bool case_sensitive
, bool whole_words_only
,
697 const wxString
& book
)
701 wxHtmlBookRecord
* bookr
= NULL
;
702 if (book
!= wxEmptyString
)
704 // we have to search in a specific book. Find it first
705 int i
, cnt
= data
->m_BookRecords
.GetCount();
706 for (i
= 0; i
< cnt
; i
++)
707 if (data
->m_BookRecords
[i
].GetTitle() == book
)
709 bookr
= &(data
->m_BookRecords
[i
]);
710 m_CurIndex
= bookr
->GetContentsStart();
711 m_MaxIndex
= bookr
->GetContentsEnd();
714 // check; we won't crash if the book doesn't exist, but it's Bad Anyway.
719 // no book specified; search all books
721 m_MaxIndex
= m_Data
->m_ContentsCnt
;
723 m_Engine
.LookFor(keyword
, case_sensitive
, whole_words_only
);
724 m_Active
= (m_CurIndex
< m_MaxIndex
);
728 bool wxHtmlSearchStatus::Search()
731 int i
= m_CurIndex
; // shortcut
737 // sanity check. Illegal use, but we'll try to prevent a crash anyway
742 m_Name
= wxEmptyString
;
743 m_ContentsItem
= NULL
;
744 thepage
= m_Data
->m_Contents
[i
].m_Page
;
746 m_Active
= (++m_CurIndex
< m_MaxIndex
);
747 // check if it is same page with different anchor:
748 if (m_LastPage
!= NULL
)
751 for (p1
= thepage
, p2
= m_LastPage
;
752 *p1
!= 0 && *p1
!= _T('#') && *p1
== *p2
; p1
++, p2
++) {}
754 m_LastPage
= thepage
;
756 if (*p1
== 0 || *p1
== _T('#'))
759 else m_LastPage
= thepage
;
762 file
= fsys
.OpenFile(m_Data
->m_Contents
[i
].m_Book
->GetFullPath(thepage
));
765 if (m_Engine
.Scan(file
->GetStream()))
767 m_Name
= m_Data
->m_Contents
[i
].m_Name
;
768 m_ContentsItem
= m_Data
->m_Contents
+ i
;
783 //--------------------------------------------------------------------------------
785 //--------------------------------------------------------------------------------
787 void wxSearchEngine::LookFor(const wxString
& keyword
, bool case_sensitive
, bool whole_words_only
)
789 m_CaseSensitive
= case_sensitive
;
790 m_WholeWords
= whole_words_only
;
791 if (m_Keyword
) delete[] m_Keyword
;
792 m_Keyword
= new wxChar
[keyword
.Length() + 1];
793 wxStrcpy(m_Keyword
, keyword
.c_str());
795 if (!m_CaseSensitive
)
797 for (int i
= wxStrlen(m_Keyword
) - 1; i
>= 0; i
--)
799 if ((m_Keyword
[i
] >= wxT('A')) && (m_Keyword
[i
] <= wxT('Z')))
800 m_Keyword
[i
] += wxT('a') - wxT('A');
807 #define WHITESPACE(c) (c == ' ' || c == '\n' || c == '\r' || c == '\t')
809 bool wxSearchEngine::Scan(wxInputStream
*stream
)
811 wxASSERT_MSG(m_Keyword
!= NULL
, wxT("wxSearchEngine::LookFor must be called before scanning!"));
814 int lng
= stream
->GetSize();
815 int wrd
= wxStrlen(m_Keyword
);
817 char *buf
= new char[lng
+ 1];
818 stream
->Read(buf
, lng
);
821 if (!m_CaseSensitive
)
822 for (i
= 0; i
< lng
; i
++)
823 if ((buf
[i
] >= 'A') && (buf
[i
] <= 'Z')) buf
[i
] += 'a' - 'A';
827 for (i
= 0; i
< lng
- wrd
; i
++)
829 if (WHITESPACE(buf
[i
])) continue;
831 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
832 if (j
== wrd
&& WHITESPACE(buf
[i
+ j
])) { found
= TRUE
; break; }
838 for (i
= 0; i
< lng
- wrd
; i
++)
841 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
842 if (j
== wrd
) { found
= TRUE
; break; }