//-----------------------------------------------------------------------------
// 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)
}
}
+// 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;
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());
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());
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
{
if (strstr(linebuf, "charset=") == linebuf)
charset = linebuf + strlen("charset=");
} while (lineptr != NULL);
- delete[] buff;
wxFontEncoding enc;
if (charset == wxEmptyString) enc = wxFONTENCODING_SYSTEM;
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[i]);
if (m_WholeWords)
{
}
}
- delete[] buf;
return found;
}
#include "wx/html/htmlfilt.h"
#include "wx/html/htmlwin.h"
+// utility function: read a wxString from a wxInputStream
+void wxPrivate_ReadString(wxString& str, wxInputStream* s)
+{
+ size_t streamSize = s->GetSize();
+
+ if(streamSize == ~(size_t)0)
+ {
+ const size_t bufSize = 4095;
+ char buffer[bufSize+1];
+ size_t lastRead;
+
+ do
+ {
+ s->Read(buffer, bufSize);
+ lastRead = s->LastRead();
+ buffer[lastRead] = 0;
+ str.Append(buffer);
+ }
+ while(lastRead == bufSize);
+ }
+ else
+ {
+ char* src = new char[streamSize+1];
+ s->Read(src, streamSize);
+ src[streamSize] = 0;
+ str = src;
+ delete [] src;
+ }
+}
/*
wxString wxHtmlFilterPlainText::ReadFile(const wxFSFile& file) const
{
wxInputStream *s = file.GetStream();
- char *src;
wxString doc, doc2;
if (s == NULL) return wxEmptyString;
- src = new char[s->GetSize()+1];
- src[s->GetSize()] = 0;
- s->Read(src, s->GetSize());
- doc = src;
- delete [] src;
+ wxPrivate_ReadString(doc, s);
+ doc.Replace(wxT("&"), wxT("&"), TRUE);
doc.Replace(wxT("<"), wxT("<"), TRUE);
doc.Replace(wxT(">"), wxT(">"), TRUE);
doc2 = "<HTML><BODY><PRE>\n" + doc + "\n</PRE></BODY></HTML>";
wxString wxHtmlFilterHTML::ReadFile(const wxFSFile& file) const
{
wxInputStream *s = file.GetStream();
- char *src;
wxString doc;
if (s == NULL)
wxLogError(_("Cannot open HTML document: %s"), file.GetLocation().c_str());
return wxEmptyString;
}
- src = new char[s->GetSize() + 1];
- src[s->GetSize()] = 0;
- s->Read(src, s->GetSize());
- doc = src;
- delete[] src;
+ wxPrivate_ReadString(doc, s);
// add meta tag if we obtained this through http:
if (file.GetMimeType().Find(_T("; charset=")) == 0)
m_BasePathIsDir = isdir;
}
-
+// defined in htmlfilt.cpp
+void wxPrivate_ReadString(wxString& str, wxInputStream* s);
void wxHtmlPrintout::SetHtmlFile(const wxString& htmlfile)
{
}
wxInputStream *st = ff->GetStream();
- char *t = new char[st->GetSize() + 1];
- st->Read(t, st->GetSize());
- t[st->GetSize()] = 0;
+ wxString doc;
+ wxPrivate_ReadString(doc, st);
- wxString doc = wxString(t);
- delete t;
delete ff;
SetHtmlText(doc, htmlfile, FALSE);