summaryrefslogtreecommitdiff
path: root/connectivity/source
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2013-10-25 16:43:20 +0200
committerNoel Grandin <noel@peralex.com>2013-10-31 08:34:21 +0200
commite2451bd729d0f1d795a5b689deba65bc4e9d92c6 (patch)
tree4f2356107b0e58db7afda0fc324b9eac49ff68c0 /connectivity/source
parent460b52838fdad0352188bdd877b69cbb5f17ca63 (diff)
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
Diffstat (limited to 'connectivity/source')
-rw-r--r--connectivity/source/commontools/AutoRetrievingBase.cxx6
-rw-r--r--connectivity/source/commontools/dbtools2.cxx6
-rw-r--r--connectivity/source/drivers/evoab2/NStatement.cxx4
-rw-r--r--connectivity/source/drivers/hsqldb/HTable.cxx4
-rw-r--r--connectivity/source/drivers/macab/macabutilities.hxx2
-rw-r--r--connectivity/source/drivers/mork/MQueryHelper.cxx2
-rw-r--r--connectivity/source/drivers/mork/MResultSet.cxx23
-rw-r--r--connectivity/source/drivers/mozab/MResultSet.cxx19
-rw-r--r--connectivity/source/drivers/mysql/YTable.cxx4
9 files changed, 33 insertions, 37 deletions
diff --git a/connectivity/source/commontools/AutoRetrievingBase.cxx b/connectivity/source/commontools/AutoRetrievingBase.cxx
index 78b5f729761e..fd82b6267a50 100644
--- a/connectivity/source/commontools/AutoRetrievingBase.cxx
+++ b/connectivity/source/commontools/AutoRetrievingBase.cxx
@@ -42,12 +42,10 @@ namespace connectivity
{ // we need a table name
sal_Int32 nIntoIndex = sStmt.indexOf("INTO ");
sStmt = sStmt.copy(nIntoIndex+5);
- do
+ while (sStmt.startsWith(" "));
{
- if ( sStmt.indexOf(' ') == 0 )
- sStmt = sStmt.copy(1);
+ sStmt = sStmt.copy(1);
}
- while (sStmt.indexOf(' ') == 0 );
nIntoIndex = 0;
OUString sTableName = sStmt.getToken(0,' ',nIntoIndex);
diff --git a/connectivity/source/commontools/dbtools2.cxx b/connectivity/source/commontools/dbtools2.cxx
index 2dcb23d338ba..de82465c8dc1 100644
--- a/connectivity/source/commontools/dbtools2.cxx
+++ b/connectivity/source/commontools/dbtools2.cxx
@@ -385,10 +385,10 @@ OUString createSqlCreateTableStatement( const Reference< XPropertySet >& descri
aSql += sKeyStmt;
else
{
- if ( aSql.lastIndexOf(',') == (aSql.getLength()-1) )
- aSql = aSql.replaceAt(aSql.getLength()-1,1,OUString(")"));
+ if ( aSql.endsWith(",") )
+ aSql = aSql.replaceAt(aSql.getLength()-1, 1, ")");
else
- aSql += OUString(")");
+ aSql += ")";
}
return aSql;
}
diff --git a/connectivity/source/drivers/evoab2/NStatement.cxx b/connectivity/source/drivers/evoab2/NStatement.cxx
index 3d89b926e403..d341eddc44a1 100644
--- a/connectivity/source/drivers/evoab2/NStatement.cxx
+++ b/connectivity/source/drivers/evoab2/NStatement.cxx
@@ -387,7 +387,7 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree )
}
else if( (aMatchString.indexOf ( WILDCARD ) == aMatchString.lastIndexOf ( WILDCARD ) ) )
{ // One occurrence of '%' matches...
- if ( aMatchString.indexOf ( WILDCARD ) == 0 )
+ if ( aMatchString.startsWith( WILDCARD ) )
pResult = createTest( aColumnName, E_BOOK_QUERY_ENDS_WITH, aMatchString.copy( 1 ) );
else if ( aMatchString.indexOf ( WILDCARD ) == aMatchString.getLength() - 1 )
pResult = createTest( aColumnName, E_BOOK_QUERY_BEGINS_WITH, aMatchString.copy( 0, aMatchString.getLength() - 1 ) );
@@ -398,7 +398,7 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree )
pResult = e_book_query_not( pResult, TRUE );
}
else if( aMatchString.getLength() >= 3 &&
- aMatchString.indexOf ( WILDCARD ) == 0 &&
+ aMatchString.startsWith( WILDCARD ) &&
aMatchString.indexOf ( WILDCARD, 1) == aMatchString.getLength() - 1 ) {
// one '%' at the start and another at the end
pResult = createTest( aColumnName, E_BOOK_QUERY_CONTAINS, aMatchString.copy (1, aMatchString.getLength() - 2) );
diff --git a/connectivity/source/drivers/hsqldb/HTable.cxx b/connectivity/source/drivers/hsqldb/HTable.cxx
index 13b636fc645e..be5c8aa74ee1 100644
--- a/connectivity/source/drivers/hsqldb/HTable.cxx
+++ b/connectivity/source/drivers/hsqldb/HTable.cxx
@@ -328,8 +328,8 @@ OUString OHSQLTable::getAlterTableColumnPart()
void OHSQLTable::executeStatement(const OUString& _rStatement )
{
OUString sSQL = _rStatement;
- if(sSQL.lastIndexOf(',') == (sSQL.getLength()-1))
- sSQL = sSQL.replaceAt(sSQL.getLength()-1,1,OUString(")"));
+ if(sSQL.endsWith(","))
+ sSQL = sSQL.replaceAt(sSQL.getLength()-1, 1, ")");
Reference< XStatement > xStmt = getConnection()->createStatement( );
if ( xStmt.is() )
diff --git a/connectivity/source/drivers/macab/macabutilities.hxx b/connectivity/source/drivers/macab/macabutilities.hxx
index a17bda266458..5b151575351d 100644
--- a/connectivity/source/drivers/macab/macabutilities.hxx
+++ b/connectivity/source/drivers/macab/macabutilities.hxx
@@ -102,7 +102,7 @@ namespace connectivity
/* Get the length, and make sure that there is actually a string
* here.
*/
- if(_originalLabel.indexOf("_$!<") == 0)
+ if(_originalLabel.startsWith("_$!<"))
{
return _originalLabel.copy(4,_originalLabel.getLength()-8);
}
diff --git a/connectivity/source/drivers/mork/MQueryHelper.cxx b/connectivity/source/drivers/mork/MQueryHelper.cxx
index 3cc5b9320e58..05dd1219f6fc 100644
--- a/connectivity/source/drivers/mork/MQueryHelper.cxx
+++ b/connectivity/source/drivers/mork/MQueryHelper.cxx
@@ -322,7 +322,7 @@ sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection)
resultVector.push_back((currentValue.endsWith(searchedValue)) ? sal_True : sal_False);
} else if (evStr->getCond() == MQueryOp::BeginsWith) {
SAL_INFO("connectivity.mork", "MQueryOp::BeginsWith; done");
- resultVector.push_back((currentValue.indexOf(searchedValue) == 0) ? sal_True : sal_False);
+ resultVector.push_back((currentValue.startsWith(searchedValue)) ? sal_True : sal_False);
} else if (evStr->getCond() == MQueryOp::Contains) {
SAL_INFO("connectivity.mork", "MQueryOp::Contains; done");
resultVector.push_back((currentValue.indexOf(searchedValue) == -1) ? sal_False : sal_True);
diff --git a/connectivity/source/drivers/mork/MResultSet.cxx b/connectivity/source/drivers/mork/MResultSet.cxx
index 524f9d02a2ac..d14a0468d7e3 100644
--- a/connectivity/source/drivers/mork/MResultSet.cxx
+++ b/connectivity/source/drivers/mork/MResultSet.cxx
@@ -761,6 +761,10 @@ void OResultSet::parseParameter( const OSQLParseNode* pNode, OUString& rMatchStr
#endif
}
+#define WILDCARD "%"
+#define ALT_WILDCARD "*"
+static const sal_Unicode MATCHCHAR = '_';
+
void OResultSet::analyseWhereClause( const OSQLParseNode* parseTree,
MQueryExpression &queryExpression)
{
@@ -912,10 +916,6 @@ void OResultSet::analyseWhereClause( const OSQLParseNode* parseT
m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_STRING, *this );
}
- const sal_Unicode WILDCARD = '%';
- const sal_Unicode ALT_WILDCARD = '*';
- const sal_Unicode MATCHCHAR = '_';
-
OUString sTableRange;
if(SQL_ISRULE(pColumn,column_ref))
m_pSQLIterator->getColumnRange(pColumn,columnName,sTableRange);
@@ -926,7 +926,7 @@ void OResultSet::analyseWhereClause( const OSQLParseNode* parseT
parseParameter( pAtom, matchString );
// Replace all '*' with '%' : UI Usually does this but not with
// Parameters for some reason.
- matchString = matchString.replace( ALT_WILDCARD, WILDCARD );
+ matchString = matchString.replaceAll( ALT_WILDCARD, WILDCARD );
}
else
{
@@ -935,7 +935,7 @@ void OResultSet::analyseWhereClause( const OSQLParseNode* parseT
// Determine where '%' character is...
- if ( matchString.equals( OUString( WILDCARD ) ) )
+ if ( matchString == WILDCARD )
{
// String containing only a '%' and nothing else
op = MQueryOp::Exists;
@@ -951,8 +951,8 @@ void OResultSet::analyseWhereClause( const OSQLParseNode* parseT
else
op = MQueryOp::Contains;
}
- else if ( matchString.indexOf ( WILDCARD ) == 0
- && matchString.lastIndexOf ( WILDCARD ) == matchString.getLength() -1
+ else if ( matchString.startsWith( WILDCARD )
+ && matchString.endsWith( WILDCARD )
&& matchString.indexOf ( WILDCARD, 1 ) == matchString.lastIndexOf ( WILDCARD )
&& matchString.indexOf( MATCHCHAR ) == -1
)
@@ -980,7 +980,7 @@ void OResultSet::analyseWhereClause( const OSQLParseNode* parseT
)
{
// One occurrence of '%' - no '_' matches...
- if ( matchString.indexOf ( WILDCARD ) == 0 )
+ if ( matchString.startsWith( WILDCARD ) )
{
op = MQueryOp::EndsWith;
matchString = matchString.replaceAt( 0, 1, OUString());
@@ -993,7 +993,7 @@ void OResultSet::analyseWhereClause( const OSQLParseNode* parseT
else
{
sal_Int32 pos = matchString.indexOf ( WILDCARD );
- matchString = matchString.replaceAt( pos, 1,OUString(".*") );
+ matchString = matchString.replaceAt( pos, 1, ".*" );
op = MQueryOp::RegExp;
}
@@ -1001,13 +1001,12 @@ void OResultSet::analyseWhereClause( const OSQLParseNode* parseT
else
{
// Most Complex, need to use an RE
- sal_Int32 pos = matchString.indexOf ( WILDCARD );
+ sal_Int32 pos;
while ( (pos = matchString.indexOf ( WILDCARD )) != -1 )
{
matchString = matchString.replaceAt( pos, 1, OUString(".*") );
}
- pos = matchString.indexOf ( MATCHCHAR );
while ( (pos = matchString.indexOf( MATCHCHAR )) != -1 )
{
matchString = matchString.replaceAt( pos, 1, OUString(".") );
diff --git a/connectivity/source/drivers/mozab/MResultSet.cxx b/connectivity/source/drivers/mozab/MResultSet.cxx
index 6d94fa7c8dff..15d99ceee51a 100644
--- a/connectivity/source/drivers/mozab/MResultSet.cxx
+++ b/connectivity/source/drivers/mozab/MResultSet.cxx
@@ -933,8 +933,8 @@ void OResultSet::analyseWhereClause( const OSQLParseNode* parseT
else
op = MQueryOp::Contains;
}
- else if ( matchString.indexOf ( WILDCARD ) == 0
- && matchString.lastIndexOf ( WILDCARD ) == matchString.getLength() -1
+ else if ( matchString.startsWith( WILDCARD )
+ && matchString.endsWith( WILDCARD )
&& matchString.indexOf ( WILDCARD, 1 ) == matchString.lastIndexOf ( WILDCARD )
&& matchString.indexOf( MATCHCHAR ) == -1
)
@@ -962,20 +962,20 @@ void OResultSet::analyseWhereClause( const OSQLParseNode* parseT
)
{
// One occurrence of '%' - no '_' matches...
- if ( matchString.indexOf ( WILDCARD ) == 0 )
+ if ( matchString.startsWith( WILDCARD ) )
{
op = MQueryOp::EndsWith;
matchString = matchString.replaceAt( 0, 1, OUString());
}
- else if ( matchString.indexOf ( WILDCARD ) == matchString.getLength() -1 )
+ else if ( matchString.endsWith( WILDCARD ) )
{
op = MQueryOp::BeginsWith;
- matchString = matchString.replaceAt( matchString.getLength() -1 , 1, OUString() );
+ matchString = matchString.replaceAt( matchString.getLength() -1, 1, OUString() );
}
else
{
sal_Int32 pos = matchString.indexOf ( WILDCARD );
- matchString = matchString.replaceAt( pos, 1,OUString(".*") );
+ matchString = matchString.replaceAt( pos, 1, ".*" );
op = MQueryOp::RegExp;
}
@@ -983,16 +983,15 @@ void OResultSet::analyseWhereClause( const OSQLParseNode* parseT
else
{
// Most Complex, need to use an RE
- sal_Int32 pos = matchString.indexOf ( WILDCARD );
+ sal_Int32 pos;
while ( (pos = matchString.indexOf ( WILDCARD )) != -1 )
{
- matchString = matchString.replaceAt( pos, 1, OUString(".*") );
+ matchString = matchString.replaceAt( pos, 1, ".*" );
}
- pos = matchString.indexOf ( MATCHCHAR );
while ( (pos = matchString.indexOf( MATCHCHAR )) != -1 )
{
- matchString = matchString.replaceAt( pos, 1, OUString(".") );
+ matchString = matchString.replaceAt( pos, 1, "." );
}
op = MQueryOp::RegExp;
diff --git a/connectivity/source/drivers/mysql/YTable.cxx b/connectivity/source/drivers/mysql/YTable.cxx
index efc80a2ae4c9..4938b724fc34 100644
--- a/connectivity/source/drivers/mysql/YTable.cxx
+++ b/connectivity/source/drivers/mysql/YTable.cxx
@@ -354,8 +354,8 @@ OUString OMySQLTable::getAlterTableColumnPart()
void OMySQLTable::executeStatement(const OUString& _rStatement )
{
OUString sSQL = _rStatement;
- if(sSQL.lastIndexOf(',') == (sSQL.getLength()-1))
- sSQL = sSQL.replaceAt(sSQL.getLength()-1,1,OUString(")"));
+ if(sSQL.endsWith(","))
+ sSQL = sSQL.replaceAt(sSQL.getLength()-1, 1, ")");
Reference< XStatement > xStmt = getConnection()->createStatement( );
if ( xStmt.is() )