summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-09-26 15:08:17 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-10-23 11:53:16 +0200
commit8dc668999a9fea8c6fe8acb84dbe1588f670fd78 (patch)
tree83497e540f718f289930b7df50c440277ff288fe /sax
parent6be21256bdca3d1d1e32b0abec53ba9695ea5808 (diff)
FastSerializer: Remove escapeXml() creating OUString(Buffer)
Instead directly write the content. Change-Id: I7b6db925348b879a013acbd2a76a80d590f721c0
Diffstat (limited to 'sax')
-rw-r--r--sax/source/tools/fastserializer.cxx62
-rw-r--r--sax/source/tools/fastserializer.hxx7
-rw-r--r--sax/source/tools/fshelper.cxx6
3 files changed, 40 insertions, 35 deletions
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( "&lt;" ); break;
- case '>': sBuf.appendAscii( "&gt;" ); break;
- case '&': sBuf.appendAscii( "&amp;" ); break;
- case '\'': sBuf.appendAscii( "&apos;" ); break;
- case '"': sBuf.appendAscii( "&quot;" ); break;
- case '\n': sBuf.appendAscii( "&#10;" ); break;
- case '\r': sBuf.appendAscii( "&#13;" ); break;
- default: sBuf.append( c ); break;
+ case '<': writeBytes( "&lt;", 4 ); break;
+ case '>': writeBytes( "&gt;", 4 ); break;
+ case '&': writeBytes( "&amp;", 5 ); break;
+ case '\'': writeBytes( "&apos;", 6 ); break;
+ case '"': writeBytes( "&quot;", 6 ); break;
+ case '\n': writeBytes( "&#10;", 5 ); break;
+ case '\r': writeBytes( "&#13;", 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<const sal_Int8*>(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)