diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-12-17 15:53:11 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-12-21 10:10:58 +0000 |
commit | 92f396733ebc518bcb7a9eae2dd3169d333b82b9 (patch) | |
tree | 55cf13dea05f06d4eea95c8382f771090a3bac4b /tools/source/stream | |
parent | b57eceb231b61abc7121686d70df8d7c0dfacb75 (diff) |
convert ReadByteString/WriteByteString from ByteString to OString
Nobody ever used the return values anyway, so for reading just
return the string and for writing the number of bytes written
Doesn't need to be members, make standalone functions
Rename to
read_lenPrefixed_uInt8s_ToO[U]String and
write_lenPrefixed_uInt8s_FromO[U]String, lengthy,
but much less unambiguous, seeing as a lot of users of it don't
seem to be aware that they read/write pascal-style length
prefixed strings, which isn't surprising given the
apparent simplicity of their original name.
added a unit test
Diffstat (limited to 'tools/source/stream')
-rw-r--r-- | tools/source/stream/stream.cxx | 36 |
1 files changed, 7 insertions, 29 deletions
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index 5fa5b0e43380..b70195978008 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -806,7 +806,7 @@ sal_Bool SvStream::ReadUniOrByteStringLine( String& rStr, rtl_TextEncoding eSrcC return ReadByteStringLine( rStr, eSrcCharSet ); } -rtl::OString read_zeroTerminated_uInt8s_AsOString(SvStream& rStream) +rtl::OString read_zeroTerminated_uInt8s_ToOString(SvStream& rStream) { rtl::OStringBuffer aOutput; @@ -839,10 +839,10 @@ rtl::OString read_zeroTerminated_uInt8s_AsOString(SvStream& rStream) return aOutput.makeStringAndClear(); } -rtl::OUString read_zeroTerminated_uInt8s_AsOUString(SvStream& rStream, rtl_TextEncoding eEnc) +rtl::OUString read_zeroTerminated_uInt8s_ToOUString(SvStream& rStream, rtl_TextEncoding eEnc) { return rtl::OStringToOUString( - read_zeroTerminated_uInt8s_AsOString(rStream), eEnc); + read_zeroTerminated_uInt8s_ToOString(rStream), eEnc); } /************************************************************************* @@ -1517,19 +1517,7 @@ SvStream& SvStream::ReadByteString( UniString& rStr, rtl_TextEncoding eSrcCharSe return *this; } - ByteString aStr; - ReadByteString( aStr ); - rStr = UniString( aStr, eSrcCharSet ); - return *this; -} - -// ----------------------------------------------------------------------- - -SvStream& SvStream::ReadByteString( ByteString& rStr ) -{ - sal_uInt16 nLen = 0; - operator>>( nLen ); - rStr = read_uInt8s_AsOString(*this, nLen); + rStr = read_lenPrefixed_uInt8s_ToOUString(*this, eSrcCharSet); return *this; } @@ -1563,17 +1551,7 @@ SvStream& SvStream::WriteByteString( const UniString& rStr, rtl_TextEncoding eDe return *this; } - return WriteByteString(rtl::OUStringToOString(rStr, eDestCharSet)); -} - -// ----------------------------------------------------------------------- - -SvStream& SvStream::WriteByteString( const ByteString& rStr) -{ - sal_uInt16 nLen = rStr.Len(); - operator<< ( nLen ); - if( nLen != 0 ) - Write( rStr.GetBuffer(), nLen ); + write_lenPrefixed_uInt8s_FromOUString(*this, rStr, eDestCharSet); return *this; } @@ -2454,7 +2432,7 @@ void SvDataCopyStream::Assign( const SvDataCopyStream& ) } //Create a OString of nLen bytes from rStream -rtl::OString read_uInt8s_AsOString(SvStream& rStrm, sal_Size nLen) +rtl::OString read_uInt8s_ToOString(SvStream& rStrm, sal_Size nLen) { using comphelper::string::rtl_string_alloc; @@ -2481,7 +2459,7 @@ rtl::OString read_uInt8s_AsOString(SvStream& rStrm, sal_Size nLen) } //Create a OUString of nLen little endian sal_Unicodes from rStream -rtl::OUString read_LEuInt16s_AsOUString(SvStream& rStrm, sal_Size nLen) +rtl::OUString read_LEuInt16s_ToOUString(SvStream& rStrm, sal_Size nLen) { using comphelper::string::rtl_uString_alloc; |