From e2451bd729d0f1d795a5b689deba65bc4e9d92c6 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 25 Oct 2013 16:43:20 +0200 Subject: Convert indexOf->startsWith and lastIndexOf->endsWith This is both an optimisation and a cleanup. This converts code like aStr.indexOf("XX") == 0 to aStr.startsWith("XX") and converts code like aStr.lastIndexOf("XXX") == aStr.getLength() - 3 to aStr.endsWith("XXX") Note that in general aStr.lastIndexOf("X") == aStr.getLength() - 1 converts to aStr.isEmpty() || aStr.endsWith("X") so I used the surrounding context to determine if aStr could be empty when modifying the code. Change-Id: I22cb8ca7c2a4d0288b001f72adb27fd63af87669 --- sal/osl/unx/file_path_helper.cxx | 2 +- sal/osl/w32/path_helper.cxx | 2 +- sal/qa/osl/file/osl_File.cxx | 8 +++----- sal/qa/osl/module/osl_Module.cxx | 5 ++--- 4 files changed, 7 insertions(+), 10 deletions(-) (limited to 'sal') diff --git a/sal/osl/unx/file_path_helper.cxx b/sal/osl/unx/file_path_helper.cxx index ce1b47b62c90..71c3c3206d16 100644 --- a/sal/osl/unx/file_path_helper.cxx +++ b/sal/osl/unx/file_path_helper.cxx @@ -71,7 +71,7 @@ void SAL_CALL osl_systemPathEnsureSeparator(rtl_uString** ppustrPath) rtl_uString_assign(ppustrPath, path.pData); } - OSL_POSTCOND(path.lastIndexOf(FPH_CHAR_PATH_SEPARATOR) == (path.getLength() - 1), \ + OSL_POSTCOND(path.endsWith(FPH_PATH_SEPARATOR()), \ "osl_systemPathEnsureSeparator: Post condition failed"); } } diff --git a/sal/osl/w32/path_helper.cxx b/sal/osl/w32/path_helper.cxx index b91c1874c4b7..c58d70dd18e4 100644 --- a/sal/osl/w32/path_helper.cxx +++ b/sal/osl/w32/path_helper.cxx @@ -54,7 +54,7 @@ void osl_systemPathEnsureSeparator(/*inout*/ rtl_uString** ppustrPath) rtl_uString_assign(ppustrPath, path.pData); } - OSL_POSTCOND(path.lastIndexOf(BACKSLASH) == (path.getLength() - 1), \ + OSL_POSTCOND(path.endsWith(BACKSLASH), \ "osl_systemPathEnsureSeparator: Post condition failed"); } diff --git a/sal/qa/osl/file/osl_File.cxx b/sal/qa/osl/file/osl_File.cxx index 54966aca78c9..50268ff49a57 100644 --- a/sal/qa/osl/file/osl_File.cxx +++ b/sal/qa/osl/file/osl_File.cxx @@ -322,9 +322,9 @@ inline sal_Bool isURL( const sal_Char *pathname ) /** simple version to judge if a file name or directory name is a URL or a system path, just to see if it is start with "file:///";. */ -inline sal_Bool isURL( const ::rtl::OUString pathname ) +inline bool isURL( const ::rtl::OUString pathname ) { - return ( ( pathname.indexOf( aPreURL ) == 0 ) ? sal_True : sal_False ); + return pathname.startsWith( aPreURL ); } /** concat two part to form a URL or system path, add PATH_SEPARATOR between them if necessary, add "file:///" to beginning if necessary. @@ -339,10 +339,8 @@ inline void concatURL( ::rtl::OUString & pathname1, const ::rtl::OUString & path pathname1 = aPathName.copy( 0 ); } - sal_Int32 index = 0; //check if '/' is in the end of pathname1 or at the begin of pathname2; - if ( ( ( index = pathname1.lastIndexOf( aSlashURL ) ) != ( pathname1.getLength() - 1 ) ) && - ( ( index = pathname2.indexOf( aSlashURL ) ) != 0 ) ) + if ( !pathname1.endsWith( aSlashURL ) && !pathname2.startsWith( aSlashURL ) ) pathname1 += aSlashURL; pathname1 += pathname2; } diff --git a/sal/qa/osl/module/osl_Module.cxx b/sal/qa/osl/module/osl_Module.cxx index 2b51bdfbc5fa..d6358d4c692c 100644 --- a/sal/qa/osl/module/osl_Module.cxx +++ b/sal/qa/osl/module/osl_Module.cxx @@ -70,10 +70,9 @@ inline ::rtl::OUString getDllURL( void ) return dllPath; } -inline sal_Bool isURL( const ::rtl::OUString pathname ) +inline bool isURL( const ::rtl::OUString pathname ) { - ::rtl::OUString aPreURL( "file:///" ); - return ( ( pathname.indexOf( aPreURL ) == 0 ) ? sal_True : sal_False ); + return pathname.startsWith( "file:///" ); } /** create a temp test directory using OUString name of full qualified URL or system path. -- cgit >distro/collabora/libreoffice-4.0.6.2 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
path: root/linguistic/source/lngreg.hxx
AgeCommit message (Expand)Author
2017-12-11loplugin:salcall fix functionsNoel Grandin
2017-05-02loplugin:checkunusedparams in hwpfilter..lotuswordproNoel Grandin