From f98407403f916f9a7474e93c674fc7ac360c3539 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Sat, 29 Dec 2012 12:50:32 +0200 Subject: Revert "String Cleanup and news OUString methods/constructors" Broke a unit test and made all tinderboxes red. This reverts commit 3179055dc3e267c961a5618c810fbc0df1858d72. --- tools/inc/tools/tempfile.hxx | 3 +- tools/source/fsys/tempfile.cxx | 114 +++++------------------------------------ 2 files changed, 13 insertions(+), 104 deletions(-) (limited to 'tools') diff --git a/tools/inc/tools/tempfile.hxx b/tools/inc/tools/tempfile.hxx index 315ba24b32e1..9e84adc96a51 100644 --- a/tools/inc/tools/tempfile.hxx +++ b/tools/inc/tools/tempfile.hxx @@ -41,8 +41,7 @@ public: The extension string may be f.e. ".txt" or "", if no extension string is given, ".tmp" is used. */ - TempFile( const String& rLeadingChars, const String* pExtension=NULL, const String* pParent=NULL, sal_Bool bDirectory=sal_False ); - TempFile( const OUString& rLeadingChars, const OUString* pExtension=NULL, const OUString* pParent=NULL, sal_Bool bDirectory=sal_False ); + TempFile( const String& rLeadingChars, const String* pExtension=NULL, const String* pParent=NULL, sal_Bool bDirectory=sal_False ); /** TempFile will be removed from disk in dtor if EnableKillingTempFile was called before. TempDirs will be removed recursively in that case. */ diff --git a/tools/source/fsys/tempfile.cxx b/tools/source/fsys/tempfile.cxx index 685960956c31..7a3f9dfc2f0a 100644 --- a/tools/source/fsys/tempfile.cxx +++ b/tools/source/fsys/tempfile.cxx @@ -35,7 +35,7 @@ using namespace osl; -namespace { struct TempNameBase_Impl : public rtl::Static< OUString, TempNameBase_Impl > {}; } +namespace { struct TempNameBase_Impl : public rtl::Static< ::rtl::OUString, TempNameBase_Impl > {}; } struct TempFile_Impl { @@ -48,9 +48,9 @@ String GetSystemTempDir_Impl() char sBuf[_MAX_PATH]; const char *pDir = TempDirImpl(sBuf); - OString aTmpA( pDir ); - OUString aTmp = ::rtl::OStringToOUString( aTmpA, osl_getThreadTextEncoding() ); - OUString aRet; + ::rtl::OString aTmpA( pDir ); + ::rtl::OUString aTmp = ::rtl::OStringToOUString( aTmpA, osl_getThreadTextEncoding() ); + rtl::OUString aRet; FileBase::getFileURLFromSystemPath( aTmp, aRet ); String aName = aRet; if( aName.GetChar(aName.Len()-1) != '/' ) @@ -66,8 +66,8 @@ String ConstructTempDir_Impl( const String* pParent ) if ( pParent && pParent->Len() ) { // if parent given try to use it - OUString aTmp( *pParent ); - OUString aRet; + rtl::OUString aTmp( *pParent ); + rtl::OUString aRet; // test for valid filename { @@ -84,7 +84,7 @@ String ConstructTempDir_Impl( const String* pParent ) if ( !aName.Len() ) { // if no parent or invalid parent : use system directory - OUString& rTempNameBase_Impl = TempNameBase_Impl::get(); + ::rtl::OUString& rTempNameBase_Impl = TempNameBase_Impl::get(); if ( rTempNameBase_Impl.isEmpty() ) rTempNameBase_Impl = GetSystemTempDir_Impl(); aName = rTempNameBase_Impl; @@ -98,45 +98,6 @@ String ConstructTempDir_Impl( const String* pParent ) return aName; } -OUString ConstructTempDir_Impl( const OUString* pParent ) -{ - OUString aName; - if ( pParent && pParent->getLength() ) - { - // if parent given try to use it - OUString aTmp( *pParent ); - OUString aRet; - - // test for valid filename - { - ::osl::DirectoryItem aItem; - sal_Int32 i = aRet.getLength(); - if ( aRet[i-1] == '/' ) - i--; - - if ( DirectoryItem::get( aRet.copy(0, i), aItem ) == FileBase::E_None ) - aName = aRet; - } - } - - if ( !aName.isEmpty() ) - { - // if no parent or invalid parent : use system directory - OUString& rTempNameBase_Impl = TempNameBase_Impl::get(); - if ( rTempNameBase_Impl.isEmpty() ) - rTempNameBase_Impl = GetSystemTempDir_Impl(); - aName = rTempNameBase_Impl; - } - - // Make sure that directory ends with a separator - xub_StrLen i = aName.getLength(); - if( i>0 && aName[i-1] != '/' ) - aName += "/"; - - return aName; -} - - void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_True ) { // add a suitable tempname @@ -144,14 +105,14 @@ void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_Tru // ER 13.07.00 why not radix 36 [0-9A-Z] ?!? const unsigned nRadix = 26; String aName( rName ); - aName += OUString("sv"); + aName += rtl::OUString("sv"); rName.Erase(); static unsigned long u = Time::GetSystemTicks(); for ( unsigned long nOld = u; ++u != nOld; ) { u %= (nRadix*nRadix*nRadix); - OUString aTmp = OUStringBuffer(aName). + rtl::OUString aTmp = rtl::OUStringBuffer(aName). append((sal_Int32)(unsigned)u, nRadix). append(".tmp"). makeStringAndClear(); @@ -230,64 +191,13 @@ TempFile::TempFile( const String& rLeadingChars, const String* pExtension, aName += rLeadingChars; for ( sal_Int32 i=0;; i++ ) { - OUStringBuffer aTmpBuffer(aName); - aTmpBuffer.append(i); - if ( pExtension ) - aTmpBuffer.append(*pExtension); - else - aTmpBuffer.append(".tmp"); - OUString aTmp = aTmpBuffer.makeStringAndClear(); - - if ( bDirectory ) - { - FileBase::RC err = Directory::create( aTmp ); - if ( err == FileBase::E_None ) - { - pImp->aName = aTmp; - break; - } - else if ( err != FileBase::E_EXIST ) - // if f.e. name contains invalid chars stop trying to create dirs - break; - } - else - { - File aFile( aTmp ); - FileBase::RC err = aFile.open(osl_File_OpenFlag_Create); - if ( err == FileBase::E_None ) - { - pImp->aName = aTmp; - aFile.close(); - break; - } - else if ( err != FileBase::E_EXIST ) - // if f.e. name contains invalid chars stop trying to create dirs - break; - } - } -} - -TempFile::TempFile( const OUString& rLeadingChars, const OUString* pExtension, - const OUString* pParent, sal_Bool bDirectory ) - : pImp( new TempFile_Impl ) - , bKillingFileEnabled( sal_False ) -{ - pImp-> bIsDirectory = bDirectory; - - // get correct directory - OUString aName = ConstructTempDir_Impl( pParent ); - - // now use special naming scheme (name takes leading chars and an index couting up from zero - aName += rLeadingChars; - for ( sal_Int32 i=0;; i++ ) - { - OUStringBuffer aTmpBuffer(aName); + rtl::OUStringBuffer aTmpBuffer(aName); aTmpBuffer.append(i); if ( pExtension ) aTmpBuffer.append(*pExtension); else aTmpBuffer.append(".tmp"); - OUString aTmp = aTmpBuffer.makeStringAndClear(); + rtl::OUString aTmp = aTmpBuffer.makeStringAndClear(); if ( bDirectory ) { @@ -338,7 +248,7 @@ TempFile::~TempFile() String TempFile::GetName() const { - OUString aTmp; + rtl::OUString aTmp; aTmp = pImp->aName; return aTmp; } -- cgit