From a7a4d01bdbb5c23d8f2025072f66ca91d3657bf3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 27 Oct 1999 23:25:45 +0000 Subject: [PATCH] added wxHtmlParser::{Push|Pop}TagHandler git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4226 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/html/htmlpars.h | 20 +++++++++++++++++++- src/html/htmlpars.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/wx/html/htmlpars.h b/include/wx/html/htmlpars.h index bc098ba42b..acf972ff42 100644 --- a/include/wx/html/htmlpars.h +++ b/include/wx/html/htmlpars.h @@ -37,7 +37,7 @@ class WXDLLEXPORT wxHtmlParser : public wxObject DECLARE_ABSTRACT_CLASS(wxHtmlParser) public: - wxHtmlParser() : wxObject(), m_HandlersHash(wxKEY_STRING) {m_FS = NULL; m_Cache = NULL;} + wxHtmlParser() : wxObject(), m_HandlersHash(wxKEY_STRING) {m_FS = NULL; m_Cache = NULL; m_HandlersStack = NULL;} virtual ~wxHtmlParser(); void SetFS(wxFileSystem *fs) {m_FS = fs;} @@ -70,6 +70,22 @@ class WXDLLEXPORT wxHtmlParser : public wxObject virtual void AddTagHandler(wxHtmlTagHandler *handler); // adds handler to the list & hash table of handlers. + + void PushTagHandler(wxHtmlTagHandler *handler, wxString tags); + // Forces the handler to handle additional tags (not returned by GetSupportedTags). + // The handler should already be in use by this parser. + // Example: you want to parse following pseudo-html structure: + // + // + // + // + // This last it has different meaning, we don't want it to be parsed by myitems handler! + // handler can handle only 'myitems' (e.g. it's GetSupportedTags returns "MYITEMS") + // you can call PushTagHandler(handler, "IT") when you find + // and call PopTagHandler() when you find + + void PopTagHandler(); + // Restores state before last call to PushTagHandler wxString* GetSource() {return &m_Source;} @@ -117,6 +133,8 @@ class WXDLLEXPORT wxHtmlParser : public wxObject // only one reference to each handler instance. wxFileSystem *m_FS; // class for opening files (file system) + wxList *m_HandlersStack; + // handlers stack used by PushTagHandler and PopTagHandler }; diff --git a/src/html/htmlpars.cpp b/src/html/htmlpars.cpp index da21362a5e..1d9b99c7f6 100644 --- a/src/html/htmlpars.cpp +++ b/src/html/htmlpars.cpp @@ -148,8 +148,41 @@ void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler) +void wxHtmlParser::PushTagHandler(wxHtmlTagHandler *handler, wxString tags) +{ + wxStringTokenizer tokenizer(tags, ", "); + wxString key; + + if (m_HandlersStack == NULL) { + m_HandlersStack = new wxList; + m_HandlersStack -> DeleteContents(TRUE); + } + + m_HandlersStack -> Insert(new wxHashTable(m_HandlersHash)); + + 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) return; + m_HandlersHash = *((wxHashTable*) first -> GetData()); + m_HandlersStack -> DeleteNode(first); +} + + + wxHtmlParser::~wxHtmlParser() { + if (m_HandlersStack) delete m_HandlersStack; m_HandlersHash.Clear(); m_HandlersList.DeleteContents(TRUE); m_HandlersList.Clear(); -- 2.45.2