[PATCH] use startsWith() instead of compareToAscii()

Thomas Arnhold (via Code Review) gerrit at gerrit.libreoffice.org
Sat Mar 9 13:46:28 PST 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2621

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/21/2621/1

use startsWith() instead of compareToAscii()

brain damage...

Change-Id: I4dc63c7346f724eded9ac7b82cda25c2bb60beff
---
M connectivity/source/drivers/hsqldb/HDriver.cxx
M forms/source/xforms/model_ui.cxx
M padmin/source/cmddlg.cxx
M sdext/source/pdfimport/filterdet.cxx
M sfx2/source/doc/docfile.cxx
M sfx2/source/doc/sfxbasemodel.cxx
M store/source/lockbyte.cxx
M svgio/source/svgreader/svgtoken.cxx
M svx/source/xml/xmleohlp.cxx
M ucb/source/ucp/file/bc.cxx
M vcl/generic/fontmanager/helper.cxx
M vcl/generic/print/genprnpsp.cxx
M vcl/headless/svpprn.cxx
M vcl/unx/generic/printer/printerinfomanager.cxx
M vcl/unx/gtk/app/gtkinst.cxx
M xmloff/source/draw/eventimp.cxx
M xmloff/source/transform/StyleOASISTContext.cxx
M xmloff/source/transform/TransformerBase.cxx
18 files changed, 32 insertions(+), 32 deletions(-)



diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx
index 3f2a96b..d58c8f5 100644
--- a/connectivity/source/drivers/hsqldb/HDriver.cxx
+++ b/connectivity/source/drivers/hsqldb/HDriver.cxx
@@ -399,7 +399,7 @@
     {
         sal_Bool bEnabled = sal_False;
         OSL_VERIFY_EQUALS( jfw_getEnabled( &bEnabled ), JFW_E_NONE, "error in jfw_getEnabled" );
-        return bEnabled  && url.compareToAscii("sdbc:embedded:hsqldb",sizeof("sdbc:embedded:hsqldb")) == 0;
+        return bEnabled  && url.startsWith("sdbc:embedded:hsqldb");
     }
 
     //--------------------------------------------------------------------
diff --git a/forms/source/xforms/model_ui.cxx b/forms/source/xforms/model_ui.cxx
index 7032b8f..6b912ce 100644
--- a/forms/source/xforms/model_ui.cxx
+++ b/forms/source/xforms/model_ui.cxx
@@ -858,7 +858,7 @@
     {
         OUString sLine = xTextInputStream->readLine();
         if( !sLine.isEmpty()
-            && sLine.compareToAscii( "<?xml", 5 ) != 0 )
+            && !sLine.startsWith( "<?xml" ) )
         {
             aBuffer.append( sLine );
             aBuffer.append( sal_Unicode('\n') );
diff --git a/padmin/source/cmddlg.cxx b/padmin/source/cmddlg.cxx
index 17e3863..24f7e9a 100644
--- a/padmin/source/cmddlg.cxx
+++ b/padmin/source/cmddlg.cxx
@@ -276,15 +276,15 @@
     while( nIndex != -1 )
     {
         OUString aToken( m_pParent->m_aJobData.m_aFeatures.getToken( 0, ',', nIndex ) );
-        if( ! aToken.compareToAscii( "fax", 3 ) )
+        if( aToken.startsWith( "fax" ) )
         {
             m_bWasFax = true;
             m_aFaxSwallowBox.Show( sal_True );
             sal_Int32 nPos = 0;
-            m_aFaxSwallowBox.Check( ! aToken.getToken( 1, '=', nPos ).compareToAscii( "swallow", 7 ) ? sal_True : sal_False );
+            m_aFaxSwallowBox.Check( aToken.getToken( 1, '=', nPos ).startsWith( "swallow" ) ? sal_True : sal_False );
             m_aConfigureBox.SelectEntryPos( m_nFaxEntry );
         }
-        else if( ! aToken.compareToAscii( "pdf=", 4 ) )
+        else if( aToken.startsWith( "pdf=" ) )
         {
             m_bWasPdf = true;
             sal_Int32 nPos = 0;
@@ -331,8 +331,8 @@
     while( nIndex != -1 )
     {
         OUString aToken( m_pParent->m_aJobData.m_aFeatures.getToken( 0, ',', nIndex ) );
-        if( aToken.compareToAscii( "fax", 3 ) &&
-            aToken.compareToAscii( "pdf", 3 ) &&
+        if( !aToken.startsWith( "fax" ) &&
+            !aToken.startsWith( "pdf" ) &&
             aToken.compareToAscii( "external_dialog" )
           )
         {
@@ -343,15 +343,15 @@
                 aFeatures += String( aToken );
             }
         }
-        else if( ! aToken.compareToAscii( "pdf=", 4 ) )
+        else if( aToken.startsWith( "pdf=" ) )
         {
             sal_Int32 nPos = 0;
             aOldPdfPath = aToken.getToken( 1, '=', nPos );
         }
-        else if( ! aToken.compareToAscii( "fax=", 4 ) )
+        else if( aToken.startsWith( "fax=" ) )
         {
             sal_Int32 nPos = 0;
-            bOldFaxSwallow = aToken.getToken( 1, '=', nPos ).compareToAscii( "swallow", 7 ) ? false : true;
+            bOldFaxSwallow = aToken.getToken( 1, '=', nPos ).startsWith( "swallow" ) ? true : false;
         }
     }
     ::std::list< String >* pList = &m_aPrinterCommands;
diff --git a/sdext/source/pdfimport/filterdet.cxx b/sdext/source/pdfimport/filterdet.cxx
index f4349bd..235a9d3 100644
--- a/sdext/source/pdfimport/filterdet.cxx
+++ b/sdext/source/pdfimport/filterdet.cxx
@@ -386,7 +386,7 @@
         // check for hybrid PDF
         oslFileHandle aFile = NULL;
         if( bSuccess &&
-            ( aURL.isEmpty() || aURL.compareToAscii( "file:", 5 ) != 0 )
+            ( aURL.isEmpty() || !aURL.startsWith( "file:" ) )
         )
         {
             sal_uInt64 nWritten = 0;
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index cea1947..7fa12d4 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -2505,7 +2505,7 @@
     SFX_ITEMSET_ARG( pImp->m_pSet, pOutStreamItem, SfxUnoAnyItem, SID_OUTPUTSTREAM, false);
     if( pOutStreamItem
      && ( !( pOutStreamItem->GetValue() >>= rOutStream )
-          || (pImp->m_aLogicName.compareToAscii("private:stream", 14) != 0)) )
+          || !pImp->m_aLogicName.startsWith("private:stream")) )
     {
         pImp->m_pSet->ClearItem( SID_OUTPUTSTREAM );
         OSL_FAIL( "Unexpected Output stream parameter!\n" );
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 9d288b5..608214df 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -2926,7 +2926,7 @@
 
     sal_Bool bSaved = sal_False;
     if ( !bSaveTo && m_pData->m_pObjectShell && !sURL.isEmpty()
-      && sURL.compareToAscii( "private:stream", 14 ) != COMPARE_EQUAL
+      && !sURL.startsWith( "private:stream" )
       && ::utl::UCBContentHelper::EqualURLs( getLocation(), sURL ) )
     {
         // this is the same file URL as the current document location, try to use storeOwn if possible
diff --git a/store/source/lockbyte.cxx b/store/source/lockbyte.cxx
index 42c50ed..9a05e94 100644
--- a/store/source/lockbyte.cxx
+++ b/store/source/lockbyte.cxx
@@ -227,7 +227,7 @@
             // Not system path. Assume file url.
             rtl_uString_assign (&(aFileUrl.pData), pFilename);
         }
-        if (aFileUrl.compareToAscii("file://", 7) != 0)
+        if (!aFileUrl.startsWith("file://"))
         {
             // Not file url. Assume relative path.
             rtl::OUString aCwdUrl;
diff --git a/svgio/source/svgreader/svgtoken.cxx b/svgio/source/svgreader/svgtoken.cxx
index 0eef4fe..56681324 100644
--- a/svgio/source/svgreader/svgtoken.cxx
+++ b/svgio/source/svgreader/svgtoken.cxx
@@ -298,7 +298,7 @@
                 aSVGTokenMapperList.insert(SVGTokenValueType(aSVGStrText, SVGTokenText));
             }
 
-            const SVGTokenMapper::const_iterator aResult(aSVGTokenMapperList.find(rStr.compareToAscii("svg:", 4) ? rStr : rStr.copy(4)));
+            const SVGTokenMapper::const_iterator aResult(aSVGTokenMapperList.find(!rStr.startsWith("svg:") ? rStr : rStr.copy(4)));
 
             if(aResult == aSVGTokenMapperList.end())
             {
diff --git a/svx/source/xml/xmleohlp.cxx b/svx/source/xml/xmleohlp.cxx
index 87a1e65..c144ec1 100644
--- a/svx/source/xml/xmleohlp.cxx
+++ b/svx/source/xml/xmleohlp.cxx
@@ -219,7 +219,7 @@
             //eliminate './' at start
             sal_Int32 nStart = 0;
             sal_Int32 nCount = aURLNoPar.getLength();
-            if( 0 == aURLNoPar.compareToAscii( "./", 2 ) )
+            if( aURLNoPar.startsWith( "./" ) )
             {
                 nStart = 2;
                 nCount -= 2;
diff --git a/ucb/source/ucp/file/bc.cxx b/ucb/source/ucp/file/bc.cxx
index a08e033..2c551af 100644
--- a/ucb/source/ucp/file/bc.cxx
+++ b/ucb/source/ucp/file/bc.cxx
@@ -1085,7 +1085,7 @@
     if( m_nState & Deleted )
         return;
 
-    if( aTransferInfo.SourceURL.compareToAscii( "file:",5 ) != 0 )
+    if( !aTransferInfo.SourceURL.startsWith( "file:" ) )
     {
         m_pMyShell->installError( nMyCommandIdentifier,
                                   TASKHANDLING_TRANSFER_INVALIDSCHEME );
diff --git a/vcl/generic/fontmanager/helper.cxx b/vcl/generic/fontmanager/helper.cxx
index 25c1c4f..7b1a571 100644
--- a/vcl/generic/fontmanager/helper.cxx
+++ b/vcl/generic/fontmanager/helper.cxx
@@ -59,19 +59,19 @@
         aBootstrap.getFrom( "UserInstallation", aUserPath );
         OUString aUPath = aUserPath;
 
-        if( ! aConfigPath.compareToAscii( "file://", 7 ) )
+        if( aConfigPath.startsWith( "file://" ) )
         {
             OUString aSysPath;
             if( osl_getSystemPathFromFileURL( aConfigPath.pData, &aSysPath.pData ) == osl_File_E_None )
                 aConfigPath = aSysPath;
         }
-        if( ! aInstallationRootPath.compareToAscii( "file://", 7 ) )
+        if( aInstallationRootPath.startsWith( "file://" ) )
         {
             OUString aSysPath;
             if( osl_getSystemPathFromFileURL( aInstallationRootPath.pData, &aSysPath.pData ) == osl_File_E_None )
                 aInstallationRootPath = aSysPath;
         }
-        if( ! aUserPath.compareToAscii( "file://", 7 ) )
+        if( aUserPath.startsWith( "file://" ) )
         {
             OUString aSysPath;
             if( osl_getSystemPathFromFileURL( aUserPath.pData, &aSysPath.pData ) == osl_File_E_None )
diff --git a/vcl/generic/print/genprnpsp.cxx b/vcl/generic/print/genprnpsp.cxx
index f01a7cf..5835870 100644
--- a/vcl/generic/print/genprnpsp.cxx
+++ b/vcl/generic/print/genprnpsp.cxx
@@ -86,7 +86,7 @@
     while( nIndex != -1 )
     {
         rtl::OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
-        if( ! aToken.compareToAscii( "pdf=", 4 ) )
+        if( aToken.startsWith( "pdf=" ) )
         {
             sal_Int32 nPos = 0;
             aDir = aToken.getToken( 1, '=', nPos );
@@ -924,7 +924,7 @@
     while( nIndex != -1 )
     {
         OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
-        if( ! aToken.compareToAscii( "fax", 3 ) )
+        if( aToken.startsWith( "fax" ) )
         {
             m_bFax = true;
             m_aTmpFile = getTmpName();
@@ -936,11 +936,11 @@
                 m_aFaxNr = it->second;
 
             sal_Int32 nPos = 0;
-            m_bSwallowFaxNo = ! aToken.getToken( 1, '=', nPos ).compareToAscii( "swallow", 7 ) ? true : false;
+            m_bSwallowFaxNo = aToken.getToken( 1, '=', nPos ).startsWith( "swallow" ) ? true : false;
 
             break;
         }
-        if( ! aToken.compareToAscii( "pdf=", 4 ) )
+        if( aToken.startsWith( "pdf=" ) )
         {
             m_bPdf = true;
             m_aTmpFile = getTmpName();
@@ -1170,7 +1170,7 @@
                 else
                     osl_createTempFile( NULL, NULL, &aPDFUrl.pData );
                 // normalize to file URL
-                if( aPDFUrl.compareToAscii( "file:", 5 ) != 0 )
+                if( !aPDFUrl.startsWith( "file:" ) )
                 {
                     // this is not a file URL, but it should
                     // form it into a osl friendly file URL
diff --git a/vcl/headless/svpprn.cxx b/vcl/headless/svpprn.cxx
index d769847..b6a6648 100644
--- a/vcl/headless/svpprn.cxx
+++ b/vcl/headless/svpprn.cxx
@@ -45,7 +45,7 @@
     while( nIndex != -1 )
     {
         OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
-        if( ! aToken.compareToAscii( "pdf=", 4 ) )
+        if( aToken.startsWith( "pdf=" ) )
         {
             sal_Int32 nPos = 0;
             aDir = aToken.getToken( 1, '=', nPos );
diff --git a/vcl/unx/generic/printer/printerinfomanager.cxx b/vcl/unx/generic/printer/printerinfomanager.cxx
index b5a0569..133a342 100644
--- a/vcl/unx/generic/printer/printerinfomanager.cxx
+++ b/vcl/unx/generic/printer/printerinfomanager.cxx
@@ -411,7 +411,7 @@
                 // set parser, merge settings
                 // don't do this for CUPS printers as this is done
                 // by the CUPS system itself
-                if( aPrinter.m_aInfo.m_aDriverName.compareToAscii( "CUPS:", 5 ) != 0 )
+                if( !aPrinter.m_aInfo.m_aDriverName.startsWith( "CUPS:" ) )
                 {
                     aPrinter.m_aInfo.m_pParser          = PPDParser::getParser( aPrinter.m_aInfo.m_aDriverName );
                     aPrinter.m_aInfo.m_aContext.setParser( aPrinter.m_aInfo.m_pParser );
@@ -791,7 +791,7 @@
             aValue.append(static_cast<sal_Int32>(it->second.m_aInfo.m_nBottomMarginAdjust));
             pConfig->WriteKey("MarginAdjust", aValue.makeStringAndClear());
 
-            if( it->second.m_aInfo.m_aDriverName.compareToAscii( "CUPS:", 5 ) != 0 )
+            if( ! it->second.m_aInfo.m_aDriverName.startsWith( "CUPS:" ) )
             {
                 // write PPDContext (not for CUPS)
                 for( int i = 0; i < it->second.m_aInfo.m_aContext.countValuesModified(); i++ )
diff --git a/vcl/unx/gtk/app/gtkinst.cxx b/vcl/unx/gtk/app/gtkinst.cxx
index cc69ccb..0717246 100644
--- a/vcl/unx/gtk/app/gtkinst.cxx
+++ b/vcl/unx/gtk/app/gtkinst.cxx
@@ -283,7 +283,7 @@
 {
     rtl::OString sGtkURL;
     rtl_TextEncoding aSystemEnc = osl_getThreadTextEncoding();
-    if ((aSystemEnc == RTL_TEXTENCODING_UTF8) || (rFileUrl.compareToAscii( "file://", 7 ) !=  0))
+    if ((aSystemEnc == RTL_TEXTENCODING_UTF8) || !rFileUrl.startsWith( "file://" ))
         sGtkURL = rtl::OUStringToOString(rFileUrl, RTL_TEXTENCODING_UTF8);
     else
     {
diff --git a/xmloff/source/draw/eventimp.cxx b/xmloff/source/draw/eventimp.cxx
index 3cdd579..fb711d8a 100644
--- a/xmloff/source/draw/eventimp.cxx
+++ b/xmloff/source/draw/eventimp.cxx
@@ -415,7 +415,7 @@
                 // so check here if its realy a bookmark or maybe a document
                 if( meClickAction == ClickAction_BOOKMARK )
                 {
-                    if( msBookmark.compareToAscii( "#", 1 ) != 0 )
+                    if( !msBookmark.startsWith( "#" ) )
                         meClickAction = ClickAction_DOCUMENT;
                 }
 
diff --git a/xmloff/source/transform/StyleOASISTContext.cxx b/xmloff/source/transform/StyleOASISTContext.cxx
index 6f7caf7..cd76458 100644
--- a/xmloff/source/transform/StyleOASISTContext.cxx
+++ b/xmloff/source/transform/StyleOASISTContext.cxx
@@ -871,7 +871,7 @@
                 --nAttrCount;
                 break;
             case XML_ATACTION_DECODE_STYLE_NAME:
-                m_bControlStyle = 0 == rAttrValue.compareToAscii( "ctrl", 4 );
+                m_bControlStyle = rAttrValue.startsWith( "ctrl" );
             case XML_ATACTION_DECODE_STYLE_NAME_REF:
                 {
                     OUString aAttrValue( rAttrValue );
diff --git a/xmloff/source/transform/TransformerBase.cxx b/xmloff/source/transform/TransformerBase.cxx
index 4adfc97..00665ef 100644
--- a/xmloff/source/transform/TransformerBase.cxx
+++ b/xmloff/source/transform/TransformerBase.cxx
@@ -1382,7 +1382,7 @@
         if( bPackage && bSupportPackage )
         {
             OUString sTmp( OUString::valueOf( sal_Unicode( '#' ) ) );
-            if( 0 == rURI.compareToAscii( "./", 2 ) )
+            if( rURI.startsWith( "./" ) )
                 rURI = rURI.copy( 2 );
             sTmp += rURI;
             rURI = sTmp;

-- 
To view, visit https://gerrit.libreoffice.org/2621
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4dc63c7346f724eded9ac7b82cda25c2bb60beff
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Thomas Arnhold <thomas at arnhold.org>



More information about the LibreOffice mailing list