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
);
118 DECLARE_NO_COPY_CLASS(HP_TagHandler
)
122 bool HP_TagHandler::HandleTag(const wxHtmlTag
& tag
)
124 if (tag
.GetName() == wxT("UL"))
131 else if (tag
.GetName() == wxT("OBJECT"))
133 m_Name
= m_Page
= wxEmptyString
;
137 if (!m_Page
.IsEmpty())
138 /* Valid HHW's file may contain only two object tags:
140 <OBJECT type="text/site properties">
141 <param name="ImageType" value="Folder">
146 <OBJECT type="text/sitemap">
147 <param name="Name" value="main page">
148 <param name="Local" value="another.htm">
151 We're interested in the latter. !m_Page.IsEmpty() is valid
152 condition because text/site properties does not contain Local param
155 if (tag
.GetParam(wxT("TYPE")) == wxT("text/sitemap"))
157 if (m_ItemsCnt
% wxHTML_REALLOC_STEP
== 0)
158 m_Items
= (wxHtmlContentsItem
*) realloc(m_Items
,
159 (m_ItemsCnt
+ wxHTML_REALLOC_STEP
) *
160 sizeof(wxHtmlContentsItem
));
162 m_Items
[m_ItemsCnt
].m_Level
= m_Level
;
163 m_Items
[m_ItemsCnt
].m_ID
= m_ID
;
164 m_Items
[m_ItemsCnt
].m_Page
= new wxChar
[m_Page
.Length() + 1];
165 wxStrcpy(m_Items
[m_ItemsCnt
].m_Page
, m_Page
.c_str());
166 m_Items
[m_ItemsCnt
].m_Name
= new wxChar
[m_Name
.Length() + 1];
167 wxStrcpy(m_Items
[m_ItemsCnt
].m_Name
, m_Name
.c_str());
168 m_Items
[m_ItemsCnt
].m_Book
= m_Book
;
176 if (m_Name
== wxEmptyString
&& tag
.GetParam(wxT("NAME")) == wxT("Name"))
177 m_Name
= tag
.GetParam(wxT("VALUE"));
178 if (tag
.GetParam(wxT("NAME")) == wxT("Local"))
179 m_Page
= tag
.GetParam(wxT("VALUE"));
180 if (tag
.GetParam(wxT("NAME")) == wxT("ID"))
181 tag
.GetParamAsInt(wxT("VALUE"), &m_ID
);
188 void HP_TagHandler::WriteOut(wxHtmlContentsItem
*& array
, int& size
)
196 void HP_TagHandler::ReadIn(wxHtmlContentsItem
* array
, int size
)
205 //-----------------------------------------------------------------------------
207 //-----------------------------------------------------------------------------
209 wxString
wxHtmlBookRecord::GetFullPath(const wxString
&page
) const
211 if (wxIsAbsolutePath(page
))
214 return m_BasePath
+ page
;
219 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpData
, wxObject
)
221 wxHtmlHelpData::wxHtmlHelpData()
223 m_TempPath
= wxEmptyString
;
231 wxHtmlHelpData::~wxHtmlHelpData()
235 m_BookRecords
.Empty();
238 for (i
= 0; i
< m_ContentsCnt
; i
++)
240 delete[] m_Contents
[i
].m_Page
;
241 delete[] m_Contents
[i
].m_Name
;
247 for (i
= 0; i
< m_IndexCnt
; i
++)
249 delete[] m_Index
[i
].m_Page
;
250 delete[] m_Index
[i
].m_Name
;
256 bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
, const wxString
& indexfile
, const wxString
& contentsfile
)
259 wxHtmlFilterHTML filter
;
264 HP_TagHandler
*handler
= new HP_TagHandler(book
);
265 parser
.AddTagHandler(handler
);
267 f
= ( contentsfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(contentsfile
) );
271 buf
= filter
.ReadFile(*f
);
273 handler
->ReadIn(m_Contents
, m_ContentsCnt
);
275 handler
->WriteOut(m_Contents
, m_ContentsCnt
);
279 wxLogError(_("Cannot open contents file: %s"), contentsfile
.c_str());
282 f
= ( indexfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(indexfile
) );
286 buf
= filter
.ReadFile(*f
);
288 handler
->ReadIn(m_Index
, m_IndexCnt
);
290 handler
->WriteOut(m_Index
, m_IndexCnt
);
292 else if (!indexfile
.IsEmpty())
294 wxLogError(_("Cannot open index file: %s"), indexfile
.c_str());
301 inline static void CacheWriteInt32(wxOutputStream
*f
, wxInt32 value
)
303 wxInt32 x
= wxINT32_SWAP_ON_BE(value
);
304 f
->Write(&x
, sizeof(x
));
307 inline static wxInt32
CacheReadInt32(wxInputStream
*f
)
310 f
->Read(&x
, sizeof(x
));
311 return wxINT32_SWAP_ON_BE(x
);
314 inline static void CacheWriteString(wxOutputStream
*f
, const wxChar
*str
)
317 wxWX2MBbuf
mbstr(wxConvUTF8
.cWX2MB(str
));
319 const wxChar
*mbstr
= str
;
321 size_t len
= strlen(mbstr
)+1;
322 CacheWriteInt32(f
, len
);
323 f
->Write(mbstr
, len
);
326 inline static wxChar
* CacheReadString(wxInputStream
*f
)
329 size_t len
= (size_t)CacheReadInt32(f
);
335 wxMB2WXbuf
wxstr(wxConvUTF8
.cMB2WX(str
));
336 wxChar
*outstr
= new wxChar
[wxStrlen(wxstr
)+1];
337 wxStrcpy(outstr
, wxstr
);
342 #define CURRENT_CACHED_BOOK_VERSION 4
344 // Additional flags to detect incompatibilities of the runtime environment:
345 #define CACHED_BOOK_FORMAT_FLAGS \
349 bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
)
354 /* load header - version info : */
355 version
= CacheReadInt32(f
);
357 if (version
!= CURRENT_CACHED_BOOK_VERSION
)
359 // NB: We can just silently return FALSE here and don't worry about
360 // it anymore, because AddBookParam will load the MS project in
361 // absence of (properly versioned) .cached file and automatically
362 // create new .cached file immediately afterward.
366 if (CacheReadInt32(f
) != CACHED_BOOK_FORMAT_FLAGS
)
369 /* load contents : */
371 m_ContentsCnt
+= CacheReadInt32(f
);
372 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
,
373 (m_ContentsCnt
/ wxHTML_REALLOC_STEP
+ 1) *
374 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
375 for (i
= st
; i
< m_ContentsCnt
; i
++)
377 m_Contents
[i
].m_Level
= CacheReadInt32(f
);
378 m_Contents
[i
].m_ID
= CacheReadInt32(f
);
379 m_Contents
[i
].m_Name
= CacheReadString(f
);
380 m_Contents
[i
].m_Page
= CacheReadString(f
);
381 m_Contents
[i
].m_Book
= book
;
386 m_IndexCnt
+= CacheReadInt32(f
);
387 m_Index
= (wxHtmlContentsItem
*) realloc(m_Index
, (m_IndexCnt
/ wxHTML_REALLOC_STEP
+ 1) *
388 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
389 for (i
= st
; i
< m_IndexCnt
; i
++)
391 m_Index
[i
].m_Name
= CacheReadString(f
);
392 m_Index
[i
].m_Page
= CacheReadString(f
);
393 m_Index
[i
].m_Book
= book
;
399 bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
)
404 /* save header - version info : */
405 CacheWriteInt32(f
, CURRENT_CACHED_BOOK_VERSION
);
406 CacheWriteInt32(f
, CACHED_BOOK_FORMAT_FLAGS
);
408 /* save contents : */
409 for (cnt
= 0, i
= 0; i
< m_ContentsCnt
; i
++)
410 if (m_Contents
[i
].m_Book
== book
&& m_Contents
[i
].m_Level
> 0)
412 CacheWriteInt32(f
, cnt
);
414 for (i
= 0; i
< m_ContentsCnt
; i
++)
416 if (m_Contents
[i
].m_Book
!= book
|| m_Contents
[i
].m_Level
== 0)
418 CacheWriteInt32(f
, m_Contents
[i
].m_Level
);
419 CacheWriteInt32(f
, m_Contents
[i
].m_ID
);
420 CacheWriteString(f
, m_Contents
[i
].m_Name
);
421 CacheWriteString(f
, m_Contents
[i
].m_Page
);
425 for (cnt
= 0, i
= 0; i
< m_IndexCnt
; i
++)
426 if (m_Index
[i
].m_Book
== book
&& m_Index
[i
].m_Level
> 0)
428 CacheWriteInt32(f
, cnt
);
430 for (i
= 0; i
< m_IndexCnt
; i
++)
432 if (m_Index
[i
].m_Book
!= book
|| m_Index
[i
].m_Level
== 0)
434 CacheWriteString(f
, m_Index
[i
].m_Name
);
435 CacheWriteString(f
, m_Index
[i
].m_Page
);
441 void wxHtmlHelpData::SetTempDir(const wxString
& path
)
443 if (path
== wxEmptyString
) m_TempPath
= path
;
446 if (wxIsAbsolutePath(path
)) m_TempPath
= path
;
447 else m_TempPath
= wxGetCwd() + _T("/") + path
;
449 if (m_TempPath
[m_TempPath
.Length() - 1] != _T('/'))
450 m_TempPath
<< _T('/');
456 static wxString
SafeFileName(const wxString
& s
)
459 res
.Replace(wxT("#"), wxT("_"));
460 res
.Replace(wxT(":"), wxT("_"));
461 res
.Replace(wxT("\\"), wxT("_"));
462 res
.Replace(wxT("/"), wxT("_"));
466 bool wxHtmlHelpData::AddBookParam(const wxFSFile
& bookfile
,
467 wxFontEncoding encoding
,
468 const wxString
& title
, const wxString
& contfile
,
469 const wxString
& indexfile
, const wxString
& deftopic
,
470 const wxString
& path
)
474 wxHtmlBookRecord
*bookr
;
476 int IndexOld
= m_IndexCnt
,
477 ContentsOld
= m_ContentsCnt
;
480 fsys
.ChangePathTo(path
, TRUE
);
482 size_t booksCnt
= m_BookRecords
.GetCount();
483 for (size_t i
= 0; i
< booksCnt
; i
++)
485 if ( m_BookRecords
[i
].GetBookFile() == bookfile
.GetLocation() )
486 return TRUE
; // book is (was) loaded
489 bookr
= new wxHtmlBookRecord(bookfile
.GetLocation(), fsys
.GetPath(), title
, deftopic
);
491 if (m_ContentsCnt
% wxHTML_REALLOC_STEP
== 0)
492 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
, (m_ContentsCnt
+ wxHTML_REALLOC_STEP
) * sizeof(wxHtmlContentsItem
));
493 m_Contents
[m_ContentsCnt
].m_Level
= 0;
494 m_Contents
[m_ContentsCnt
].m_ID
= 0;
495 m_Contents
[m_ContentsCnt
].m_Page
= new wxChar
[deftopic
.Length() + 1];
496 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Page
, deftopic
.c_str());
497 m_Contents
[m_ContentsCnt
].m_Name
= new wxChar
[title
.Length() + 1];
498 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Name
, title
.c_str());
499 m_Contents
[m_ContentsCnt
].m_Book
= bookr
;
501 // store the contents index for later
502 int cont_start
= m_ContentsCnt
++;
504 // Try to find cached binary versions:
505 // 1. save file as book, but with .hhp.cached extension
506 // 2. same as 1. but in temp path
507 // 3. otherwise or if cache load failed, load it from MS.
509 fi
= fsys
.OpenFile(bookfile
.GetLocation() + wxT(".cached"));
513 fi
->GetModificationTime() < bookfile
.GetModificationTime() ||
514 #endif // wxUSE_DATETIME
515 !LoadCachedBook(bookr
, fi
->GetStream()))
517 if (fi
!= NULL
) delete fi
;
518 fi
= fsys
.OpenFile(m_TempPath
+ wxFileNameFromPath(bookfile
.GetLocation()) + wxT(".cached"));
519 if (m_TempPath
== wxEmptyString
|| fi
== NULL
||
521 fi
->GetModificationTime() < bookfile
.GetModificationTime() ||
522 #endif // wxUSE_DATETIME
523 !LoadCachedBook(bookr
, fi
->GetStream()))
525 LoadMSProject(bookr
, fsys
, indexfile
, contfile
);
526 if (m_TempPath
!= wxEmptyString
)
528 wxFileOutputStream
*outs
= new wxFileOutputStream(m_TempPath
+
529 SafeFileName(wxFileNameFromPath(bookfile
.GetLocation())) + wxT(".cached"));
530 SaveCachedBook(bookr
, outs
);
536 if (fi
!= NULL
) delete fi
;
538 // Now store the contents range
539 bookr
->SetContentsRange(cont_start
, m_ContentsCnt
);
541 // Convert encoding, if neccessary:
542 if (encoding
!= wxFONTENCODING_SYSTEM
)
544 wxFontEncodingArray a
= wxEncodingConverter::GetPlatformEquivalents(encoding
);
545 if (a
.GetCount() != 0 && a
[0] != encoding
)
548 wxEncodingConverter conv
;
549 conv
.Init(encoding
, a
[0]);
551 for (i
= IndexOld
; i
< m_IndexCnt
; i
++)
552 conv
.Convert(m_Index
[i
].m_Name
);
553 for (i
= ContentsOld
; i
< m_ContentsCnt
; i
++)
554 conv
.Convert(m_Contents
[i
].m_Name
);
558 m_BookRecords
.Add(bookr
);
560 qsort(m_Index
, m_IndexCnt
, sizeof(wxHtmlContentsItem
), wxHtmlHelpIndexCompareFunc
);
566 bool wxHtmlHelpData::AddBook(const wxString
& book
)
568 if (book
.Right(4).Lower() == wxT(".zip") ||
569 book
.Right(4).Lower() == wxT(".htb") /*html book*/)
575 s
= fsys
.FindFirst(book
+ wxT("#zip:") + wxT("*.hhp"), wxFILE
);
578 if (AddBook(s
)) rt
= TRUE
;
589 wxString title
= _("noname"),
591 start
= wxEmptyString
,
592 contents
= wxEmptyString
,
593 index
= wxEmptyString
,
594 charset
= wxEmptyString
;
596 fi
= fsys
.OpenFile(book
);
599 wxLogError(_("Cannot open HTML help book: %s"), book
.c_str());
602 fsys
.ChangePathTo(book
);
604 const wxChar
*lineptr
;
607 wxHtmlFilterPlainText filter
;
608 tmp
= filter
.ReadFile(*fi
);
609 lineptr
= tmp
.c_str();
613 lineptr
= ReadLine(lineptr
, linebuf
, 300);
615 for (wxChar
*ch
= linebuf
; *ch
!= wxT('\0') && *ch
!= wxT('='); ch
++)
618 if (wxStrstr(linebuf
, _T("title=")) == linebuf
)
619 title
= linebuf
+ wxStrlen(_T("title="));
620 if (wxStrstr(linebuf
, _T("default topic=")) == linebuf
)
621 start
= linebuf
+ wxStrlen(_T("default topic="));
622 if (wxStrstr(linebuf
, _T("index file=")) == linebuf
)
623 index
= linebuf
+ wxStrlen(_T("index file="));
624 if (wxStrstr(linebuf
, _T("contents file=")) == linebuf
)
625 contents
= linebuf
+ wxStrlen(_T("contents file="));
626 if (wxStrstr(linebuf
, _T("charset=")) == linebuf
)
627 charset
= linebuf
+ wxStrlen(_T("charset="));
628 } while (lineptr
!= NULL
);
631 if (charset
== wxEmptyString
) enc
= wxFONTENCODING_SYSTEM
;
632 else enc
= wxFontMapper::Get()->CharsetToEncoding(charset
);
633 bool rtval
= AddBookParam(*fi
, enc
,
634 title
, contents
, index
, start
, fsys
.GetPath());
640 wxString
wxHtmlHelpData::FindPageByName(const wxString
& x
)
646 wxString
url(wxEmptyString
);
648 /* 1. try to open given file: */
650 cnt
= m_BookRecords
.GetCount();
651 for (i
= 0; i
< cnt
; i
++)
653 f
= fsys
.OpenFile(m_BookRecords
[i
].GetFullPath(x
));
656 url
= m_BookRecords
[i
].GetFullPath(x
);
663 /* 2. try to find a book: */
665 for (i
= 0; i
< cnt
; i
++)
667 if (m_BookRecords
[i
].GetTitle() == x
)
669 url
= m_BookRecords
[i
].GetFullPath(m_BookRecords
[i
].GetStart());
674 /* 3. try to find in contents: */
677 for (i
= 0; i
< cnt
; i
++)
679 if (wxStrcmp(m_Contents
[i
].m_Name
, x
) == 0)
681 url
= m_Contents
[i
].GetFullPath();
687 /* 4. try to find in index: */
690 for (i
= 0; i
< cnt
; i
++)
692 if (wxStrcmp(m_Index
[i
].m_Name
, x
) == 0)
694 url
= m_Index
[i
].GetFullPath();
702 wxString
wxHtmlHelpData::FindPageById(int id
)
705 wxString
url(wxEmptyString
);
707 for (i
= 0; i
< m_ContentsCnt
; i
++)
709 if (m_Contents
[i
].m_ID
== id
)
711 url
= m_Contents
[i
].GetFullPath();
719 //----------------------------------------------------------------------------------
720 // wxHtmlSearchStatus functions
721 //----------------------------------------------------------------------------------
723 wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData
* data
, const wxString
& keyword
,
724 bool case_sensitive
, bool whole_words_only
,
725 const wxString
& book
)
729 wxHtmlBookRecord
* bookr
= NULL
;
730 if (book
!= wxEmptyString
)
732 // we have to search in a specific book. Find it first
733 int i
, cnt
= data
->m_BookRecords
.GetCount();
734 for (i
= 0; i
< cnt
; i
++)
735 if (data
->m_BookRecords
[i
].GetTitle() == book
)
737 bookr
= &(data
->m_BookRecords
[i
]);
738 m_CurIndex
= bookr
->GetContentsStart();
739 m_MaxIndex
= bookr
->GetContentsEnd();
742 // check; we won't crash if the book doesn't exist, but it's Bad Anyway.
747 // no book specified; search all books
749 m_MaxIndex
= m_Data
->m_ContentsCnt
;
751 m_Engine
.LookFor(keyword
, case_sensitive
, whole_words_only
);
752 m_Active
= (m_CurIndex
< m_MaxIndex
);
756 bool wxHtmlSearchStatus::Search()
759 int i
= m_CurIndex
; // shortcut
765 // sanity check. Illegal use, but we'll try to prevent a crash anyway
770 m_Name
= wxEmptyString
;
771 m_ContentsItem
= NULL
;
772 thepage
= m_Data
->m_Contents
[i
].m_Page
;
774 m_Active
= (++m_CurIndex
< m_MaxIndex
);
775 // check if it is same page with different anchor:
776 if (m_LastPage
!= NULL
)
779 for (p1
= thepage
, p2
= m_LastPage
;
780 *p1
!= 0 && *p1
!= _T('#') && *p1
== *p2
; p1
++, p2
++) {}
782 m_LastPage
= thepage
;
784 if (*p1
== 0 || *p1
== _T('#'))
787 else m_LastPage
= thepage
;
790 file
= fsys
.OpenFile(m_Data
->m_Contents
[i
].m_Book
->GetFullPath(thepage
));
793 if (m_Engine
.Scan(*file
))
795 m_Name
= m_Data
->m_Contents
[i
].m_Name
;
796 m_ContentsItem
= m_Data
->m_Contents
+ i
;
811 //--------------------------------------------------------------------------------
812 // wxHtmlSearchEngine
813 //--------------------------------------------------------------------------------
815 void wxHtmlSearchEngine::LookFor(const wxString
& keyword
, bool case_sensitive
, bool whole_words_only
)
817 m_CaseSensitive
= case_sensitive
;
818 m_WholeWords
= whole_words_only
;
819 if (m_Keyword
) delete[] m_Keyword
;
820 m_Keyword
= new wxChar
[keyword
.Length() + 1];
821 wxStrcpy(m_Keyword
, keyword
.c_str());
823 if (!m_CaseSensitive
)
825 for (int i
= wxStrlen(m_Keyword
) - 1; i
>= 0; i
--)
827 if ((m_Keyword
[i
] >= wxT('A')) && (m_Keyword
[i
] <= wxT('Z')))
828 m_Keyword
[i
] += wxT('a') - wxT('A');
834 static inline bool WHITESPACE(wxChar c
)
836 return c
== _T(' ') || c
== _T('\n') || c
== _T('\r') || c
== _T('\t');
839 bool wxHtmlSearchEngine::Scan(const wxFSFile
& file
)
841 wxASSERT_MSG(m_Keyword
!= NULL
, wxT("wxHtmlSearchEngine::LookFor must be called before scanning!"));
844 int wrd
= wxStrlen(m_Keyword
);
846 wxHtmlFilterHTML filter
;
847 wxString tmp
= filter
.ReadFile(file
);
848 int lng
= tmp
.length();
849 const wxChar
*buf
= tmp
.c_str();
851 if (!m_CaseSensitive
)
852 for (i
= 0; i
< lng
; i
++)
853 tmp
[(size_t)i
] = (wxChar
)wxTolower(tmp
[(size_t)i
]);
857 for (i
= 0; i
< lng
- wrd
; i
++)
859 if (WHITESPACE(buf
[i
])) continue;
861 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
862 if (j
== wrd
&& WHITESPACE(buf
[i
+ j
])) { found
= TRUE
; break; }
868 for (i
= 0; i
< lng
- wrd
; i
++)
871 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
872 if (j
== wrd
) { found
= TRUE
; break; }