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 "helpdata.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #if wxUSE_HTML && wxUSE_STREAMS
34 #include "wx/html/helpdata.h"
35 #include "wx/tokenzr.h"
36 #include "wx/wfstream.h"
37 #include "wx/busyinfo.h"
38 #include "wx/encconv.h"
39 #include "wx/fontmap.h"
41 #include "wx/html/htmlpars.h"
42 #include "wx/html/htmldefs.h"
43 #include "wx/html/htmlfilt.h"
44 #include "wx/filename.h"
46 #include "wx/arrimpl.cpp"
47 WX_DEFINE_OBJARRAY(wxHtmlBookRecArray
)
49 //-----------------------------------------------------------------------------
50 // static helper functions
51 //-----------------------------------------------------------------------------
53 // Reads one line, stores it into buf and returns pointer to new line or NULL.
54 static const wxChar
* ReadLine(const wxChar
*line
, wxChar
*buf
, size_t bufsize
)
56 wxChar
*writeptr
= buf
;
57 wxChar
*endptr
= buf
+ bufsize
- 1;
58 const wxChar
*readptr
= line
;
60 while (*readptr
!= 0 && *readptr
!= _T('\r') && *readptr
!= _T('\n') &&
62 *(writeptr
++) = *(readptr
++);
64 while (*readptr
== _T('\r') || *readptr
== _T('\n'))
74 extern "C" int LINKAGEMODE
75 wxHtmlHelpIndexCompareFunc(const void *a
, const void *b
)
77 return wxStricmp(((wxHtmlContentsItem
*)a
)->m_Name
, ((wxHtmlContentsItem
*)b
)->m_Name
);
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
85 class HP_Parser
: public wxHtmlParser
88 wxObject
* GetProduct() { return NULL
; }
90 virtual void AddText(const wxChar
* WXUNUSED(txt
)) {}
94 //-----------------------------------------------------------------------------
96 //-----------------------------------------------------------------------------
98 class HP_TagHandler
: public wxHtmlTagHandler
101 wxString m_Name
, m_Page
;
105 wxHtmlContentsItem
*m_Items
;
107 wxHtmlBookRecord
*m_Book
;
110 HP_TagHandler(wxHtmlBookRecord
*b
) : wxHtmlTagHandler()
111 { m_Book
= b
; m_Items
= NULL
; m_ItemsCnt
= 0; m_Name
= m_Page
= wxEmptyString
;
112 m_Level
= 0; m_ID
= -1; }
113 wxString
GetSupportedTags() { return wxT("UL,OBJECT,PARAM"); }
114 bool HandleTag(const wxHtmlTag
& tag
);
115 void WriteOut(wxHtmlContentsItem
*& array
, int& size
);
116 void ReadIn(wxHtmlContentsItem
* array
, int size
);
120 bool HP_TagHandler::HandleTag(const wxHtmlTag
& tag
)
122 if (tag
.GetName() == wxT("UL"))
129 else if (tag
.GetName() == wxT("OBJECT"))
131 m_Name
= m_Page
= wxEmptyString
;
135 if (!m_Page
.IsEmpty())
136 /* Valid HHW's file may contain only two object tags:
138 <OBJECT type="text/site properties">
139 <param name="ImageType" value="Folder">
144 <OBJECT type="text/sitemap">
145 <param name="Name" value="main page">
146 <param name="Local" value="another.htm">
149 We're interested in the latter. !m_Page.IsEmpty() is valid
150 condition because text/site properties does not contain Local param
153 if (tag
.GetParam(wxT("TYPE")) == wxT("text/sitemap"))
155 if (m_ItemsCnt
% wxHTML_REALLOC_STEP
== 0)
156 m_Items
= (wxHtmlContentsItem
*) realloc(m_Items
,
157 (m_ItemsCnt
+ wxHTML_REALLOC_STEP
) *
158 sizeof(wxHtmlContentsItem
));
160 m_Items
[m_ItemsCnt
].m_Level
= m_Level
;
161 m_Items
[m_ItemsCnt
].m_ID
= m_ID
;
162 m_Items
[m_ItemsCnt
].m_Page
= new wxChar
[m_Page
.Length() + 1];
163 wxStrcpy(m_Items
[m_ItemsCnt
].m_Page
, m_Page
.c_str());
164 m_Items
[m_ItemsCnt
].m_Name
= new wxChar
[m_Name
.Length() + 1];
165 wxStrcpy(m_Items
[m_ItemsCnt
].m_Name
, m_Name
.c_str());
166 m_Items
[m_ItemsCnt
].m_Book
= m_Book
;
174 if (m_Name
== wxEmptyString
&& tag
.GetParam(wxT("NAME")) == wxT("Name"))
175 m_Name
= tag
.GetParam(wxT("VALUE"));
176 if (tag
.GetParam(wxT("NAME")) == wxT("Local"))
177 m_Page
= tag
.GetParam(wxT("VALUE"));
178 if (tag
.GetParam(wxT("NAME")) == wxT("ID"))
179 tag
.GetParamAsInt(wxT("VALUE"), &m_ID
);
186 void HP_TagHandler::WriteOut(wxHtmlContentsItem
*& array
, int& size
)
194 void HP_TagHandler::ReadIn(wxHtmlContentsItem
* array
, int size
)
203 //-----------------------------------------------------------------------------
205 //-----------------------------------------------------------------------------
207 wxString
wxHtmlBookRecord::GetFullPath(const wxString
&page
) const
209 if (wxIsAbsolutePath(page
))
212 return m_BasePath
+ page
;
217 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpData
, wxObject
)
219 wxHtmlHelpData::wxHtmlHelpData()
221 m_TempPath
= wxEmptyString
;
229 wxHtmlHelpData::~wxHtmlHelpData()
233 m_BookRecords
.Empty();
236 for (i
= 0; i
< m_ContentsCnt
; i
++)
238 delete[] m_Contents
[i
].m_Page
;
239 delete[] m_Contents
[i
].m_Name
;
245 for (i
= 0; i
< m_IndexCnt
; i
++)
247 delete[] m_Index
[i
].m_Page
;
248 delete[] m_Index
[i
].m_Name
;
254 bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
, const wxString
& indexfile
, const wxString
& contentsfile
)
257 wxHtmlFilterHTML filter
;
262 HP_TagHandler
*handler
= new HP_TagHandler(book
);
263 parser
.AddTagHandler(handler
);
265 f
= ( contentsfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(contentsfile
) );
269 buf
= filter
.ReadFile(*f
);
271 handler
->ReadIn(m_Contents
, m_ContentsCnt
);
273 handler
->WriteOut(m_Contents
, m_ContentsCnt
);
277 wxLogError(_("Cannot open contents file: %s"), contentsfile
.c_str());
280 f
= ( indexfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(indexfile
) );
284 buf
= filter
.ReadFile(*f
);
286 handler
->ReadIn(m_Index
, m_IndexCnt
);
288 handler
->WriteOut(m_Index
, m_IndexCnt
);
290 else if (!indexfile
.IsEmpty())
292 wxLogError(_("Cannot open index file: %s"), indexfile
.c_str());
299 inline static void CacheWriteInt32(wxOutputStream
*f
, wxInt32 value
)
301 wxInt32 x
= wxINT32_SWAP_ON_BE(value
);
302 f
->Write(&x
, sizeof(x
));
305 inline static wxInt32
CacheReadInt32(wxInputStream
*f
)
308 f
->Read(&x
, sizeof(x
));
309 return wxINT32_SWAP_ON_BE(x
);
312 inline static void CacheWriteString(wxOutputStream
*f
, const wxChar
*str
)
315 wxWX2MBbuf
mbstr(wxConvUTF8
.cWX2MB(str
));
317 const wxChar
*mbstr
= str
;
319 size_t len
= strlen(mbstr
)+1;
320 CacheWriteInt32(f
, len
);
321 f
->Write(mbstr
, len
);
324 inline static wxChar
* CacheReadString(wxInputStream
*f
)
327 size_t len
= (size_t)CacheReadInt32(f
);
333 wxMB2WXbuf
wxstr(wxConvUTF8
.cMB2WX(str
));
334 wxChar
*outstr
= new wxChar
[wxStrlen(wxstr
)+1];
335 wxStrcpy(outstr
, wxstr
);
340 #define CURRENT_CACHED_BOOK_VERSION 3
342 bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
)
347 /* load header - version info : */
348 version
= CacheReadInt32(f
);
350 if (version
!= CURRENT_CACHED_BOOK_VERSION
)
352 // NB: We can just silently return FALSE here and don't worry about
353 // it anymore, because AddBookParam will load the MS project in
354 // absence of (properly versioned) .cached file and automatically
355 // create new .cached file immediately afterward.
359 /* load contents : */
361 m_ContentsCnt
+= CacheReadInt32(f
);
362 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
,
363 (m_ContentsCnt
/ wxHTML_REALLOC_STEP
+ 1) *
364 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
365 for (i
= st
; i
< m_ContentsCnt
; i
++)
367 m_Contents
[i
].m_Level
= CacheReadInt32(f
);
368 m_Contents
[i
].m_ID
= CacheReadInt32(f
);
369 m_Contents
[i
].m_Name
= CacheReadString(f
);
370 m_Contents
[i
].m_Page
= CacheReadString(f
);
371 m_Contents
[i
].m_Book
= book
;
376 m_IndexCnt
+= CacheReadInt32(f
);
377 m_Index
= (wxHtmlContentsItem
*) realloc(m_Index
, (m_IndexCnt
/ wxHTML_REALLOC_STEP
+ 1) *
378 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
379 for (i
= st
; i
< m_IndexCnt
; i
++)
381 m_Index
[i
].m_Name
= CacheReadString(f
);
382 m_Index
[i
].m_Page
= CacheReadString(f
);
383 m_Index
[i
].m_Book
= book
;
389 bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
)
394 /* save header - version info : */
395 CacheWriteInt32(f
, CURRENT_CACHED_BOOK_VERSION
);
397 /* save contents : */
398 for (cnt
= 0, i
= 0; i
< m_ContentsCnt
; i
++)
399 if (m_Contents
[i
].m_Book
== book
&& m_Contents
[i
].m_Level
> 0)
401 CacheWriteInt32(f
, cnt
);
403 for (i
= 0; i
< m_ContentsCnt
; i
++)
405 if (m_Contents
[i
].m_Book
!= book
|| m_Contents
[i
].m_Level
== 0)
407 CacheWriteInt32(f
, m_Contents
[i
].m_Level
);
408 CacheWriteInt32(f
, m_Contents
[i
].m_ID
);
409 CacheWriteString(f
, m_Contents
[i
].m_Name
);
410 CacheWriteString(f
, m_Contents
[i
].m_Page
);
414 for (cnt
= 0, i
= 0; i
< m_IndexCnt
; i
++)
415 if (m_Index
[i
].m_Book
== book
&& m_Index
[i
].m_Level
> 0)
417 CacheWriteInt32(f
, cnt
);
419 for (i
= 0; i
< m_IndexCnt
; i
++)
421 if (m_Index
[i
].m_Book
!= book
|| m_Index
[i
].m_Level
== 0)
423 CacheWriteString(f
, m_Index
[i
].m_Name
);
424 CacheWriteString(f
, m_Index
[i
].m_Page
);
430 void wxHtmlHelpData::SetTempDir(const wxString
& path
)
432 if (path
== wxEmptyString
) m_TempPath
= path
;
435 if (wxIsAbsolutePath(path
)) m_TempPath
= path
;
436 else m_TempPath
= wxGetCwd() + _T("/") + path
;
438 if (m_TempPath
[m_TempPath
.Length() - 1] != _T('/'))
439 m_TempPath
<< _T('/');
445 static wxString
SafeFileName(const wxString
& s
)
448 res
.Replace(wxT("#"), wxT("_"));
449 res
.Replace(wxT(":"), wxT("_"));
450 res
.Replace(wxT("\\"), wxT("_"));
451 res
.Replace(wxT("/"), wxT("_"));
455 bool wxHtmlHelpData::AddBookParam(const wxFSFile
& bookfile
,
456 wxFontEncoding encoding
,
457 const wxString
& title
, const wxString
& contfile
,
458 const wxString
& indexfile
, const wxString
& deftopic
,
459 const wxString
& path
)
463 wxHtmlBookRecord
*bookr
;
465 int IndexOld
= m_IndexCnt
,
466 ContentsOld
= m_ContentsCnt
;
469 fsys
.ChangePathTo(path
, TRUE
);
471 size_t booksCnt
= m_BookRecords
.GetCount();
472 for (size_t i
= 0; i
< booksCnt
; i
++)
474 if ( m_BookRecords
[i
].GetBookFile() == bookfile
.GetLocation() )
475 return TRUE
; // book is (was) loaded
478 bookr
= new wxHtmlBookRecord(bookfile
.GetLocation(), fsys
.GetPath(), title
, deftopic
);
480 if (m_ContentsCnt
% wxHTML_REALLOC_STEP
== 0)
481 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
, (m_ContentsCnt
+ wxHTML_REALLOC_STEP
) * sizeof(wxHtmlContentsItem
));
482 m_Contents
[m_ContentsCnt
].m_Level
= 0;
483 m_Contents
[m_ContentsCnt
].m_ID
= 0;
484 m_Contents
[m_ContentsCnt
].m_Page
= new wxChar
[deftopic
.Length() + 1];
485 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Page
, deftopic
.c_str());
486 m_Contents
[m_ContentsCnt
].m_Name
= new wxChar
[title
.Length() + 1];
487 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Name
, title
.c_str());
488 m_Contents
[m_ContentsCnt
].m_Book
= bookr
;
490 // store the contents index for later
491 int cont_start
= m_ContentsCnt
++;
493 // Try to find cached binary versions:
494 // 1. save file as book, but with .hhp.cached extension
495 // 2. same as 1. but in temp path
496 // 3. otherwise or if cache load failed, load it from MS.
498 fi
= fsys
.OpenFile(bookfile
.GetLocation() + wxT(".cached"));
501 fi
->GetModificationTime() < bookfile
.GetModificationTime() ||
502 !LoadCachedBook(bookr
, fi
->GetStream()))
504 if (fi
!= NULL
) delete fi
;
505 fi
= fsys
.OpenFile(m_TempPath
+ wxFileNameFromPath(bookfile
.GetLocation()) + wxT(".cached"));
506 if (m_TempPath
== wxEmptyString
|| fi
== NULL
||
507 fi
->GetModificationTime() < bookfile
.GetModificationTime() ||
508 !LoadCachedBook(bookr
, fi
->GetStream()))
510 LoadMSProject(bookr
, fsys
, indexfile
, contfile
);
511 if (m_TempPath
!= wxEmptyString
)
513 wxFileOutputStream
*outs
= new wxFileOutputStream(m_TempPath
+
514 SafeFileName(wxFileNameFromPath(bookfile
.GetLocation())) + wxT(".cached"));
515 SaveCachedBook(bookr
, outs
);
521 if (fi
!= NULL
) delete fi
;
523 // Now store the contents range
524 bookr
->SetContentsRange(cont_start
, m_ContentsCnt
);
526 // Convert encoding, if neccessary:
527 if (encoding
!= wxFONTENCODING_SYSTEM
)
529 wxFontEncodingArray a
= wxEncodingConverter::GetPlatformEquivalents(encoding
);
530 if (a
.GetCount() != 0 && a
[0] != encoding
)
533 wxEncodingConverter conv
;
534 conv
.Init(encoding
, a
[0]);
536 for (i
= IndexOld
; i
< m_IndexCnt
; i
++)
537 conv
.Convert(m_Index
[i
].m_Name
);
538 for (i
= ContentsOld
; i
< m_ContentsCnt
; i
++)
539 conv
.Convert(m_Contents
[i
].m_Name
);
543 m_BookRecords
.Add(bookr
);
545 qsort(m_Index
, m_IndexCnt
, sizeof(wxHtmlContentsItem
), wxHtmlHelpIndexCompareFunc
);
551 bool wxHtmlHelpData::AddBook(const wxString
& book
)
553 if (book
.Right(4).Lower() == wxT(".zip") ||
554 book
.Right(4).Lower() == wxT(".htb") /*html book*/)
560 s
= fsys
.FindFirst(book
+ wxT("#zip:") + wxT("*.hhp"), wxFILE
);
563 if (AddBook(s
)) rt
= TRUE
;
575 wxString title
= _("noname"),
577 start
= wxEmptyString
,
578 contents
= wxEmptyString
,
579 index
= wxEmptyString
,
580 charset
= wxEmptyString
;
582 #if defined(__WXMAC__) && !defined(__DARWIN__)
583 if (wxIsAbsolutePath(book
)) bookFull
= book
;
584 else bookFull
= wxGetCwd() + book
; // no slash or dot
585 wxFileName
fn( bookFull
);
586 bookFull
= fn
.GetFullPath( wxPATH_UNIX
);
588 if (wxIsAbsolutePath(book
)) bookFull
= book
;
589 else bookFull
= wxGetCwd() + wxT("/") + book
;
592 fi
= fsys
.OpenFile(bookFull
);
595 wxLogError(_("Cannot open HTML help book: %s"), bookFull
.c_str());
598 fsys
.ChangePathTo(bookFull
);
600 const wxChar
*lineptr
;
603 wxHtmlFilterPlainText filter
;
604 tmp
= filter
.ReadFile(*fi
);
605 lineptr
= tmp
.c_str();
609 lineptr
= ReadLine(lineptr
, linebuf
, 300);
611 for (wxChar
*ch
= linebuf
; *ch
!= wxT('\0') && *ch
!= wxT('='); ch
++)
614 if (wxStrstr(linebuf
, _T("title=")) == linebuf
)
615 title
= linebuf
+ wxStrlen(_T("title="));
616 if (wxStrstr(linebuf
, _T("default topic=")) == linebuf
)
617 start
= linebuf
+ wxStrlen(_T("default topic="));
618 if (wxStrstr(linebuf
, _T("index file=")) == linebuf
)
619 index
= linebuf
+ wxStrlen(_T("index file="));
620 if (wxStrstr(linebuf
, _T("contents file=")) == linebuf
)
621 contents
= linebuf
+ wxStrlen(_T("contents file="));
622 if (wxStrstr(linebuf
, _T("charset=")) == linebuf
)
623 charset
= linebuf
+ wxStrlen(_T("charset="));
624 } while (lineptr
!= NULL
);
627 if (charset
== wxEmptyString
) enc
= wxFONTENCODING_SYSTEM
;
628 else enc
= wxFontMapper::Get()->CharsetToEncoding(charset
);
629 bool rtval
= AddBookParam(*fi
, enc
,
630 title
, contents
, index
, start
, fsys
.GetPath());
636 wxString
wxHtmlHelpData::FindPageByName(const wxString
& x
)
642 wxString
url(wxEmptyString
);
644 /* 1. try to open given file: */
646 cnt
= m_BookRecords
.GetCount();
647 for (i
= 0; i
< cnt
; i
++)
649 f
= fsys
.OpenFile(m_BookRecords
[i
].GetFullPath(x
));
652 url
= m_BookRecords
[i
].GetFullPath(x
);
659 /* 2. try to find a book: */
661 for (i
= 0; i
< cnt
; i
++)
663 if (m_BookRecords
[i
].GetTitle() == x
)
665 url
= m_BookRecords
[i
].GetFullPath(m_BookRecords
[i
].GetStart());
670 /* 3. try to find in contents: */
673 for (i
= 0; i
< cnt
; i
++)
675 if (wxStrcmp(m_Contents
[i
].m_Name
, x
) == 0)
677 url
= m_Contents
[i
].GetFullPath();
683 /* 4. try to find in index: */
686 for (i
= 0; i
< cnt
; i
++)
688 if (wxStrcmp(m_Index
[i
].m_Name
, x
) == 0)
690 url
= m_Index
[i
].GetFullPath();
698 wxString
wxHtmlHelpData::FindPageById(int id
)
701 wxString
url(wxEmptyString
);
703 for (i
= 0; i
< m_ContentsCnt
; i
++)
705 if (m_Contents
[i
].m_ID
== id
)
707 url
= m_Contents
[i
].GetFullPath();
715 //----------------------------------------------------------------------------------
716 // wxHtmlSearchStatus functions
717 //----------------------------------------------------------------------------------
719 wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData
* data
, const wxString
& keyword
,
720 bool case_sensitive
, bool whole_words_only
,
721 const wxString
& book
)
725 wxHtmlBookRecord
* bookr
= NULL
;
726 if (book
!= wxEmptyString
)
728 // we have to search in a specific book. Find it first
729 int i
, cnt
= data
->m_BookRecords
.GetCount();
730 for (i
= 0; i
< cnt
; i
++)
731 if (data
->m_BookRecords
[i
].GetTitle() == book
)
733 bookr
= &(data
->m_BookRecords
[i
]);
734 m_CurIndex
= bookr
->GetContentsStart();
735 m_MaxIndex
= bookr
->GetContentsEnd();
738 // check; we won't crash if the book doesn't exist, but it's Bad Anyway.
743 // no book specified; search all books
745 m_MaxIndex
= m_Data
->m_ContentsCnt
;
747 m_Engine
.LookFor(keyword
, case_sensitive
, whole_words_only
);
748 m_Active
= (m_CurIndex
< m_MaxIndex
);
752 bool wxHtmlSearchStatus::Search()
755 int i
= m_CurIndex
; // shortcut
761 // sanity check. Illegal use, but we'll try to prevent a crash anyway
766 m_Name
= wxEmptyString
;
767 m_ContentsItem
= NULL
;
768 thepage
= m_Data
->m_Contents
[i
].m_Page
;
770 m_Active
= (++m_CurIndex
< m_MaxIndex
);
771 // check if it is same page with different anchor:
772 if (m_LastPage
!= NULL
)
775 for (p1
= thepage
, p2
= m_LastPage
;
776 *p1
!= 0 && *p1
!= _T('#') && *p1
== *p2
; p1
++, p2
++) {}
778 m_LastPage
= thepage
;
780 if (*p1
== 0 || *p1
== _T('#'))
783 else m_LastPage
= thepage
;
786 file
= fsys
.OpenFile(m_Data
->m_Contents
[i
].m_Book
->GetFullPath(thepage
));
789 if (m_Engine
.Scan(*file
))
791 m_Name
= m_Data
->m_Contents
[i
].m_Name
;
792 m_ContentsItem
= m_Data
->m_Contents
+ i
;
807 //--------------------------------------------------------------------------------
808 // wxHtmlSearchEngine
809 //--------------------------------------------------------------------------------
811 void wxHtmlSearchEngine::LookFor(const wxString
& keyword
, bool case_sensitive
, bool whole_words_only
)
813 m_CaseSensitive
= case_sensitive
;
814 m_WholeWords
= whole_words_only
;
815 if (m_Keyword
) delete[] m_Keyword
;
816 m_Keyword
= new wxChar
[keyword
.Length() + 1];
817 wxStrcpy(m_Keyword
, keyword
.c_str());
819 if (!m_CaseSensitive
)
821 for (int i
= wxStrlen(m_Keyword
) - 1; i
>= 0; i
--)
823 if ((m_Keyword
[i
] >= wxT('A')) && (m_Keyword
[i
] <= wxT('Z')))
824 m_Keyword
[i
] += wxT('a') - wxT('A');
830 static inline bool WHITESPACE(wxChar c
)
832 return c
== _T(' ') || c
== _T('\n') || c
== _T('\r') || c
== _T('\t');
835 bool wxHtmlSearchEngine::Scan(const wxFSFile
& file
)
837 wxASSERT_MSG(m_Keyword
!= NULL
, wxT("wxHtmlSearchEngine::LookFor must be called before scanning!"));
840 int wrd
= wxStrlen(m_Keyword
);
842 wxHtmlFilterHTML filter
;
843 wxString tmp
= filter
.ReadFile(file
);
844 int lng
= tmp
.length();
845 const wxChar
*buf
= tmp
.c_str();
847 if (!m_CaseSensitive
)
848 for (i
= 0; i
< lng
; i
++)
849 tmp
[(size_t)i
] = (wxChar
)wxTolower(tmp
[(size_t)i
]);
853 for (i
= 0; i
< lng
- wrd
; i
++)
855 if (WHITESPACE(buf
[i
])) continue;
857 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
858 if (j
== wrd
&& WHITESPACE(buf
[i
+ j
])) { found
= TRUE
; break; }
864 for (i
= 0; i
< lng
- wrd
; i
++)
867 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
868 if (j
== wrd
) { found
= TRUE
; break; }