From 9ab0b38e95133dab720408cc2c80093b8a201c10 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 15 Feb 2012 15:26:43 +0100 Subject: Various string function clean up Added: * rtl::OString::matchL * rtl::OString::endsWith * rtl::OString::endsWithL * rtl::OString::indexOfL * rtl::OString::replaceFirst * rtl::OString::replaceAll * rtl::OString::getToken * rtl::OUString::endsWith * rtl::OUString::replaceFirst * rtl::OUString::replaceFirstAsciiL * rtl::OUString::replaceFirstAsciiLAsciiL * rtl::OUString::replaceAll * rtl::OUString::replaceAllAsciiL * rtl::OUString::replaceAllAsciiLAsciiL * rtl::OUString::getToken plus underlying C functions where necessary Deprecated: * comphelper::string::remove * comphelper::string::getToken Removed: * comphelper::string::searchAndReplaceAsciiL * comphelper::string::searchAndReplaceAllAsciiWithAscii * comphelper::string::searchAndReplaceAsciiI * comphelper::string::replace * comphelper::string::matchL * comphelper::string::matchIgnoreAsciiCaseL * comphelper::string::indexOfL Also fixed some apparent misuses of RTL_CONSTASCII_USTRINGPARAM -> RTL_CONSTASCII_STRINGPARAM. --- dbaccess/source/core/dataaccess/datasource.cxx | 6 +- .../source/core/dataaccess/documentcontainer.cxx | 12 ++- .../source/ext/macromigration/migrationengine.cxx | 39 +++++--- .../source/ext/macromigration/migrationlog.cxx | 107 +++++++++++++-------- dbaccess/source/ui/app/AppController.cxx | 9 +- dbaccess/source/ui/uno/copytablewizard.cxx | 7 +- 6 files changed, 115 insertions(+), 65 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx index 8a077a581aeb..ae8971729bb2 100644 --- a/dbaccess/source/core/dataaccess/datasource.cxx +++ b/dbaccess/source/core/dataaccess/datasource.cxx @@ -66,7 +66,6 @@ #include #include #include -#include #include #include #include @@ -747,8 +746,9 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const ::rtl::O ::rtl::OUString sMessage = DBACORE_RESSTRING( nExceptionMessageId ); SQLContext aContext; - aContext.Message = DBACORE_RESSTRING( RID_STR_CONNECTION_REQUEST ); - ::comphelper::string::searchAndReplaceAsciiI( aContext.Message, "$name$", m_pImpl->m_sConnectURL ); + aContext.Message = DBACORE_RESSTRING(RID_STR_CONNECTION_REQUEST). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$name$"), m_pImpl->m_sConnectURL); throwGenericSQLException( sMessage, static_cast< XDataSource* >( this ), makeAny( aContext ) ); } diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx index e5c485e6d4e9..082a6f315f96 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.cxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx @@ -43,7 +43,6 @@ #include "datasource.hxx" #include #include -#include #include #include "core_resource.hxx" #include "core_resource.hrc" @@ -542,8 +541,9 @@ Reference< XComponent > SAL_CALL ODocumentContainer::loadComponentFromURL( const ::rtl::OUString sName; if ( !lcl_queryContent(_sURL,xNameContainer,aContent,sName) ) { - ::rtl::OUString sMessage( DBA_RES( RID_STR_NAME_NOT_FOUND ) ); - ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$name$", _sURL ); + ::rtl::OUString sMessage( + DBA_RES(RID_STR_NAME_NOT_FOUND).replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$name$"), _sURL)); throw IllegalArgumentException( sMessage, *this, 1 ); } @@ -611,9 +611,11 @@ void SAL_CALL ODocumentContainer::insertByHierarchicalName( const ::rtl::OUStrin if ( !xNameContainer.is() ) { - ::rtl::OUString sMessage( DBA_RES( RID_STR_NO_SUB_FOLDER ) ); sal_Int32 index = sName.getLength(); - ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$folder$", _sName.getToken(0,'/',index) ); + ::rtl::OUString sMessage( + DBA_RES(RID_STR_NO_SUB_FOLDER).replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$folder$"), + _sName.getToken(0,'/',index))); throw IllegalArgumentException( sMessage, *this, 1 ); } diff --git a/dbaccess/source/ext/macromigration/migrationengine.cxx b/dbaccess/source/ext/macromigration/migrationengine.cxx index 65155866bd92..5bdde99a1407 100644 --- a/dbaccess/source/ext/macromigration/migrationengine.cxx +++ b/dbaccess/source/ext/macromigration/migrationengine.cxx @@ -72,7 +72,6 @@ #include #include #include -#include #include #include #include @@ -254,8 +253,13 @@ namespace dbmm //---------------------------------------------------------------- ::rtl::OUString lcl_getSubDocumentDescription( const SubDocument& _rDocument ) { - ::rtl::OUString sObjectName = ResId::toString(MacroMigrationResId( _rDocument.eType == eForm ? STR_FORM : STR_REPORT)); - ::comphelper::string::searchAndReplaceAsciiI( sObjectName, "$name$", _rDocument.sHierarchicalName ); + ::rtl::OUString sObjectName( + ResId::toString( + MacroMigrationResId( + _rDocument.eType == eForm ? STR_FORM : STR_REPORT)). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$name$"), + _rDocument.sHierarchicalName)); return sObjectName; } @@ -1025,8 +1029,11 @@ namespace dbmm // initialize global progress sal_Int32 nOverallRange( m_aSubDocs.size() ); - String sProgressSkeleton = ResId::toString(MacroMigrationResId( STR_OVERALL_PROGRESS)); - sProgressSkeleton.SearchAndReplaceAscii( "$overall$", String::CreateFromInt32( nOverallRange ) ); + rtl::OUString sProgressSkeleton( + ResId::toString(MacroMigrationResId( STR_OVERALL_PROGRESS)). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$overall$"), + rtl::OUString::valueOf(nOverallRange))); m_rProgress.start( nOverallRange ); @@ -1037,8 +1044,10 @@ namespace dbmm { sal_Int32 nOverallProgressValue( doc - m_aSubDocs.begin() + 1 ); // update overall progress text - ::rtl::OUString sOverallProgress( sProgressSkeleton ); - ::comphelper::string::searchAndReplaceAsciiI( sOverallProgress, "$current$", ::rtl::OUString::valueOf( nOverallProgressValue ) ); + ::rtl::OUString sOverallProgress( + sProgressSkeleton.replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$current$"), + ::rtl::OUString::valueOf(nOverallProgressValue))); m_rProgress.setOverallProgressText( sOverallProgress ); // migrate document @@ -1927,12 +1936,16 @@ namespace dbmm const ScriptType _eScriptType, const ::rtl::OUString& _rLibraryName ) const { // a human-readable description of the affected library - ::rtl::OUString sLibraryDescription( ResId::toString( - MacroMigrationResId( STR_LIBRARY_TYPE_AND_NAME ) ) ); - ::comphelper::string::searchAndReplaceAsciiI( sLibraryDescription, "$type$", - getScriptTypeDisplayName( _eScriptType ) ); - ::comphelper::string::searchAndReplaceAsciiI( sLibraryDescription, "$library$", - _rLibraryName ); + ::rtl::OUString sLibraryDescription( + ResId::toString(MacroMigrationResId(STR_LIBRARY_TYPE_AND_NAME)). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$type$"), + getScriptTypeDisplayName(_eScriptType)). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$library$"), _rLibraryName)); + //TODO: probably broken if first replaceFirstAsciiL can produce + // fresh instance of "$library$" in subject string of second + // replaceFirstAsciiL InteractionHandler aHandler( m_aContext, m_xDocumentModel ); ::rtl::OUString sPassword; diff --git a/dbaccess/source/ext/macromigration/migrationlog.cxx b/dbaccess/source/ext/macromigration/migrationlog.cxx index 38ded5ae0d80..06391ce600f9 100644 --- a/dbaccess/source/ext/macromigration/migrationlog.cxx +++ b/dbaccess/source/ext/macromigration/migrationlog.cxx @@ -36,7 +36,6 @@ /** === end UNO includes === **/ #include -#include #include #include @@ -240,22 +239,25 @@ namespace dbmm static void lcl_appendErrorDescription( ::rtl::OUStringBuffer& _inout_rBuffer, const MigrationError& _rError ) { const sal_Char* pAsciiErrorDescription( NULL ); - ::std::vector< const sal_Char* > aAsciiParameterNames; + ::std::vector< rtl::OUString > aParameterNames; switch ( _rError.eType ) { case ERR_OPENING_SUB_DOCUMENT_FAILED: pAsciiErrorDescription = "opening '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_CLOSING_SUB_DOCUMENT_FAILED: pAsciiErrorDescription = "closing '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_STORAGE_COMMIT_FAILED: pAsciiErrorDescription = "committing the changes for document '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_STORING_DATABASEDOC_FAILED: @@ -268,52 +270,66 @@ namespace dbmm case ERR_UNEXPECTED_LIBSTORAGE_ELEMENT: pAsciiErrorDescription = "unexpected #lib# storage element in document '#doc#', named '#element#'"; - aAsciiParameterNames.push_back( "#doc#" ); - aAsciiParameterNames.push_back( "#libstore#" ); - aAsciiParameterNames.push_back( "#element#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#libstore#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#element#"))); break; case ERR_CREATING_DBDOC_SCRIPT_STORAGE_FAILED: pAsciiErrorDescription = "creating the database document's storage for #scripttype# scripts failed"; - aAsciiParameterNames.push_back( "#scripttype#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#scripttype#"))); break; case ERR_COMMITTING_SCRIPT_STORAGES_FAILED: pAsciiErrorDescription = "saving the #scripttype# scripts for document '#doc#' failed"; - aAsciiParameterNames.push_back( "#scripttype#" ); - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#scripttype#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_GENERAL_SCRIPT_MIGRATION_FAILURE: pAsciiErrorDescription = "general error while migrating #scripttype# scripts of document '#doc#'"; - aAsciiParameterNames.push_back( "#scripttype#" ); - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#scripttype#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_GENERAL_MACRO_MIGRATION_FAILURE: pAsciiErrorDescription = "general error during macro migration of document '#doc#'"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_UNKNOWN_SCRIPT_TYPE: pAsciiErrorDescription = "unknown script type: #type#"; - aAsciiParameterNames.push_back( "#type#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#type#"))); break; case ERR_UNKNOWN_SCRIPT_LANGUAGE: pAsciiErrorDescription = "unknown script language: #lang#"; - aAsciiParameterNames.push_back( "#lang#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#lang#"))); break; case ERR_UNKNOWN_SCRIPT_NAME_FORMAT: pAsciiErrorDescription = "unknown script name format: #script#"; - aAsciiParameterNames.push_back( "#script#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#script#"))); break; case ERR_SCRIPT_TRANSLATION_FAILURE: pAsciiErrorDescription = "analyzing/translating the script URL failed; script type: #type#; script: #code#"; - aAsciiParameterNames.push_back( "#type#" ); - aAsciiParameterNames.push_back( "#code#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#type#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#code#"))); break; case ERR_INVALID_SCRIPT_DESCRIPTOR_FORMAT: @@ -322,57 +338,72 @@ namespace dbmm case ERR_ADJUSTING_DOCUMENT_EVENTS_FAILED: pAsciiErrorDescription = "adjusting events for document '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_ADJUSTING_DIALOG_EVENTS_FAILED: pAsciiErrorDescription = "adjusting events for dialog #lib#.#dlg# in document '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); - aAsciiParameterNames.push_back( "#lib#" ); - aAsciiParameterNames.push_back( "#dlg#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#lib#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#dlg#"))); break; case ERR_ADJUSTING_FORMCOMP_EVENTS_FAILED: pAsciiErrorDescription = "adjusting form component events for '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_BIND_SCRIPT_STORAGE_FAILED: pAsciiErrorDescription = "binding to the script storage failed for document '#doc#'"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_REMOVE_SCRIPTS_STORAGE_FAILED: pAsciiErrorDescription = "removing a scripts storage failed for document '#doc#'"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_DOCUMENT_BACKUP_FAILED: pAsciiErrorDescription = "backing up the document to #location# failed"; - aAsciiParameterNames.push_back( "#location#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#location#"))); break; case ERR_UNKNOWN_SCRIPT_FOLDER: pAsciiErrorDescription = "unknown script folder '#name#' in document '#doc#'"; - aAsciiParameterNames.push_back( "#doc#" ); - aAsciiParameterNames.push_back( "#name#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#name#"))); break; case ERR_EXAMINING_SCRIPTS_FOLDER_FAILED: pAsciiErrorDescription = "examining the 'Scripts' folder failed for document '#doc#'"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_PASSWORD_VERIFICATION_FAILED: pAsciiErrorDescription = "password verification failed for document '#doc#', #libtype# library '#name#'"; - aAsciiParameterNames.push_back( "#doc#" ); - aAsciiParameterNames.push_back( "#libtype#" ); - aAsciiParameterNames.push_back( "#name#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#libtype#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#name#"))); break; case ERR_NEW_STYLE_REPORT: pAsciiErrorDescription = "#doc# could not be processed, since you don't have the Oracle Report Builder (TM) extension installed."; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; // do *not* add a default case here: Without a default, some compilers will warn you when @@ -382,13 +413,13 @@ namespace dbmm if ( pAsciiErrorDescription ) { ::rtl::OUString sSubstituted( ::rtl::OUString::createFromAscii( pAsciiErrorDescription ) ); - OSL_ENSURE( aAsciiParameterNames.size() == _rError.aErrorDetails.size(), + OSL_ENSURE( aParameterNames.size() == _rError.aErrorDetails.size(), "lcl_appendErrorDescription: unexpected number of error message parameters!" ); - for ( size_t i=0; i < ::std::min( aAsciiParameterNames.size(), _rError.aErrorDetails.size() ); ++i ) + for ( size_t i=0; i < ::std::min( aParameterNames.size(), _rError.aErrorDetails.size() ); ++i ) { - ::comphelper::string::searchAndReplaceAsciiI( sSubstituted, aAsciiParameterNames[i], - _rError.aErrorDetails[i] ); + sSubstituted = sSubstituted.replaceFirst( + aParameterNames[i], _rError.aErrorDetails[i]); } _inout_rBuffer.append( sSubstituted ); diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 3fd0762bcf87..b3f34f325871 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -90,7 +90,6 @@ #include #include -#include #include #include #include @@ -2964,8 +2963,12 @@ void SAL_CALL OApplicationController::removeSelectionChangeListener( const Refer default: case DatabaseObjectContainer::DATA_SOURCE: { - ::rtl::OUString sMessage = String(ModuleRes( RID_STR_UNSUPPORTED_OBJECT_TYPE )); - ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$type$", ::rtl::OUString::valueOf(sal_Int32( pObject->Type )) ); + ::rtl::OUString sMessage( + rtl::OUString( + String(ModuleRes(RID_STR_UNSUPPORTED_OBJECT_TYPE))). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$type$"), + ::rtl::OUString::valueOf(sal_Int32(pObject->Type)))); throw IllegalArgumentException(sMessage, *this, sal_Int16( pObject - aSelectedObjects.getConstArray() )); } } diff --git a/dbaccess/source/ui/uno/copytablewizard.cxx b/dbaccess/source/ui/uno/copytablewizard.cxx index 129721b4c19a..cfcadfcf2e26 100644 --- a/dbaccess/source/ui/uno/copytablewizard.cxx +++ b/dbaccess/source/ui/uno/copytablewizard.cxx @@ -68,7 +68,6 @@ #include #include #include -#include #include #include #include @@ -762,8 +761,10 @@ void CopyTableWizard::impl_checkForUnsupportedSettings_throw( const Reference< X if ( !sUnsupportedSetting.isEmpty() ) { - ::rtl::OUString sMessage( String(ModuleRes( STR_CTW_ERROR_UNSUPPORTED_SETTING )) ); - ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$name$", sUnsupportedSetting ); + ::rtl::OUString sMessage( + rtl::OUString(String(ModuleRes(STR_CTW_ERROR_UNSUPPORTED_SETTING))). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$name$"), sUnsupportedSetting)); throw IllegalArgumentException( sMessage, *const_cast< CopyTableWizard* >( this ), -- cgit