diff options
author | David Tardon <dtardon@redhat.com> | 2017-04-20 15:46:17 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2017-04-20 15:46:17 +0200 |
commit | 1fb548389f0bab6767bf0f656d15328bca0e35cf (patch) | |
tree | c8dbf6e43be98a28ffb89a0e43f6fb42ec2b06c5 | |
parent | 5115e1a1882e378133c024349a8d329d88ba64df (diff) |
move this from a separate source to ABXMLHelper
Change-Id: I6429111a974c51a35f778c02f11d653f5bc48fbb
-rw-r--r-- | src/lib/ABWParser.cpp | 1 | ||||
-rw-r--r-- | src/lib/ABWXMLHelper.cpp | 24 | ||||
-rw-r--r-- | src/lib/ABWXMLHelper.h | 18 | ||||
-rw-r--r-- | src/lib/ABWXMLString.cpp | 34 | ||||
-rw-r--r-- | src/lib/ABWXMLString.h | 38 | ||||
-rw-r--r-- | src/lib/Makefile.am | 2 |
6 files changed, 40 insertions, 77 deletions
diff --git a/src/lib/ABWParser.cpp b/src/lib/ABWParser.cpp index 514fa3f..3f77770 100644 --- a/src/lib/ABWParser.cpp +++ b/src/lib/ABWParser.cpp @@ -23,7 +23,6 @@ #include "ABWStylesCollector.h" #include "libabw_internal.h" #include "ABWXMLHelper.h" -#include "ABWXMLString.h" #include "ABWXMLTokenMap.h" diff --git a/src/lib/ABWXMLHelper.cpp b/src/lib/ABWXMLHelper.cpp index f3dff78..553155e 100644 --- a/src/lib/ABWXMLHelper.cpp +++ b/src/lib/ABWXMLHelper.cpp @@ -9,11 +9,14 @@ #include <string.h> #include <libxml/xmlIO.h> -#include <libxml/xmlstring.h> +#include <libxml/xmlmemory.h> #include <librevenge-stream/librevenge-stream.h> #include "ABWXMLHelper.h" #include "libabw_internal.h" +namespace libabw +{ + namespace { @@ -71,9 +74,24 @@ extern "C" { } // anonymous namespace +ABWXMLString::ABWXMLString(xmlChar *xml) + : m_xml(xml, xmlFree) +{ +} + +const xmlChar *ABWXMLString::get() const +{ + return m_xml.get(); +} + +ABWXMLString::operator const char *() const +{ + return reinterpret_cast<const char *>(m_xml.get()); +} + // xmlTextReader helper function -xmlTextReaderPtr libabw::xmlReaderForStream(librevenge::RVNGInputStream *input) +xmlTextReaderPtr xmlReaderForStream(librevenge::RVNGInputStream *input) { xmlTextReaderPtr reader = xmlReaderForIO(abwxmlInputReadFunc, abwxmlInputCloseFunc, (void *)input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET|XML_PARSE_RECOVER); @@ -81,4 +99,6 @@ xmlTextReaderPtr libabw::xmlReaderForStream(librevenge::RVNGInputStream *input) return reader; } +} + /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/ABWXMLHelper.h b/src/lib/ABWXMLHelper.h index 3febdb8..6008cad 100644 --- a/src/lib/ABWXMLHelper.h +++ b/src/lib/ABWXMLHelper.h @@ -10,12 +10,30 @@ #ifndef __ABWXMLHELPER_H__ #define __ABWXMLHELPER_H__ +#include <memory> + #include <librevenge-stream/librevenge-stream.h> + #include <libxml/xmlreader.h> +#include <libxml/xmlstring.h> namespace libabw { +// An exception-safe wrapper around xmlChar * +class ABWXMLString +{ +public: + ABWXMLString(xmlChar *xml); + + const xmlChar *get() const; + + operator const char *() const; + +private: + std::shared_ptr<xmlChar> m_xml; +}; + // create an xmlTextReader pointer from a librevenge::RVNGInputStream pointer // needs to be freed using xmlTextReaderFree function. diff --git a/src/lib/ABWXMLString.cpp b/src/lib/ABWXMLString.cpp deleted file mode 100644 index 00f9a43..0000000 --- a/src/lib/ABWXMLString.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * This file is part of the libabw project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include "ABWXMLString.h" - -#include <libxml/xmlmemory.h> - -namespace libabw -{ - -ABWXMLString::ABWXMLString(xmlChar *xml) - : m_xml(xml, xmlFree) -{ -} - -const xmlChar *ABWXMLString::get() const -{ - return m_xml.get(); -} - -ABWXMLString::operator const char *() const -{ - return reinterpret_cast<const char *>(m_xml.get()); -} - -} - -/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/ABWXMLString.h b/src/lib/ABWXMLString.h deleted file mode 100644 index ce679db..0000000 --- a/src/lib/ABWXMLString.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * This file is part of the libabw project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef __ABWXMLSTRING_H__ -#define __ABWXMLSTRING_H__ - -#include <memory> - -#include <libxml/xmlstring.h> - -namespace libabw -{ - -// An exception-safe wrapper around xmlChar * -class ABWXMLString -{ -public: - ABWXMLString(xmlChar *xml); - - const xmlChar *get() const; - - operator const char *() const; - -private: - std::shared_ptr<xmlChar> m_xml; -}; - -} - -#endif /* __ABWXMLSTRING_H__ */ - -/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index daeb7d9..1fe3d54 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -37,7 +37,6 @@ libabw_@ABW_MAJOR_VERSION@_@ABW_MINOR_VERSION@_la_SOURCES = \ ABWParser.cpp \ ABWStylesCollector.cpp \ ABWXMLHelper.cpp \ - ABWXMLString.cpp \ ABWXMLTokenMap.cpp \ ABWZlibStream.cpp \ AbiDocument.cpp \ @@ -49,7 +48,6 @@ libabw_@ABW_MAJOR_VERSION@_@ABW_MINOR_VERSION@_la_SOURCES = \ ABWParser.h \ ABWStylesCollector.h \ ABWXMLHelper.h \ - ABWXMLString.h \ ABWXMLTokenMap.h \ ABWZlibStream.h \ libabw_internal.h |