summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers/mork/MResultSet.cxx
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/drivers/mork/MResultSet.cxx
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/drivers/mork/MResultSet.cxx')
-rw-r--r--connectivity/source/drivers/mork/MResultSet.cxx23
1 files changed, 11 insertions, 12 deletions
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(".") );