From 3c9505fdff1c49495829a1d8116b023ee54ad291 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sat, 15 Jan 2011 06:36:14 +0200 Subject: [PATCH] Added CharData support in xml parser --- coding/internal/xmlparser.h | 15 ++++++++++++--- coding/parse_xml.hpp | 4 ++-- indexer/osm2type.cpp | 1 + indexer/xml_element.hpp | 1 + yg/skin_loader.hpp | 1 + 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/coding/internal/xmlparser.h b/coding/internal/xmlparser.h index fed55e3a2c..e079840018 100644 --- a/coding/internal/xmlparser.h +++ b/coding/internal/xmlparser.h @@ -12,8 +12,9 @@ class XmlParser : public CExpatImpl< XmlParser > public: typedef CExpatImpl< XmlParser > BaseT; - XmlParser(DispatcherT& dispatcher) - : m_depth(0), m_restrictDepth(-1), m_dispatcher(dispatcher) + XmlParser(DispatcherT& dispatcher, bool enableCharHandler = false) + : m_depth(0), m_restrictDepth(-1), m_dispatcher(dispatcher), + m_enableCharHandler(enableCharHandler) { } @@ -22,6 +23,8 @@ public: { // Enable all the event routines we want BaseT::EnableElementHandler(); + if (m_enableCharHandler) + BaseT::EnableCharacterDataHandler(); } // Start element handler @@ -55,10 +58,16 @@ public: } } + void OnCharacterData (const XML_Char *pszData, int nLength) + { + m_dispatcher.CharData(string(pszData, nLength)); + } + private: size_t m_depth; size_t m_restrictDepth; - DispatcherT& m_dispatcher; + DispatcherT & m_dispatcher; + bool m_enableCharHandler; }; #include "../../base/stop_mem_debug.hpp" diff --git a/coding/parse_xml.hpp b/coding/parse_xml.hpp index f2a610a960..e614cbe37a 100644 --- a/coding/parse_xml.hpp +++ b/coding/parse_xml.hpp @@ -9,10 +9,10 @@ static const size_t KMaxXMLFileBufferSize = 16384; template -bool ParseXML(SourceT & source, XMLDispatcherT & dispatcher) +bool ParseXML(SourceT & source, XMLDispatcherT & dispatcher, bool useCharData = false) { // Create the parser - XmlParser parser(dispatcher); + XmlParser parser(dispatcher, useCharData); if (!parser.Create()) return false; diff --git a/indexer/osm2type.cpp b/indexer/osm2type.cpp index e0bc33989e..453ae749d6 100644 --- a/indexer/osm2type.cpp +++ b/indexer/osm2type.cpp @@ -157,6 +157,7 @@ namespace ftype { public: OSMTypesStream() : m_priority(0), m_forceSkip(false) {} + void CharData(string const &) {} bool Push(string const & name) { if (!m_forceSkip && is_our_element(name)) diff --git a/indexer/xml_element.hpp b/indexer/xml_element.hpp index 314a34df36..966c0943bf 100644 --- a/indexer/xml_element.hpp +++ b/indexer/xml_element.hpp @@ -38,6 +38,7 @@ public: bool Push(string const & name); void AddAttr(string const & name, string const & value); void Pop(string const &); + void CharData(string const &) {} protected: virtual void EmitElement(XMLElement * p) = 0; diff --git a/yg/skin_loader.hpp b/yg/skin_loader.hpp index 55623d7c4b..c637e06acb 100644 --- a/yg/skin_loader.hpp +++ b/yg/skin_loader.hpp @@ -118,6 +118,7 @@ namespace yg bool Push(string const & element); void Pop(string const & element); void AddAttr(string const & attribute, string const & value); + void CharData(string const &) {} void popCharStyle(); void popGlyphInfo();