X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/19bcc6049d33fd5812e6a1c0685d368fa98daa67..cbf656555e872684a74eb0badffe1aa33bedf95d:/src/html/htmlpars.cpp diff --git a/src/html/htmlpars.cpp b/src/html/htmlpars.cpp index 213bd0f75b..ab88ab7d46 100644 --- a/src/html/htmlpars.cpp +++ b/src/html/htmlpars.cpp @@ -51,27 +51,28 @@ wxObject* wxHtmlParser::Parse(const wxString& source) return result; } - - void wxHtmlParser::InitParser(const wxString& source) { - m_Source = source; - m_Cache = new wxHtmlTagsCache(m_Source); + SetSource(source); } - - - + void wxHtmlParser::DoneParser() { delete m_Cache; m_Cache = NULL; } - - +void wxHtmlParser::SetSource(const wxString& src) +{ + m_Source = src; + delete m_Cache; + m_Cache = new wxHtmlTagsCache(m_Source); +} void wxHtmlParser::DoParsing(int begin_pos, int end_pos) { + if (end_pos <= begin_pos) return; + char c; char *temp = new char[end_pos - begin_pos + 1]; int i; @@ -80,19 +81,23 @@ void wxHtmlParser::DoParsing(int begin_pos, int end_pos) templen = 0; i = begin_pos; - while (i < end_pos) { + while (i < end_pos) + { c = m_Source[(unsigned int) i]; // continue building word: - if (c != '<') { + if (c != '<') + { temp[templen++] = c; 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; @@ -103,15 +108,14 @@ 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; } - - void wxHtmlParser::AddTag(const wxHtmlTag& tag) { wxHtmlTagHandler *h; @@ -119,18 +123,17 @@ 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()); } } - - void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler) { - wxString s(handler -> GetSupportedTags()); + wxString s(handler->GetSupportedTags()); wxStringTokenizer tokenizer(s, ", "); while (tokenizer.HasMoreTokens()) @@ -139,48 +142,44 @@ void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler) if (m_HandlersList.IndexOf(handler) == wxNOT_FOUND) m_HandlersList.Append(handler); - handler -> SetParser(this); + handler->SetParser(this); } - - 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); } } - - void wxHtmlParser::PopTagHandler() { wxNode *first; if (m_HandlersStack == NULL || - (first = m_HandlersStack -> GetFirst()) == 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); + m_HandlersHash = *((wxHashTable*) first->GetData()); + m_HandlersStack->DeleteNode(first); } - - wxHtmlParser::~wxHtmlParser() { if (m_HandlersStack) delete m_HandlersStack; @@ -189,8 +188,6 @@ wxHtmlParser::~wxHtmlParser() m_HandlersList.Clear(); } - - //----------------------------------------------------------------------------- // wxHtmlTagHandler //-----------------------------------------------------------------------------