X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a7a4d01bdbb5c23d8f2025072f66ca91d3657bf3..4817645de8ac9590977e429925a790aafb3b2e5b:/src/html/htmlpars.cpp diff --git a/src/html/htmlpars.cpp b/src/html/htmlpars.cpp index 1d9b99c7f6..17fb0afb1c 100644 --- a/src/html/htmlpars.cpp +++ b/src/html/htmlpars.cpp @@ -12,17 +12,17 @@ #pragma implementation #endif -#include +#include "wx/wxprec.h" #include "wx/defs.h" -#if wxUSE_HTML +#if wxUSE_HTML && wxUSE_STREAMS #ifdef __BORDLANDC__ #pragma hdrstop #endif #ifndef WXPRECOMP -#include +#include "wx/wx.h" #endif #include "wx/tokenzr.h" @@ -69,35 +69,36 @@ void wxHtmlParser::DoneParser() -#define wxHTML_MAX_BUFLEN 1024 void wxHtmlParser::DoParsing(int begin_pos, int end_pos) { - char temp[wxHTML_BUFLEN], c; + if (end_pos <= begin_pos) return; + + char c; + char *temp = new char[end_pos - begin_pos + 1]; int i; int templen; templen = 0; i = begin_pos; - while (i < end_pos) { - c = m_Source[i]; + while (i < end_pos) + { + c = m_Source[(unsigned int) i]; // continue building word: - if (c != '<') { + if (c != '<') + { temp[templen++] = c; - if (templen == wxHTML_BUFLEN-1) { - temp[templen] = 0; - AddText(temp); - templen = 0; - } i++; } - else if (c == '<') { + else if (c == '<') + { wxHtmlTag tag(m_Source, i, end_pos, m_Cache); - if (templen) { + if (templen) + { temp[templen] = 0; AddText(temp); templen = 0; @@ -108,10 +109,12 @@ void wxHtmlParser::DoParsing(int begin_pos, int end_pos) } } - if (templen) { // last word of block :-( + if (templen) + { // last word of block :-( temp[templen] = 0; AddText(temp); } + delete[] temp; } @@ -123,8 +126,9 @@ void wxHtmlParser::AddTag(const wxHtmlTag& tag) h = (wxHtmlTagHandler*) m_HandlersHash.Get(tag.GetName()); if (h) - inner = h -> HandleTag(tag); - if (!inner) { + inner = h->HandleTag(tag); + if (!inner) + { if (tag.HasEnding()) DoParsing(tag.GetBeginPos(), tag.GetEndPos1()); } @@ -134,7 +138,7 @@ void wxHtmlParser::AddTag(const wxHtmlTag& tag) void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler) { - wxString s(handler -> GetSupportedTags()); + wxString s(handler->GetSupportedTags()); wxStringTokenizer tokenizer(s, ", "); while (tokenizer.HasMoreTokens()) @@ -143,7 +147,7 @@ void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler) if (m_HandlersList.IndexOf(handler) == wxNOT_FOUND) m_HandlersList.Append(handler); - handler -> SetParser(this); + handler->SetParser(this); } @@ -153,14 +157,16 @@ void wxHtmlParser::PushTagHandler(wxHtmlTagHandler *handler, wxString tags) wxStringTokenizer tokenizer(tags, ", "); wxString key; - if (m_HandlersStack == NULL) { + if (m_HandlersStack == NULL) + { m_HandlersStack = new wxList; - m_HandlersStack -> DeleteContents(TRUE); + m_HandlersStack->DeleteContents(TRUE); } - m_HandlersStack -> Insert(new wxHashTable(m_HandlersHash)); + m_HandlersStack->Insert(new wxHashTable(m_HandlersHash)); - while (tokenizer.HasMoreTokens()) { + while (tokenizer.HasMoreTokens()) + { key = tokenizer.NextToken(); m_HandlersHash.Delete(key); m_HandlersHash.Put(key, handler); @@ -173,9 +179,14 @@ void wxHtmlParser::PopTagHandler() { wxNode *first; - if (m_HandlersStack == NULL || (first = m_HandlersStack -> GetFirst()) == NULL) return; - m_HandlersHash = *((wxHashTable*) first -> GetData()); - m_HandlersStack -> DeleteNode(first); + if (m_HandlersStack == NULL || + (first = m_HandlersStack->GetFirst()) == NULL) + { + wxLogWarning(_("Warning: attempt to remove HTML tag handler from empty stack.")); + return; + } + m_HandlersHash = *((wxHashTable*) first->GetData()); + m_HandlersStack->DeleteNode(first); }