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"
42 #include "wx/arrimpl.cpp"
43 WX_DEFINE_OBJARRAY(wxHtmlBookRecArray
)
45 //-----------------------------------------------------------------------------
46 // static helper functions
47 //-----------------------------------------------------------------------------
49 // Reads one line, stores it into buf and returns pointer to new line or NULL.
50 static char* ReadLine(char *line
, char *buf
)
52 char *writeptr
= buf
, *readptr
= line
;
54 while (*readptr
!= 0 && *readptr
!= '\r' && *readptr
!= '\n') *(writeptr
++) = *(readptr
++);
56 while (*readptr
== '\r' || *readptr
== '\n') readptr
++;
57 if (*readptr
== 0) return NULL
;
63 static int LINKAGEMODE
IndexCompareFunc(const void *a
, const void *b
)
65 return wxStrcmp(((wxHtmlContentsItem
*)a
)->m_Name
, ((wxHtmlContentsItem
*)b
)->m_Name
);
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
73 class HP_Parser
: public wxHtmlParser
76 void AddText(const char* WXUNUSED(text
)) { }
77 wxObject
* GetProduct() { return NULL
; }
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
85 class HP_TagHandler
: public wxHtmlTagHandler
88 wxString m_Name
, m_Page
;
92 wxHtmlContentsItem
*m_Items
;
94 wxHtmlBookRecord
*m_Book
;
97 HP_TagHandler(wxHtmlBookRecord
*b
) : wxHtmlTagHandler()
98 { m_Book
= b
; m_Items
= NULL
; m_ItemsCnt
= 0; m_Name
= m_Page
= wxEmptyString
;
99 m_Level
= 0; m_ID
= -1; }
100 wxString
GetSupportedTags() { return wxT("UL,OBJECT,PARAM"); }
101 bool HandleTag(const wxHtmlTag
& tag
);
102 void WriteOut(wxHtmlContentsItem
*& array
, int& size
);
103 void ReadIn(wxHtmlContentsItem
* array
, int size
);
107 bool HP_TagHandler::HandleTag(const wxHtmlTag
& tag
)
109 if (tag
.GetName() == wxT("UL"))
116 else if (tag
.GetName() == wxT("OBJECT"))
118 m_Name
= m_Page
= wxEmptyString
;
122 if (!m_Page
.IsEmpty())
123 /* Valid HHW's file may contain only two object tags:
125 <OBJECT type="text/site properties">
126 <param name="ImageType" value="Folder">
131 <OBJECT type="text/sitemap">
132 <param name="Name" value="main page">
133 <param name="Local" value="another.htm">
136 We're interested in the latter. !m_Page.IsEmpty() is valid
137 condition because text/site properties does not contain Local param
140 if (tag
.GetParam(wxT("TYPE")) == wxT("text/sitemap"))
142 if (m_ItemsCnt
% wxHTML_REALLOC_STEP
== 0)
143 m_Items
= (wxHtmlContentsItem
*) realloc(m_Items
,
144 (m_ItemsCnt
+ wxHTML_REALLOC_STEP
) *
145 sizeof(wxHtmlContentsItem
));
147 m_Items
[m_ItemsCnt
].m_Level
= m_Level
;
148 m_Items
[m_ItemsCnt
].m_ID
= m_ID
;
149 m_Items
[m_ItemsCnt
].m_Page
= new wxChar
[m_Page
.Length() + 1];
150 wxStrcpy(m_Items
[m_ItemsCnt
].m_Page
, m_Page
.c_str());
151 m_Items
[m_ItemsCnt
].m_Name
= new wxChar
[m_Name
.Length() + 1];
152 wxStrcpy(m_Items
[m_ItemsCnt
].m_Name
, m_Name
.c_str());
153 m_Items
[m_ItemsCnt
].m_Book
= m_Book
;
161 if (m_Name
== wxEmptyString
&& tag
.GetParam(wxT("NAME")) == wxT("Name"))
162 m_Name
= tag
.GetParam(wxT("VALUE"));
163 if (tag
.GetParam(wxT("NAME")) == wxT("Local"))
164 m_Page
= tag
.GetParam(wxT("VALUE"));
165 if (tag
.GetParam(wxT("NAME")) == wxT("ID"))
166 tag
.GetParamAsInt(wxT("VALUE"), &m_ID
);
173 void HP_TagHandler::WriteOut(wxHtmlContentsItem
*& array
, int& size
)
181 void HP_TagHandler::ReadIn(wxHtmlContentsItem
* array
, int size
)
190 //-----------------------------------------------------------------------------
192 //-----------------------------------------------------------------------------
194 wxString
wxHtmlBookRecord::GetFullPath(const wxString
&page
) const
196 if (wxIsAbsolutePath(page
))
199 return m_BasePath
+ page
;
204 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpData
, wxObject
)
206 wxHtmlHelpData::wxHtmlHelpData()
208 m_TempPath
= wxEmptyString
;
216 wxHtmlHelpData::~wxHtmlHelpData()
220 m_BookRecords
.Empty();
223 for (i
= 0; i
< m_ContentsCnt
; i
++)
225 delete[] m_Contents
[i
].m_Page
;
226 delete[] m_Contents
[i
].m_Name
;
232 for (i
= 0; i
< m_IndexCnt
; i
++)
234 delete[] m_Index
[i
].m_Page
;
235 delete[] m_Index
[i
].m_Name
;
241 bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
, const wxString
& indexfile
, const wxString
& contentsfile
)
249 HP_TagHandler
*handler
= new HP_TagHandler(book
);
250 parser
.AddTagHandler(handler
);
252 f
= ( contentsfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(contentsfile
) );
255 sz
= f
->GetStream()->GetSize();
256 buf
= new char[sz
+ 1];
258 f
->GetStream()->Read(buf
, sz
);
260 handler
->ReadIn(m_Contents
, m_ContentsCnt
);
262 handler
->WriteOut(m_Contents
, m_ContentsCnt
);
266 wxLogError(_("Cannot open contents file: %s"), contentsfile
.c_str());
268 f
= ( indexfile
.IsEmpty() ? (wxFSFile
*) NULL
: fsys
.OpenFile(indexfile
) );
271 sz
= f
->GetStream()->GetSize();
272 buf
= new char[sz
+ 1];
274 f
->GetStream()->Read(buf
, sz
);
276 handler
->ReadIn(m_Index
, m_IndexCnt
);
278 handler
->WriteOut(m_Index
, m_IndexCnt
);
281 else if (!indexfile
.IsEmpty())
282 wxLogError(_("Cannot open index file: %s"), indexfile
.c_str());
291 #define READ_STRING(f, s, lng) { char tmpc; for (int i = 0; i < lng; i++) { f->Read(&tmpc, 1); s[i] = (wxChar)tmpc;} }
292 #define WRITE_STRING(f, s, lng) { char tmpc; for (int i = 0; i < lng; i++) { tmpc = (char)s[i]; f->Write(&tmpc, 1);} }
296 #define READ_STRING(f, s, lng) f->Read(s, lng * sizeof(char));
297 #define WRITE_STRING(f, s, lng) f->Write(s, lng * sizeof(char));
302 #define CURRENT_CACHED_BOOK_VERSION 1
304 bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
)
310 /* load header - version info : */
312 f
->Read(&x
, sizeof(x
));
313 version
= wxINT32_SWAP_ON_BE(x
);
315 if (version
!= CURRENT_CACHED_BOOK_VERSION
)
317 wxLogError(_("Incorrect version of HTML help book"));
319 // NOTE: when adding new version, please ensure backward compatibility!
322 /* load contents : */
324 f
->Read(&x
, sizeof(x
));
326 m_ContentsCnt
+= wxINT32_SWAP_ON_BE(x
);
327 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
,
328 (m_ContentsCnt
/ wxHTML_REALLOC_STEP
+ 1) *
329 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
330 for (i
= st
; i
< m_ContentsCnt
; i
++)
332 f
->Read(&x
, sizeof(x
));
333 m_Contents
[i
].m_Level
= wxINT32_SWAP_ON_BE(x
);
334 f
->Read(&x
, sizeof(x
));
335 m_Contents
[i
].m_ID
= wxINT32_SWAP_ON_BE(x
);
336 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
337 m_Contents
[i
].m_Name
= new wxChar
[x
];
338 READ_STRING(f
, m_Contents
[i
].m_Name
, x
);
339 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
340 m_Contents
[i
].m_Page
= new wxChar
[x
];
341 READ_STRING(f
, m_Contents
[i
].m_Page
, x
);
342 m_Contents
[i
].m_Book
= book
;
347 f
->Read(&x
, sizeof(x
));
349 m_IndexCnt
+= wxINT32_SWAP_ON_BE(x
);
350 m_Index
= (wxHtmlContentsItem
*) realloc(m_Index
, (m_IndexCnt
/ wxHTML_REALLOC_STEP
+ 1) *
351 wxHTML_REALLOC_STEP
* sizeof(wxHtmlContentsItem
));
352 for (i
= st
; i
< m_IndexCnt
; i
++)
354 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
355 m_Index
[i
].m_Name
= new wxChar
[x
];
356 READ_STRING(f
, m_Index
[i
].m_Name
, x
);
357 f
->Read(&x
, sizeof(x
)); x
= wxINT32_SWAP_ON_BE(x
);
358 m_Index
[i
].m_Page
= new wxChar
[x
];
359 READ_STRING(f
, m_Index
[i
].m_Page
, x
);
360 m_Index
[i
].m_Book
= book
;
366 bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
)
371 /* save header - version info : */
373 x
= wxINT32_SWAP_ON_BE(CURRENT_CACHED_BOOK_VERSION
);
374 f
->Write(&x
, sizeof(x
));
376 /* save contents : */
379 for (i
= 0; i
< m_ContentsCnt
; i
++) if (m_Contents
[i
].m_Book
== book
&& m_Contents
[i
].m_Level
> 0) x
++;
380 x
= wxINT32_SWAP_ON_BE(x
);
381 f
->Write(&x
, sizeof(x
));
382 for (i
= 0; i
< m_ContentsCnt
; i
++)
384 if (m_Contents
[i
].m_Book
!= book
|| m_Contents
[i
].m_Level
== 0) continue;
385 x
= wxINT32_SWAP_ON_BE(m_Contents
[i
].m_Level
);
386 f
->Write(&x
, sizeof(x
));
387 x
= wxINT32_SWAP_ON_BE(m_Contents
[i
].m_ID
);
388 f
->Write(&x
, sizeof(x
));
389 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Contents
[i
].m_Name
) + 1);
390 f
->Write(&x
, sizeof(x
));
391 WRITE_STRING(f
, m_Contents
[i
].m_Name
, x
);
392 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Contents
[i
].m_Page
) + 1);
393 f
->Write(&x
, sizeof(x
));
394 WRITE_STRING(f
, m_Contents
[i
].m_Page
, x
);
400 for (i
= 0; i
< m_IndexCnt
; i
++) if (m_Index
[i
].m_Book
== book
&& m_Index
[i
].m_Level
> 0) x
++;
401 x
= wxINT32_SWAP_ON_BE(x
);
402 f
->Write(&x
, sizeof(x
));
403 for (i
= 0; i
< m_IndexCnt
; i
++)
405 if (m_Index
[i
].m_Book
!= book
|| m_Index
[i
].m_Level
== 0) continue;
406 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Index
[i
].m_Name
) + 1);
407 f
->Write(&x
, sizeof(x
));
408 WRITE_STRING(f
, m_Index
[i
].m_Name
, x
);
409 x
= wxINT32_SWAP_ON_BE(wxStrlen(m_Index
[i
].m_Page
) + 1);
410 f
->Write(&x
, sizeof(x
));
411 WRITE_STRING(f
, m_Index
[i
].m_Page
, x
);
417 void wxHtmlHelpData::SetTempDir(const wxString
& path
)
419 if (path
== wxEmptyString
) m_TempPath
= path
;
422 if (wxIsAbsolutePath(path
)) m_TempPath
= path
;
423 else m_TempPath
= wxGetCwd() + _T("/") + path
;
425 if (m_TempPath
[m_TempPath
.Length() - 1] != _T('/'))
426 m_TempPath
<< _T('/');
432 static wxString
SafeFileName(const wxString
& s
)
435 res
.Replace(wxT("#"), wxT("_"));
436 res
.Replace(wxT(":"), wxT("_"));
437 res
.Replace(wxT("\\"), wxT("_"));
438 res
.Replace(wxT("/"), wxT("_"));
442 bool wxHtmlHelpData::AddBookParam(const wxFSFile
& bookfile
,
443 wxFontEncoding encoding
,
444 const wxString
& title
, const wxString
& contfile
,
445 const wxString
& indexfile
, const wxString
& deftopic
,
446 const wxString
& path
)
450 wxHtmlBookRecord
*bookr
;
452 int IndexOld
= m_IndexCnt
,
453 ContentsOld
= m_ContentsCnt
;
455 if (! path
.IsEmpty())
456 fsys
.ChangePathTo(path
, TRUE
);
458 bookr
= new wxHtmlBookRecord(fsys
.GetPath(), title
, deftopic
);
460 if (m_ContentsCnt
% wxHTML_REALLOC_STEP
== 0)
461 m_Contents
= (wxHtmlContentsItem
*) realloc(m_Contents
, (m_ContentsCnt
+ wxHTML_REALLOC_STEP
) * sizeof(wxHtmlContentsItem
));
462 m_Contents
[m_ContentsCnt
].m_Level
= 0;
463 m_Contents
[m_ContentsCnt
].m_ID
= 0;
464 m_Contents
[m_ContentsCnt
].m_Page
= new wxChar
[deftopic
.Length() + 1];
465 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Page
, deftopic
.c_str());
466 m_Contents
[m_ContentsCnt
].m_Name
= new wxChar
[title
.Length() + 1];
467 wxStrcpy(m_Contents
[m_ContentsCnt
].m_Name
, title
.c_str());
468 m_Contents
[m_ContentsCnt
].m_Book
= bookr
;
470 // store the contents index for later
471 int cont_start
= m_ContentsCnt
++;
473 // Try to find cached binary versions:
474 // 1. save file as book, but with .hhp.cached extension
475 // 2. same as 1. but in temp path
476 // 3. otherwise or if cache load failed, load it from MS.
478 fi
= fsys
.OpenFile(bookfile
.GetLocation() + wxT(".cached"));
481 fi
->GetModificationTime() < bookfile
.GetModificationTime() ||
482 !LoadCachedBook(bookr
, fi
->GetStream()))
484 if (fi
!= NULL
) delete fi
;
485 fi
= fsys
.OpenFile(m_TempPath
+ wxFileNameFromPath(bookfile
.GetLocation()) + wxT(".cached"));
486 if (m_TempPath
== wxEmptyString
|| fi
== NULL
||
487 fi
->GetModificationTime() < bookfile
.GetModificationTime() ||
488 !LoadCachedBook(bookr
, fi
->GetStream()))
490 LoadMSProject(bookr
, fsys
, indexfile
, contfile
);
491 if (m_TempPath
!= wxEmptyString
)
493 wxFileOutputStream
*outs
= new wxFileOutputStream(m_TempPath
+
494 SafeFileName(wxFileNameFromPath(bookfile
.GetLocation())) + wxT(".cached"));
495 SaveCachedBook(bookr
, outs
);
501 if (fi
!= NULL
) delete fi
;
503 // Now store the contents range
504 bookr
->SetContentsRange(cont_start
, m_ContentsCnt
);
506 // Convert encoding, if neccessary:
507 if (encoding
!= wxFONTENCODING_SYSTEM
)
509 wxFontEncodingArray a
= wxEncodingConverter::GetPlatformEquivalents(encoding
);
510 if (a
.GetCount() != 0 && a
[0] != encoding
)
513 wxEncodingConverter conv
;
514 conv
.Init(encoding
, a
[0]);
516 for (i
= IndexOld
; i
< m_IndexCnt
; i
++)
517 conv
.Convert(m_Index
[i
].m_Name
);
518 for (i
= ContentsOld
; i
< m_ContentsCnt
; i
++)
519 conv
.Convert(m_Contents
[i
].m_Name
);
523 m_BookRecords
.Add(bookr
);
525 qsort(m_Index
, m_IndexCnt
, sizeof(wxHtmlContentsItem
), IndexCompareFunc
);
531 bool wxHtmlHelpData::AddBook(const wxString
& book
)
533 if (book
.Right(4).Lower() == wxT(".zip") ||
534 book
.Right(4).Lower() == wxT(".htb") /*html book*/)
541 s
= fsys
.FindFirst(book
+ wxT("#zip:") + wxT("*.hhp"), wxFILE
);
544 if (AddBook(s
)) rt
= TRUE
;
560 char *buff
, *lineptr
;
563 wxString title
= _("noname"),
565 start
= wxEmptyString
,
566 contents
= wxEmptyString
,
567 index
= wxEmptyString
,
568 charset
= wxEmptyString
;
570 if (wxIsAbsolutePath(book
)) bookFull
= book
;
571 else bookFull
= wxGetCwd() + "/" + book
;
573 fi
= fsys
.OpenFile(bookFull
);
576 wxLogError(_("Cannot open HTML help book: %s"), bookFull
.c_str());
579 fsys
.ChangePathTo(bookFull
);
582 buff
= new char[sz
+ 1];
588 lineptr
= ReadLine(lineptr
, linebuf
);
590 if (strstr(linebuf
, "Title=") == linebuf
)
591 title
= linebuf
+ strlen("Title=");
592 if (strstr(linebuf
, "Default topic=") == linebuf
)
593 start
= linebuf
+ strlen("Default topic=");
594 if (strstr(linebuf
, "Index file=") == linebuf
)
595 index
= linebuf
+ strlen("Index file=");
596 if (strstr(linebuf
, "Contents file=") == linebuf
)
597 contents
= linebuf
+ strlen("Contents file=");
598 if (strstr(linebuf
, "Charset=") == linebuf
)
599 charset
= linebuf
+ strlen("Charset=");
600 } while (lineptr
!= NULL
);
604 if (charset
== wxEmptyString
) enc
= wxFONTENCODING_SYSTEM
;
605 else enc
= wxTheFontMapper
->CharsetToEncoding(charset
);
606 bool rtval
= AddBookParam(*fi
, enc
,
607 title
, contents
, index
, start
, fsys
.GetPath());
613 wxString
wxHtmlHelpData::FindPageByName(const wxString
& x
)
619 wxString
url(wxEmptyString
);
621 /* 1. try to open given file: */
623 cnt
= m_BookRecords
.GetCount();
624 for (i
= 0; i
< cnt
; i
++)
626 f
= fsys
.OpenFile(m_BookRecords
[i
].GetFullPath(x
));
629 url
= m_BookRecords
[i
].GetFullPath(x
);
636 /* 2. try to find a book: */
638 for (i
= 0; i
< cnt
; i
++)
640 if (m_BookRecords
[i
].GetTitle() == x
)
642 url
= m_BookRecords
[i
].GetFullPath(m_BookRecords
[i
].GetStart());
647 /* 3. try to find in contents: */
650 for (i
= 0; i
< cnt
; i
++)
652 if (wxStrcmp(m_Contents
[i
].m_Name
, x
) == 0)
654 url
= m_Contents
[i
].GetFullPath();
660 /* 4. try to find in index: */
663 for (i
= 0; i
< cnt
; i
++)
665 if (wxStrcmp(m_Index
[i
].m_Name
, x
) == 0)
667 url
= m_Index
[i
].GetFullPath();
675 wxString
wxHtmlHelpData::FindPageById(int id
)
678 wxString
url(wxEmptyString
);
680 for (i
= 0; i
< m_ContentsCnt
; i
++)
682 if (m_Contents
[i
].m_ID
== id
)
684 url
= m_Contents
[i
].GetFullPath();
692 //----------------------------------------------------------------------------------
693 // wxHtmlSearchStatus functions
694 //----------------------------------------------------------------------------------
696 wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData
* data
, const wxString
& keyword
,
697 bool case_sensitive
, bool whole_words_only
,
698 const wxString
& book
)
702 wxHtmlBookRecord
* bookr
= NULL
;
703 if (book
!= wxEmptyString
)
705 // we have to search in a specific book. Find it first
706 int i
, cnt
= data
->m_BookRecords
.GetCount();
707 for (i
= 0; i
< cnt
; i
++)
708 if (data
->m_BookRecords
[i
].GetTitle() == book
)
710 bookr
= &(data
->m_BookRecords
[i
]);
711 m_CurIndex
= bookr
->GetContentsStart();
712 m_MaxIndex
= bookr
->GetContentsEnd();
715 // check; we won't crash if the book doesn't exist, but it's Bad Anyway.
720 // no book specified; search all books
722 m_MaxIndex
= m_Data
->m_ContentsCnt
;
724 m_Engine
.LookFor(keyword
, case_sensitive
, whole_words_only
);
725 m_Active
= (m_CurIndex
< m_MaxIndex
);
729 bool wxHtmlSearchStatus::Search()
732 int i
= m_CurIndex
; // shortcut
738 // sanity check. Illegal use, but we'll try to prevent a crash anyway
743 m_Name
= wxEmptyString
;
744 m_ContentsItem
= NULL
;
745 thepage
= m_Data
->m_Contents
[i
].m_Page
;
747 m_Active
= (++m_CurIndex
< m_MaxIndex
);
748 // check if it is same page with different anchor:
749 if (m_LastPage
!= NULL
)
752 for (p1
= thepage
, p2
= m_LastPage
;
753 *p1
!= 0 && *p1
!= _T('#') && *p1
== *p2
; p1
++, p2
++) {}
755 m_LastPage
= thepage
;
757 if (*p1
== 0 || *p1
== _T('#'))
760 else m_LastPage
= thepage
;
763 file
= fsys
.OpenFile(m_Data
->m_Contents
[i
].m_Book
->GetFullPath(thepage
));
766 if (m_Engine
.Scan(file
->GetStream()))
768 m_Name
= m_Data
->m_Contents
[i
].m_Name
;
769 m_ContentsItem
= m_Data
->m_Contents
+ i
;
784 //--------------------------------------------------------------------------------
786 //--------------------------------------------------------------------------------
788 void wxSearchEngine::LookFor(const wxString
& keyword
, bool case_sensitive
, bool whole_words_only
)
790 m_CaseSensitive
= case_sensitive
;
791 m_WholeWords
= whole_words_only
;
792 if (m_Keyword
) delete[] m_Keyword
;
793 m_Keyword
= new wxChar
[keyword
.Length() + 1];
794 wxStrcpy(m_Keyword
, keyword
.c_str());
796 if (!m_CaseSensitive
)
798 for (int i
= wxStrlen(m_Keyword
) - 1; i
>= 0; i
--)
800 if ((m_Keyword
[i
] >= wxT('A')) && (m_Keyword
[i
] <= wxT('Z')))
801 m_Keyword
[i
] += wxT('a') - wxT('A');
808 #define WHITESPACE(c) (c == ' ' || c == '\n' || c == '\r' || c == '\t')
810 bool wxSearchEngine::Scan(wxInputStream
*stream
)
812 wxASSERT_MSG(m_Keyword
!= NULL
, wxT("wxSearchEngine::LookFor must be called before scanning!"));
815 int lng
= stream
->GetSize();
816 int wrd
= wxStrlen(m_Keyword
);
818 char *buf
= new char[lng
+ 1];
819 stream
->Read(buf
, lng
);
822 if (!m_CaseSensitive
)
823 for (i
= 0; i
< lng
; i
++)
824 if ((buf
[i
] >= 'A') && (buf
[i
] <= 'Z')) buf
[i
] += 'a' - 'A';
828 for (i
= 0; i
< lng
- wrd
; i
++)
830 if (WHITESPACE(buf
[i
])) continue;
832 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
833 if (j
== wrd
&& WHITESPACE(buf
[i
+ j
])) { found
= TRUE
; break; }
839 for (i
= 0; i
< lng
- wrd
; i
++)
842 while ((j
< wrd
) && (buf
[i
+ j
] == m_Keyword
[j
])) j
++;
843 if (j
== wrd
) { found
= TRUE
; break; }