X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5ecdcaa78f1f7cd91a5335b74fc10ec875883992..92bbd64f7fc6d489fa7af1193feef7f3308da549:/src/html/helpdata.cpp diff --git a/src/html/helpdata.cpp b/src/html/helpdata.cpp index 312857dedf..e8b0e27bab 100644 --- a/src/html/helpdata.cpp +++ b/src/html/helpdata.cpp @@ -10,7 +10,7 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation +#pragma implementation "helpdata.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -48,17 +48,17 @@ WX_DEFINE_OBJARRAY(wxHtmlBookRecArray) //----------------------------------------------------------------------------- // Reads one line, stores it into buf and returns pointer to new line or NULL. -static char* ReadLine(char *line, char *buf, size_t bufsize) +static const wxChar* ReadLine(const wxChar *line, wxChar *buf, size_t bufsize) { - char *writeptr = buf; - char *endptr = buf + bufsize - 1; - char *readptr = line; + wxChar *writeptr = buf; + wxChar *endptr = buf + bufsize - 1; + const wxChar *readptr = line; - while (*readptr != 0 && *readptr != '\r' && *readptr != '\n' && + while (*readptr != 0 && *readptr != _T('\r') && *readptr != _T('\n') && writeptr != endptr) *(writeptr++) = *(readptr++); *writeptr = 0; - while (*readptr == '\r' || *readptr == '\n') + while (*readptr == _T('\r') || *readptr == _T('\n')) readptr++; if (*readptr == 0) return NULL; @@ -248,11 +248,13 @@ wxHtmlHelpData::~wxHtmlHelpData() } } +// defined in htmlfilt.cpp +void wxPrivate_ReadString(wxString& str, wxInputStream* s); + bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, const wxString& indexfile, const wxString& contentsfile) { wxFSFile *f; - char *buf; - int sz; + wxString buf; wxString string; HP_Parser parser; @@ -262,15 +264,12 @@ bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, c f = ( contentsfile.IsEmpty() ? (wxFSFile*) NULL : fsys.OpenFile(contentsfile) ); if (f) { - sz = f->GetStream()->GetSize(); - buf = new char[sz + 1]; - buf[sz] = 0; - f->GetStream()->Read(buf, sz); + buf.clear(); + wxPrivate_ReadString(buf, f->GetStream()); delete f; handler->ReadIn(m_Contents, m_ContentsCnt); parser.Parse(buf); handler->WriteOut(m_Contents, m_ContentsCnt); - delete[] buf; } else wxLogError(_("Cannot open contents file: %s"), contentsfile.c_str()); @@ -278,15 +277,12 @@ bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, c f = ( indexfile.IsEmpty() ? (wxFSFile*) NULL : fsys.OpenFile(indexfile) ); if (f) { - sz = f->GetStream()->GetSize(); - buf = new char[sz + 1]; - buf[sz] = 0; - f->GetStream()->Read(buf, sz); + buf.clear(); + wxPrivate_ReadString(buf, f->GetStream()); delete f; handler->ReadIn(m_Index, m_IndexCnt); parser.Parse(buf); handler->WriteOut(m_Index, m_IndexCnt); - delete[] buf; } else if (!indexfile.IsEmpty()) wxLogError(_("Cannot open index file: %s"), indexfile.c_str()); @@ -586,39 +582,35 @@ bool wxHtmlHelpData::AddBook(const wxString& book) fsys.ChangePathTo(bookFull); s = fi->GetStream(); - int sz; - char *buff, *lineptr; - char linebuf[300]; + const wxChar *lineptr; + wxChar linebuf[300]; + wxString tmp; - sz = s->GetSize(); - buff = new char[sz + 1]; - buff[sz] = 0; - s->Read(buff, sz); - lineptr = buff; + wxPrivate_ReadString(tmp, s); + lineptr = tmp.c_str(); do { lineptr = ReadLine(lineptr, linebuf, 300); - for (char *ch = linebuf; *ch != '\0' && *ch != '='; ch++) + for (wxChar *ch = linebuf; *ch != '\0' && *ch != '='; ch++) *ch = tolower(*ch); - if (strstr(linebuf, "title=") == linebuf) - title = linebuf + strlen("title="); - if (strstr(linebuf, "default topic=") == linebuf) - start = linebuf + strlen("default topic="); - if (strstr(linebuf, "index file=") == linebuf) - index = linebuf + strlen("index file="); - if (strstr(linebuf, "contents file=") == linebuf) - contents = linebuf + strlen("contents file="); - if (strstr(linebuf, "charset=") == linebuf) - charset = linebuf + strlen("charset="); + if (wxStrstr(linebuf, _T("title=")) == linebuf) + title = linebuf + wxStrlen(_T("title=")); + if (wxStrstr(linebuf, _T("default topic=")) == linebuf) + start = linebuf + wxStrlen(_T("default topic=")); + if (wxStrstr(linebuf, _T("index file=")) == linebuf) + index = linebuf + wxStrlen(_T("index file=")); + if (wxStrstr(linebuf, _T("contents file=")) == linebuf) + contents = linebuf + wxStrlen(_T("contents file=")); + if (wxStrstr(linebuf, _T("charset=")) == linebuf) + charset = linebuf + wxStrlen(_T("charset=")); } while (lineptr != NULL); - delete[] buff; wxFontEncoding enc; if (charset == wxEmptyString) enc = wxFONTENCODING_SYSTEM; - else enc = wxTheFontMapper->CharsetToEncoding(charset); + else enc = wxFontMapper::Get()->CharsetToEncoding(charset); bool rtval = AddBookParam(*fi, enc, title, contents, index, start, fsys.GetPath()); delete fi; @@ -820,24 +812,26 @@ void wxSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, bool } - -#define WHITESPACE(c) (c == ' ' || c == '\n' || c == '\r' || c == '\t') +static inline bool WHITESPACE(wxChar c) +{ + return c == _T(' ') || c == _T('\n') || c == _T('\r') || c == _T('\t'); +} bool wxSearchEngine::Scan(wxInputStream *stream) { wxASSERT_MSG(m_Keyword != NULL, wxT("wxSearchEngine::LookFor must be called before scanning!")); int i, j; - int lng = stream ->GetSize(); int wrd = wxStrlen(m_Keyword); bool found = FALSE; - char *buf = new char[lng + 1]; - stream->Read(buf, lng); - buf[lng] = 0; + wxString tmp; + wxPrivate_ReadString(tmp, stream); + int lng = tmp.length(); + const wxChar *buf = tmp.c_str(); if (!m_CaseSensitive) for (i = 0; i < lng; i++) - if ((buf[i] >= 'A') && (buf[i] <= 'Z')) buf[i] += 'a' - 'A'; + tmp[(size_t)i] = (wxChar)wxTolower(tmp[(size_t)i]); if (m_WholeWords) { @@ -860,7 +854,6 @@ bool wxSearchEngine::Scan(wxInputStream *stream) } } - delete[] buf; return found; }