From 8dc668999a9fea8c6fe8acb84dbe1588f670fd78 Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Fri, 26 Sep 2014 15:08:17 +0200 Subject: FastSerializer: Remove escapeXml() creating OUString(Buffer) Instead directly write the content. Change-Id: I7b6db925348b879a013acbd2a76a80d590f721c0 --- sax/source/tools/fastserializer.cxx | 62 ++++++++++++++++++++----------------- sax/source/tools/fastserializer.hxx | 7 ++--- sax/source/tools/fshelper.cxx | 6 ++-- 3 files changed, 40 insertions(+), 35 deletions(-) (limited to 'sax') diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx index 56b27af7e82d..300c0d3f56cc 100644 --- a/sax/source/tools/fastserializer.cxx +++ b/sax/source/tools/fastserializer.cxx @@ -76,39 +76,36 @@ namespace sax_fastparser { writeBytes(toUnoSequence(aXmlHeader)); } - OUString FastSaxSerializer::escapeXml( const OUString& s ) + void FastSaxSerializer::write( const OUString& sOutput, bool bEscape ) { - OUStringBuffer sBuf( s.getLength() ); - const sal_Unicode* pStr = s.getStr(); - sal_Int32 nLen = s.getLength(); - for( sal_Int32 i = 0; i < nLen; ++i) + write( OUStringToOString(sOutput, RTL_TEXTENCODING_UTF8), bEscape ); + } + + void FastSaxSerializer::write( const OString& sOutput, bool bEscape ) + { + if (!bEscape) { - sal_Unicode c = pStr[ i ]; + writeBytes( sOutput.getStr(), sOutput.getLength() ); + return; + } + + const char* pStr = sOutput.getStr(); + sal_Int32 nLen = sOutput.getLength(); + for (sal_Int32 i = 0; i < nLen; ++i) + { + char c = pStr[ i ]; switch( c ) { - case '<': sBuf.appendAscii( "<" ); break; - case '>': sBuf.appendAscii( ">" ); break; - case '&': sBuf.appendAscii( "&" ); break; - case '\'': sBuf.appendAscii( "'" ); break; - case '"': sBuf.appendAscii( """ ); break; - case '\n': sBuf.appendAscii( " " ); break; - case '\r': sBuf.appendAscii( " " ); break; - default: sBuf.append( c ); break; + case '<': writeBytes( "<", 4 ); break; + case '>': writeBytes( ">", 4 ); break; + case '&': writeBytes( "&", 5 ); break; + case '\'': writeBytes( "'", 6 ); break; + case '"': writeBytes( """, 6 ); break; + case '\n': writeBytes( " ", 5 ); break; + case '\r': writeBytes( " ", 5 ); break; + default: writeBytes( &c, 1 ); break; } } - return sBuf.makeStringAndClear(); - } - - void FastSaxSerializer::write( const OUString& sOutput ) - { - write( OUStringToOString(sOutput, RTL_TEXTENCODING_UTF8) ); - } - - void FastSaxSerializer::write( const OString& sOutput ) - { - writeBytes( Sequence< sal_Int8 >( - reinterpret_cast< const sal_Int8*>( sOutput.getStr() ), - sOutput.getLength() ) ); } void SAL_CALL FastSaxSerializer::endDocument( ) throw (SAXException, RuntimeException) @@ -226,7 +223,7 @@ namespace sax_fastparser { #endif write(rAttrName); writeBytes(toUnoSequence(maEqualSignAndQuote)); - write(escapeXml(pAttr[i].Value)); + write(pAttr[i].Value, true); writeBytes(toUnoSequence(maQuote)); } @@ -250,7 +247,7 @@ namespace sax_fastparser { writeBytes(toUnoSequence(maEqualSignAndQuote)); - write(escapeXml(pFastAttr[j].Value)); + write(pFastAttr[j].Value, true); writeBytes(toUnoSequence(maQuote)); } @@ -295,6 +292,13 @@ namespace sax_fastparser { } } + void FastSaxSerializer::writeBytes( const char* pStr, size_t nLen ) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) + { + writeBytes( Sequence< sal_Int8 >( + reinterpret_cast(pStr), nLen) ); + } + void FastSaxSerializer::writeBytes( const Sequence< ::sal_Int8 >& aData ) throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { if ( maMarkStack.empty() ) diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx index d754b98fbdb1..bf27abcf773c 100644 --- a/sax/source/tools/fastserializer.hxx +++ b/sax/source/tools/fastserializer.hxx @@ -110,10 +110,8 @@ public: void SAL_CALL writeId( ::sal_Int32 Element ); OString SAL_CALL getId( ::sal_Int32 Element ); - void write( const OUString& s ); - void write( const OString& s ); - - static OUString escapeXml( const OUString& s ); + void write( const OUString& s, bool bEscape = false ); + void write( const OString& s, bool bEscape = false ); public: /** From now on, don't write directly to the stream, but to top of a stack. @@ -233,6 +231,7 @@ protected: The latter in the case that we are inside a mark(). */ void writeBytes( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + void writeBytes( const char* pStr, size_t nLen ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); }; } // namespace sax_fastparser diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx index cb2c7f7af6ff..0e5df2819378 100644 --- a/sax/source/tools/fshelper.cxx +++ b/sax/source/tools/fshelper.cxx @@ -139,12 +139,14 @@ FastSerializerHelper* FastSerializerHelper::write(double value) FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value) { - return writeEscaped(OUString::createFromAscii(value)); + mpSerializer->write(OString(value), true); + return this; } FastSerializerHelper* FastSerializerHelper::writeEscaped(const OUString& value) { - return write(FastSaxSerializer::escapeXml(value)); + mpSerializer->write(value, true); + return this; } FastSerializerHelper* FastSerializerHelper::writeId(sal_Int32 tokenId) -- cgit