diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-10-15 15:48:30 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-10-17 16:06:27 +0100 |
commit | 794a7c67e89be302cb65ea95d7b12a1da34839c0 (patch) | |
tree | 027c7c9160785a4d8c0f4a3fecbf4ee92893457f /xmlreader | |
parent | 239847102b632a4976f50d99b38b3c79b95e56aa (diff) |
allow XmlReader to parse a string
Change-Id: I3433e6f3766c1ea54ad53896c4e4d142d1e319a5
Diffstat (limited to 'xmlreader')
-rw-r--r-- | xmlreader/inc/xmlreader/xmlreader.hxx | 6 | ||||
-rw-r--r-- | xmlreader/source/xmlreader.cxx | 23 |
2 files changed, 27 insertions, 2 deletions
diff --git a/xmlreader/inc/xmlreader/xmlreader.hxx b/xmlreader/inc/xmlreader/xmlreader.hxx index b6de02734e84..1d3faf05c0c2 100644 --- a/xmlreader/inc/xmlreader/xmlreader.hxx +++ b/xmlreader/inc/xmlreader/xmlreader.hxx @@ -44,6 +44,10 @@ public: com::sun::star::container::NoSuchElementException, com::sun::star::uno::RuntimeException)); + //string is not copied so must persist for lifetime + //of XmlReader + explicit XmlReader(const char * str, sal_uInt64 len) SAL_THROW(()); + ~XmlReader(); enum { NAMESPACE_NONE = -2, NAMESPACE_UNKNOWN = -1, NAMESPACE_XML = 0 }; @@ -170,6 +174,8 @@ private: SAL_DLLPRIVATE int toNamespaceId(NamespaceIris::size_type pos); + SAL_DLLPRIVATE void init(); + rtl::OUString fileUrl_; oslFileHandle fileHandle_; sal_uInt64 fileSize_; diff --git a/xmlreader/source/xmlreader.cxx b/xmlreader/source/xmlreader.cxx index fcf6e157a246..e297cd176c53 100644 --- a/xmlreader/source/xmlreader.cxx +++ b/xmlreader/source/xmlreader.cxx @@ -96,19 +96,38 @@ XmlReader::XmlReader(rtl::OUString const & fileUrl) rtl::OUString::valueOf(static_cast< sal_Int32 >(e)) + ")"), css::uno::Reference< css::uno::XInterface >()); } + init(); + pos_ = static_cast< char * >(fileAddress_); + end_ = pos_ + fileSize_; +} + +XmlReader::XmlReader(const char * str, sal_uInt64 len) + SAL_THROW(()) + : fileHandle_(NULL) + , fileSize_(len) + , fileAddress_(NULL) +{ + init(); + pos_ = str; + end_ = pos_ + fileSize_; +} + +void XmlReader::init() +{ namespaceIris_.push_back( Span( RTL_CONSTASCII_STRINGPARAM( "http://www.w3.org/XML/1998/namespace"))); namespaces_.push_back( NamespaceData(Span(RTL_CONSTASCII_STRINGPARAM("xml")), NAMESPACE_XML)); - pos_ = static_cast< char * >(fileAddress_); - end_ = pos_ + fileSize_; state_ = STATE_CONTENT; firstAttribute_ = true; } XmlReader::~XmlReader() { + if (!fileHandle_) + return; + oslFileError e = osl_unmapMappedFile(fileHandle_, fileAddress_, fileSize_); if (e != osl_File_E_None) { SAL_WARN( |