diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-12-21 10:44:56 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-12-21 13:44:52 +0000 |
commit | c4f0efc2378cebc3b581bc949da70a2b2f149961 (patch) | |
tree | 3c0a330f7811c9407a787cec45382993b4037a6f /svtools/source/misc/imap.cxx | |
parent | 073431d26d39216a7f5f85489ecd4eb60806ee88 (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 'svtools/source/misc/imap.cxx')
-rw-r--r-- | svtools/source/misc/imap.cxx | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/svtools/source/misc/imap.cxx b/svtools/source/misc/imap.cxx index 016250c23c8c..bb720f6838e7 100644 --- a/svtools/source/misc/imap.cxx +++ b/svtools/source/misc/imap.cxx @@ -104,16 +104,16 @@ void IMapObject::Write( SvStream& rOStm, const String& rBaseURL ) const const rtl::OString aRelURL = rtl::OUStringToOString( URIHelper::simpleNormalizedMakeRelative(rBaseURL, aURL), eEncoding); - rOStm.WriteByteString(aRelURL); - rOStm.WriteByteString(rtl::OUStringToOString(aAltText, eEncoding)); + write_lenPrefixed_uInt8s_FromOString(rOStm, aRelURL); + write_lenPrefixed_uInt8s_FromOUString(rOStm, aAltText, eEncoding); rOStm << bActive; - rOStm.WriteByteString(rtl::OUStringToOString(aTarget, eEncoding)); + write_lenPrefixed_uInt8s_FromOUString(rOStm, aTarget, eEncoding); pCompat = new IMapCompat( rOStm, STREAM_WRITE ); WriteIMapObject( rOStm ); - aEventList.Write( rOStm ); // V4 - rOStm.WriteByteString(rtl::OUStringToOString(aName, eEncoding)); // V5 + aEventList.Write( rOStm ); // V4 + write_lenPrefixed_uInt8s_FromOUString(rOStm, aName, eEncoding); // V5 delete pCompat; } @@ -129,16 +129,15 @@ void IMapObject::Read( SvStream& rIStm, const String& rBaseURL ) { IMapCompat* pCompat; rtl_TextEncoding nTextEncoding; - ByteString aString; // Typ und Version ueberlesen wir rIStm.SeekRel( 2 ); rIStm >> nReadVersion; rIStm >> nTextEncoding; - rIStm.ReadByteString( aString ); aURL = String( aString.GetBuffer(), nTextEncoding ); - rIStm.ReadByteString( aString ); aAltText = String( aString.GetBuffer(), nTextEncoding ); + aURL = read_lenPrefixed_uInt8s_ToOUString(rIStm, nTextEncoding); + aAltText = read_lenPrefixed_uInt8s_ToOUString(rIStm, nTextEncoding); rIStm >> bActive; - rIStm.ReadByteString( aString ); aTarget = String( aString.GetBuffer(), nTextEncoding ); + aTarget = read_lenPrefixed_uInt8s_ToOUString(rIStm, nTextEncoding); // URL absolut machen aURL = URIHelper::SmartRel2Abs( INetURLObject(rBaseURL), aURL, URIHelper::GetMaybeFileHdl(), true, false, INetURLObject::WAS_ENCODED, INetURLObject::DECODE_UNAMBIGUOUS ); @@ -153,9 +152,7 @@ void IMapObject::Read( SvStream& rIStm, const String& rBaseURL ) // ab Version 5 kann ein Objektname vorhanden sein if ( nReadVersion >= 0x0005 ) - { - rIStm.ReadByteString( aString ); aName = String( aString.GetBuffer(), nTextEncoding ); - } + aName = read_lenPrefixed_uInt8s_ToOUString(rIStm, nTextEncoding); } delete pCompat; @@ -1117,20 +1114,19 @@ void ImageMap::Write( SvStream& rOStm, const String& rBaseURL ) const { IMapCompat* pCompat; String aImageName( GetName() ); - String aDummy; sal_uInt16 nOldFormat = rOStm.GetNumberFormatInt(); sal_uInt16 nCount = (sal_uInt16) GetIMapObjectCount(); - const rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); + const rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); //vomit! rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); // MagicCode schreiben rOStm << IMAPMAGIC; rOStm << GetVersion(); - rOStm.WriteByteString(rtl::OUStringToOString(aImageName, eEncoding)); - rOStm.WriteByteString(rtl::OUStringToOString(aDummy, eEncoding)); + write_lenPrefixed_uInt8s_FromOUString(rOStm, aImageName, eEncoding); + write_lenPrefixed_uInt8s_FromOString(rOStm, rtl::OString()); //dummy rOStm << nCount; - rOStm.WriteByteString(rtl::OUStringToOString(aImageName, eEncoding)); + write_lenPrefixed_uInt8s_FromOUString(rOStm, aImageName, eEncoding); pCompat = new IMapCompat( rOStm, STREAM_WRITE ); @@ -1152,7 +1148,6 @@ void ImageMap::Write( SvStream& rOStm, const String& rBaseURL ) const void ImageMap::Read( SvStream& rIStm, const String& rBaseURL ) { - ByteString aString; char cMagic[6]; sal_uInt16 nOldFormat = rIStm.GetNumberFormatInt(); sal_uInt16 nCount; @@ -1170,10 +1165,10 @@ void ImageMap::Read( SvStream& rIStm, const String& rBaseURL ) // Version ueberlesen wir rIStm.SeekRel( 2 ); - rIStm.ReadByteString( aString ); aName = String( aString, osl_getThreadTextEncoding() ); - rIStm.ReadByteString( aString ); // Dummy + aName = read_lenPrefixed_uInt8s_ToOUString(rIStm, osl_getThreadTextEncoding()); + read_lenPrefixed_uInt8s_ToOString(rIStm); // Dummy rIStm >> nCount; - rIStm.ReadByteString( aString ); // Dummy + read_lenPrefixed_uInt8s_ToOString(rIStm); // Dummy pCompat = new IMapCompat( rIStm, STREAM_READ ); |