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 /svx/source/gallery2 | |
parent | callcatcher: remove unused Find1RefWindow variant (diff) | |
download | core-92f396733ebc518bcb7a9eae2dd3169d333b82b9.tar.gz core-92f396733ebc518bcb7a9eae2dd3169d333b82b9.zip |
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 'svx/source/gallery2')
-rw-r--r-- | svx/source/gallery2/gallery1.cxx | 51 | ||||
-rw-r--r-- | svx/source/gallery2/galobj.cxx | 36 | ||||
-rw-r--r-- | svx/source/gallery2/galtheme.cxx | 19 |
3 files changed, 38 insertions, 68 deletions
diff --git a/svx/source/gallery2/gallery1.cxx b/svx/source/gallery2/gallery1.cxx index 4c10186cac9b..9b7cfe2739e6 100644 --- a/svx/source/gallery2/gallery1.cxx +++ b/svx/source/gallery2/gallery1.cxx @@ -78,7 +78,7 @@ GalleryThemeEntry::GalleryThemeEntry( const INetURLObject& rBaseURL, const Strin if( nId && bThemeNameFromResource ) aName = String( GAL_RESID( RID_GALLERYSTR_THEME_START + (sal_uInt16) nId ) ); - if( !aName.Len() ) + if( !aName.getLength() ) aName = rName; } @@ -107,7 +107,7 @@ INetURLObject GalleryThemeEntry::ImplGetURLIgnoreCase( const INetURLObject& rURL // ----------------------------------------------------------------------------- -void GalleryThemeEntry::SetName( const String& rNewName ) +void GalleryThemeEntry::SetName( const rtl::OUString& rNewName ) { if( aName != rNewName ) { @@ -132,16 +132,12 @@ void GalleryThemeEntry::SetId( sal_uInt32 nNewId, sal_Bool bResetThemeName ) SvStream& operator<<( SvStream& rOut, const GalleryImportThemeEntry& rEntry ) { - rOut.WriteByteString(rtl::OUStringToOString(rEntry.aThemeName, RTL_TEXTENCODING_UTF8)); - - rOut.WriteByteString(rtl::OUStringToOString(rEntry.aUIName, RTL_TEXTENCODING_UTF8)); - - rOut.WriteByteString(rtl::OUStringToOString(String(rEntry.aURL.GetMainURL( INetURLObject::NO_DECODE )), RTL_TEXTENCODING_UTF8)); - - rOut.WriteByteString(rtl::OUStringToOString(rEntry.aImportName, RTL_TEXTENCODING_UTF8)); - - rOut.WriteByteString(rtl::OUString()); + write_lenPrefixed_uInt8s_FromOUString(rOut, rEntry.aThemeName, RTL_TEXTENCODING_UTF8); + write_lenPrefixed_uInt8s_FromOUString(rOut, rEntry.aUIName, RTL_TEXTENCODING_UTF8); + write_lenPrefixed_uInt8s_FromOUString(rOut, (rEntry.aURL.GetMainURL( INetURLObject::NO_DECODE )), RTL_TEXTENCODING_UTF8); + write_lenPrefixed_uInt8s_FromOUString(rOut, rEntry.aImportName, RTL_TEXTENCODING_UTF8); + write_lenPrefixed_uInt8s_FromOString(rOut, rtl::OString()); return rOut; } @@ -149,22 +145,11 @@ SvStream& operator<<( SvStream& rOut, const GalleryImportThemeEntry& rEntry ) SvStream& operator>>( SvStream& rIn, GalleryImportThemeEntry& rEntry ) { - ByteString aTmpStr; - - rIn.ReadByteString(aTmpStr); - rEntry.aThemeName = String( aTmpStr, RTL_TEXTENCODING_UTF8 ); - - rIn.ReadByteString(aTmpStr); - rEntry.aUIName = String( aTmpStr, RTL_TEXTENCODING_UTF8 ); - - rIn.ReadByteString(aTmpStr); - rEntry.aURL = INetURLObject( String( aTmpStr, RTL_TEXTENCODING_UTF8 ) ); - - rIn.ReadByteString(aTmpStr); - rEntry.aImportName = String( aTmpStr, RTL_TEXTENCODING_UTF8 ); - - rIn.ReadByteString(aTmpStr); - + rEntry.aThemeName = read_lenPrefixed_uInt8s_ToOUString(rIn, RTL_TEXTENCODING_UTF8); + rEntry.aUIName = read_lenPrefixed_uInt8s_ToOUString(rIn, RTL_TEXTENCODING_UTF8); + rEntry.aURL = read_lenPrefixed_uInt8s_ToOUString(rIn, RTL_TEXTENCODING_UTF8); + rEntry.aImportName = read_lenPrefixed_uInt8s_ToOUString(rIn, RTL_TEXTENCODING_UTF8); + read_lenPrefixed_uInt8s_ToOString(rIn); return rIn; } @@ -547,21 +532,23 @@ void Gallery::ImplWriteImportList() // ------------------------------------------------------------------------ -GalleryThemeEntry* Gallery::ImplGetThemeEntry( const String& rThemeName ) +GalleryThemeEntry* Gallery::ImplGetThemeEntry( const rtl::OUString& rThemeName ) { GalleryThemeEntry* pFound = NULL; - if( rThemeName.Len() ) + if( rThemeName.getLength() ) + { for ( size_t i = 0, n = aThemeList.size(); i < n && !pFound; ++i ) if( rThemeName == aThemeList[ i ]->GetThemeName() ) pFound = aThemeList[ i ]; + } return pFound; } // ------------------------------------------------------------------------ -GalleryImportThemeEntry* Gallery::ImplGetImportThemeEntry( const String& rImportName ) +GalleryImportThemeEntry* Gallery::ImplGetImportThemeEntry( const rtl::OUString& rImportName ) { for ( size_t i = 0, n = aImportList.size(); i < n; ++i ) if ( rImportName == aImportList[ i ]->aUIName ) @@ -571,7 +558,7 @@ GalleryImportThemeEntry* Gallery::ImplGetImportThemeEntry( const String& rImport // ------------------------------------------------------------------------ -String Gallery::GetThemeName( sal_uIntPtr nThemeId ) const +rtl::OUString Gallery::GetThemeName( sal_uIntPtr nThemeId ) const { GalleryThemeEntry* pFound = NULL; @@ -606,7 +593,7 @@ String Gallery::GetThemeName( sal_uIntPtr nThemeId ) const pFound = ( (Gallery*) this )->ImplGetThemeEntry( String::CreateFromAscii( aFallback.GetBuffer() ) ); } - return( pFound ? pFound->GetThemeName() : String() ); + return( pFound ? pFound->GetThemeName() : rtl::OUString() ); } // ------------------------------------------------------------------------ diff --git a/svx/source/gallery2/galobj.cxx b/svx/source/gallery2/galobj.cxx index 1f03f1397b43..ddf56cbd7c01 100644 --- a/svx/source/gallery2/galobj.cxx +++ b/svx/source/gallery2/galobj.cxx @@ -168,7 +168,7 @@ void SgaObject::WriteData( SvStream& rOut, const String& rDestDir ) const String aURLWithoutDestDir = String(aURL.GetMainURL( INetURLObject::NO_DECODE )); aURLWithoutDestDir.SearchAndReplace(rDestDir, String()); - rOut.WriteByteString(rtl::OUStringToOString(aURLWithoutDestDir, RTL_TEXTENCODING_UTF8)); + write_lenPrefixed_uInt8s_FromOUString(rOut, aURLWithoutDestDir, RTL_TEXTENCODING_UTF8); } // ------------------------------------------------------------------------ @@ -185,9 +185,8 @@ void SgaObject::ReadData(SvStream& rIn, sal_uInt16& rReadVersion ) else rIn >> aThumbMtf; - ByteString aTmpStr; - rIn.ReadByteString(aTmpStr); - aURL = INetURLObject(rtl::OStringToOUString(aTmpStr,RTL_TEXTENCODING_UTF8)); + rtl::OUString aTmpStr = read_lenPrefixed_uInt8s_ToOUString(rIn, RTL_TEXTENCODING_UTF8); + aURL = INetURLObject(aTmpStr); } // ------------------------------------------------------------------------ @@ -294,9 +293,8 @@ void SgaObjectBmp::WriteData( SvStream& rOut, const String& rDestDir ) const SgaObject::WriteData( rOut, rDestDir ); char aDummy[ 10 ]; rOut.Write( aDummy, 10 ); - String aDummyStr; - rOut.WriteByteString(rtl::OUStringToOString(aDummyStr, RTL_TEXTENCODING_UTF8)); - rOut.WriteByteString(rtl::OUStringToOString(aTitle, RTL_TEXTENCODING_UTF8)); + write_lenPrefixed_uInt8s_FromOString(rOut, rtl::OString()); //dummy + write_lenPrefixed_uInt8s_FromOUString(rOut, aTitle, RTL_TEXTENCODING_UTF8); } // ------------------------------------------------------------------------ @@ -306,14 +304,10 @@ void SgaObjectBmp::ReadData( SvStream& rIn, sal_uInt16& rReadVersion ) SgaObject::ReadData( rIn, rReadVersion ); rIn.SeekRel( 10 ); // 16, 16, 32, 16 - ByteString aTmpStr; - rIn.ReadByteString(aTmpStr); // dummy + read_lenPrefixed_uInt8s_ToOString(rIn); //dummy if( rReadVersion >= 5 ) - { - rIn.ReadByteString(aTmpStr); - aTitle = rtl::OStringToOUString(aTmpStr, RTL_TEXTENCODING_UTF8); - } + aTitle = read_lenPrefixed_uInt8s_ToOUString(rIn, RTL_TEXTENCODING_UTF8); } // ------------------ @@ -380,7 +374,7 @@ void SgaObjectSound::WriteData( SvStream& rOut, const String& rDestDir ) const { SgaObject::WriteData( rOut, rDestDir ); rOut << (sal_uInt16) eSoundType; - rOut.WriteByteString(rtl::OUStringToOString(aTitle, RTL_TEXTENCODING_UTF8)); + write_lenPrefixed_uInt8s_FromOUString(rOut, aTitle, RTL_TEXTENCODING_UTF8); } // ------------------------------------------------------------------------ @@ -396,11 +390,7 @@ void SgaObjectSound::ReadData( SvStream& rIn, sal_uInt16& rReadVersion ) rIn >> nTmp16; eSoundType = (GalSoundType) nTmp16; if( rReadVersion >= 6 ) - { - ByteString aTmpStr; - rIn.ReadByteString(aTmpStr); - aTitle = rtl::OStringToOUString(aTmpStr, RTL_TEXTENCODING_UTF8); - } + aTitle = read_lenPrefixed_uInt8s_ToOUString(rIn, RTL_TEXTENCODING_UTF8); } } @@ -591,7 +581,7 @@ sal_Bool SgaObjectSvDraw::DrawCentered( OutputDevice* pOut, const FmFormModel& r void SgaObjectSvDraw::WriteData( SvStream& rOut, const String& rDestDir ) const { SgaObject::WriteData( rOut, rDestDir ); - rOut.WriteByteString(rtl::OUStringToOString(aTitle, RTL_TEXTENCODING_UTF8)); + write_lenPrefixed_uInt8s_FromOUString(rOut, aTitle, RTL_TEXTENCODING_UTF8); } // ------------------------------------------------------------------------ @@ -601,11 +591,7 @@ void SgaObjectSvDraw::ReadData( SvStream& rIn, sal_uInt16& rReadVersion ) SgaObject::ReadData( rIn, rReadVersion ); if( rReadVersion >= 5 ) - { - ByteString aTmpStr; - rIn.ReadByteString(aTmpStr); - aTitle = rtl::OStringToOUString(aTmpStr, RTL_TEXTENCODING_UTF8); - } + aTitle = read_lenPrefixed_uInt8s_ToOUString(rIn, RTL_TEXTENCODING_UTF8); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index 12f1e6d257ab..4a34a85ee611 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -733,8 +733,7 @@ GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, sa { sal_uInt32 nThemeId = 0; - ByteString aTmpStr; - pIStm->ReadByteString(aTmpStr); + rtl::OString aTmpStr = read_lenPrefixed_uInt8s_ToOString(*pIStm); aThemeName = rtl::OStringToOUString(aTmpStr, RTL_TEXTENCODING_UTF8); // Charakterkonvertierung durchfuehren @@ -1355,7 +1354,7 @@ SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const sal_Bool bRel; rOStm << (sal_uInt16) 0x0004; - rOStm.WriteByteString(rtl::OUStringToOString(GetRealName(), RTL_TEXTENCODING_UTF8)); + write_lenPrefixed_uInt8s_FromOUString(rOStm, GetRealName(), RTL_TEXTENCODING_UTF8); rOStm << nCount << (sal_uInt16) osl_getThreadTextEncoding(); for( sal_uInt32 i = 0; i < nCount; i++ ) @@ -1395,7 +1394,7 @@ SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const aPath.SearchAndReplace(m_aDestDir, String()); rOStm << bRel; - rOStm.WriteByteString(rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8)); + write_lenPrefixed_uInt8s_FromOUString(rOStm, aPath, RTL_TEXTENCODING_UTF8); rOStm << pObj->nOffset << (sal_uInt16) pObj->eObjKind; } @@ -1433,10 +1432,9 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm ) String aThemeName; rtl_TextEncoding nTextEncoding; - aImportName = String(); + aImportName = rtl::OUString(); rIStm >> nVersion; - ByteString aTmpStr; - rIStm.ReadByteString(aTmpStr); + rtl::OString aTmpStr = read_lenPrefixed_uInt8s_ToOString(rIStm); rIStm >> nCount; if( nVersion >= 0x0004 ) @@ -1471,13 +1469,12 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm ) { pObj = new GalleryObject; - ByteString aTempFileName; String aFileName; String aPath; sal_uInt16 nTemp; rIStm >> bRel; - rIStm.ReadByteString(aTempFileName); + rtl::OString aTempFileName = read_lenPrefixed_uInt8s_ToOString(rIStm); rIStm >> pObj->nOffset; rIStm >> nTemp; pObj->eObjKind = (SgaObjKind) nTemp; @@ -1583,7 +1580,7 @@ SvStream& operator>>( SvStream& rIn, GalleryTheme& rTheme ) void GalleryTheme::ImplSetModified( sal_Bool bModified ) { pThm->SetModified( bModified ); } -const String& GalleryTheme::GetRealName() const { return pThm->GetThemeName(); } +const rtl::OUString& GalleryTheme::GetRealName() const { return pThm->GetThemeName(); } const INetURLObject& GalleryTheme::GetThmURL() const { return pThm->GetThmURL(); } const INetURLObject& GalleryTheme::GetSdgURL() const { return pThm->GetSdgURL(); } const INetURLObject& GalleryTheme::GetSdvURL() const { return pThm->GetSdvURL(); } @@ -1594,7 +1591,7 @@ sal_Bool GalleryTheme::IsImported() const { return pThm->IsImported(); } sal_Bool GalleryTheme::IsReadOnly() const { return pThm->IsReadOnly(); } sal_Bool GalleryTheme::IsDefault() const { return pThm->IsDefault(); } sal_Bool GalleryTheme::IsModified() const { return pThm->IsModified(); } -const String& GalleryTheme::GetName() const { return IsImported() ? aImportName : pThm->GetThemeName(); } +const rtl::OUString& GalleryTheme::GetName() const { return IsImported() ? aImportName : pThm->GetThemeName(); } void GalleryTheme::InsertAllThemes( ListBox& rListBox ) { |