summaryrefslogtreecommitdiff
path: root/tools/source/stream
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-01-24 16:44:15 +0000
committerCaolán McNamara <caolanm@redhat.com>2012-01-24 16:53:56 +0000
commit3ee84cb27e49d26acc50e235abafd7aa5e6a8c72 (patch)
treeb56bd4e9e21313746629461752196f624b012c46 /tools/source/stream
parent17ecf0036d44657b954de6c8f7efd536ab5c4809 (diff)
use write_uInt16s_FromOUString pattern
Diffstat (limited to 'tools/source/stream')
-rw-r--r--tools/source/stream/stream.cxx47
1 files changed, 30 insertions, 17 deletions
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index 11cfe33e766c..0e899050fced 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -856,21 +856,21 @@ rtl::OUString read_zeroTerminated_uInt8s_ToOUString(SvStream& rStream, rtl_TextE
read_zeroTerminated_uInt8s_ToOString(rStream), eEnc);
}
-/*************************************************************************
-|*
-|* Stream::WriteUnicodeText()
-|*
-*************************************************************************/
-
-sal_Bool SvStream::WriteUnicodeText( const String& rStr )
-{
- DBG_ASSERT( sizeof(sal_Unicode) == sizeof(sal_uInt16), "WriteUnicodeText: swapping sizeof(sal_Unicode) not implemented" );
- if ( bSwap )
+//Attempt to write a prefixed sequence of nUnits 16bit units from an OUString,
+//returned value is number of bytes written
+sal_Size write_uInt16s_FromOUString(SvStream& rStrm, const rtl::OUString& rStr,
+ sal_Size nUnits)
+{
+ DBG_ASSERT( sizeof(sal_Unicode) == sizeof(sal_uInt16), "write_uInt16s_FromOUString: swapping sizeof(sal_Unicode) not implemented" );
+ sal_Size nWritten;
+ if (!rStrm.IsEndianSwap())
+ nWritten = rStrm.Write( (char*)rStr.getStr(), nUnits * sizeof(sal_Unicode) );
+ else
{
- xub_StrLen nLen = rStr.Len();
+ sal_Size nLen = nUnits;
sal_Unicode aBuf[384];
sal_Unicode* const pTmp = ( nLen > 384 ? new sal_Unicode[nLen] : aBuf);
- memcpy( pTmp, rStr.GetBuffer(), nLen * sizeof(sal_Unicode) );
+ memcpy( pTmp, rStr.getStr(), nLen * sizeof(sal_Unicode) );
sal_Unicode* p = pTmp;
const sal_Unicode* const pStop = pTmp + nLen;
while ( p < pStop )
@@ -878,23 +878,36 @@ sal_Bool SvStream::WriteUnicodeText( const String& rStr )
SwapUShort( *p );
p++;
}
- Write( (char*)pTmp, nLen * sizeof(sal_Unicode) );
+ nWritten = rStrm.Write( (char*)pTmp, nLen * sizeof(sal_Unicode) );
if ( pTmp != aBuf )
delete [] pTmp;
}
- else
- Write( (char*)rStr.GetBuffer(), rStr.Len() * sizeof(sal_Unicode) );
+ return nWritten;
+}
+
+/*************************************************************************
+|*
+|* Stream::WriteUnicodeText()
+|*
+*************************************************************************/
+
+sal_Bool SvStream::WriteUnicodeText( const String& rStr )
+{
+ write_uInt16s_FromOUString(*this, rStr, rStr.Len());
return nError == SVSTREAM_OK;
}
sal_Bool SvStream::WriteUnicodeOrByteText( const String& rStr, rtl_TextEncoding eDestCharSet )
{
if ( eDestCharSet == RTL_TEXTENCODING_UNICODE )
- return WriteUnicodeText( rStr );
+ {
+ write_uInt16s_FromOUString(*this, rStr, rStr.Len());
+ return nError == SVSTREAM_OK;
+ }
else
{
rtl::OString aStr(rtl::OUStringToOString(rStr, eDestCharSet));
- Write(aStr.getStr(), aStr.getLength());
+ write_uInt8s_FromOString(*this, aStr, aStr.getLength());
return nError == SVSTREAM_OK;
}
}