X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fc7995487f3032d8415f87619efac7c391c72730..4c0c8053346f8d81a6ef9e0122eab16b3cf487cd:/src/html/helpdata.cpp diff --git a/src/html/helpdata.cpp b/src/html/helpdata.cpp index 59cdca10d4..7baaa8f2a9 100644 --- a/src/html/helpdata.cpp +++ b/src/html/helpdata.cpp @@ -48,11 +48,11 @@ 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 char* ReadLine(const char *line, char *buf, size_t bufsize) { char *writeptr = buf; char *endptr = buf + bufsize - 1; - char *readptr = line; + const char *readptr = line; while (*readptr != 0 && *readptr != '\r' && *readptr != '\n' && writeptr != endptr) @@ -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()); @@ -439,25 +435,6 @@ static wxString SafeFileName(const wxString& s) return res; } -bool wxHtmlHelpData::AlreadyHasBook(wxHtmlBookRecord * bookr) -{ - size_t bookCount = m_BookRecords.GetCount(); - if (bookCount == 0) return FALSE ; - - wxHtmlBookRecord currentBook(wxEmptyString,wxEmptyString,wxEmptyString); - size_t i; - for (i=0; iGetBasePath()) && - currentBook.GetTitle().IsSameAs(bookr->GetTitle()) && - currentBook.GetStart().IsSameAs(bookr->GetStart()) ) - return TRUE ; - - } - return FALSE ; -} - bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, wxFontEncoding encoding, const wxString& title, const wxString& contfile, @@ -471,12 +448,17 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, int IndexOld = m_IndexCnt, ContentsOld = m_ContentsCnt; - if (! path.IsEmpty()) + if (!path.IsEmpty()) fsys.ChangePathTo(path, TRUE); - bookr = new wxHtmlBookRecord(fsys.GetPath(), title, deftopic); - // return TRUE to indicate book is loaded - if (AlreadyHasBook(bookr)) return TRUE ; + size_t booksCnt = m_BookRecords.GetCount(); + for (size_t i = 0; i < booksCnt; i++) + { + if ( m_BookRecords[i].GetBookFile() == bookfile.GetLocation() ) + return TRUE; // book is (was) loaded + } + + bookr = new wxHtmlBookRecord(bookfile.GetLocation(), fsys.GetPath(), title, deftopic); if (m_ContentsCnt % wxHTML_REALLOC_STEP == 0) m_Contents = (wxHtmlContentsItem*) realloc(m_Contents, (m_ContentsCnt + wxHTML_REALLOC_STEP) * sizeof(wxHtmlContentsItem)); @@ -600,15 +582,12 @@ bool wxHtmlHelpData::AddBook(const wxString& book) fsys.ChangePathTo(bookFull); s = fi->GetStream(); - int sz; - char *buff, *lineptr; + const char *lineptr; char 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 { @@ -628,11 +607,10 @@ bool wxHtmlHelpData::AddBook(const wxString& book) if (strstr(linebuf, "charset=") == linebuf) charset = linebuf + strlen("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; @@ -842,16 +820,16 @@ 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 char *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] = (char)tolower(tmp[(size_t)i]); if (m_WholeWords) { @@ -874,7 +852,6 @@ bool wxSearchEngine::Scan(wxInputStream *stream) } } - delete[] buf; return found; }