From d958e6d04983eb395b13b0d72aae5af550f9db9f Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Fri, 3 Oct 2014 16:37:26 +0200 Subject: FastSerializer: Simplify OUString write a bit more Change-Id: Ifa0746d635ec43cdc37867cf94bcc128bb8e2aca --- sax/source/tools/fastserializer.cxx | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'sax') diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx index cd8b0caed9c4..0f05ec9a3ff0 100644 --- a/sax/source/tools/fastserializer.cxx +++ b/sax/source/tools/fastserializer.cxx @@ -53,15 +53,6 @@ static const char sEqualSignAndQuote[] = "=\""; static const char sSpace[] = " "; static const char sXmlHeader[] = "\n"; -static bool lcl_isAscii(const OUString& sStr) -{ - for (sal_Int32 i = 0; i < sStr.getLength(); ++i) - if (sStr[i] & 0xff80) - return false; - - return true; -} - namespace sax_fastparser { FastSaxSerializer::FastSaxSerializer( const css::uno::Reference< css::io::XOutputStream >& xOutputStream ) : maCachedOutputStream() @@ -101,16 +92,16 @@ namespace sax_fastparser { void FastSaxSerializer::write( const OUString& sOutput, bool bEscape ) { - if (!lcl_isAscii(sOutput)) - { - write( OUStringToOString(sOutput, RTL_TEXTENCODING_UTF8), bEscape ); - return ; - } - - for (sal_Int32 i = 0; i < sOutput.getLength(); ++i) + const sal_Int32 nLength = sOutput.getLength(); + for (sal_Int32 i = 0; i < nLength; ++i) { - char c = sOutput[ i ]; - if (bEscape) switch( c ) + const sal_Unicode cUnicode = sOutput[ i ]; + const char cChar = cUnicode; + if (cUnicode & 0xff80) + { + write( OString(&cUnicode, 1, RTL_TEXTENCODING_UTF8) ); + } + else if(bEscape) switch( cChar ) { case '<': writeBytes( "<", 4 ); break; case '>': writeBytes( ">", 4 ); break; @@ -119,10 +110,10 @@ namespace sax_fastparser { case '"': writeBytes( """, 6 ); break; case '\n': writeBytes( " ", 5 ); break; case '\r': writeBytes( " ", 5 ); break; - default: writeBytes( &c, 1 ); break; + default: writeBytes( &cChar, 1 ); break; } else - writeBytes( &c, 1 ); + writeBytes( &cChar, 1 ); } } -- cgit