summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorJulien Nabet <serval2412@yahoo.fr>2022-09-05 21:59:04 +0200
committerJulien Nabet <serval2412@yahoo.fr>2022-09-08 18:56:52 +0200
commit4182f3cda4add3920c797087872b81f0212c2ae7 (patch)
tree1e87506faed8956b3b1b8c5168cbc57293f23252 /connectivity
parent727739fa3583a6db140a6f8ddb46b34cd4c29596 (diff)
Simplify by using replace instead of replaceAt in loop in connectivity (4)
Change-Id: Iab92f1ee2be1e5b9ab3fa005890acfe9acbf3732 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139460 Tested-by: Julien Nabet <serval2412@yahoo.fr> Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/parse/sqlnode.cxx30
1 files changed, 9 insertions, 21 deletions
diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx
index 8df3b302c016..bd6853ecd1ee 100644
--- a/connectivity/source/parse/sqlnode.cxx
+++ b/connectivity/source/parse/sqlnode.cxx
@@ -100,31 +100,19 @@ namespace
/** quotes a string and search for quotes inside the string and replace them with the new quote
@param rValue
The value to be quoted.
- @param rQuot
+ @param rQuote
The quote
- @param rQuotToReplace
+ @param rQuoteToReplace
The quote to replace with
@return
The quoted string.
*/
- OUString SetQuotation(std::u16string_view rValue, const OUString& rQuot, std::u16string_view rQuotToReplace)
+ OUString SetQuotation(const OUString& rValue, std::u16string_view rQuote, std::u16string_view rQuoteToReplace)
{
- OUString rNewValue = rQuot + rValue;
- sal_Int32 nIndex = sal_Int32(-1); // Replace quotes with double quotes or the parser gets into problems
-
- if (!rQuot.isEmpty())
- {
- do
- {
- nIndex += 2;
- nIndex = rNewValue.indexOf(rQuot,nIndex);
- if(nIndex != -1)
- rNewValue = rNewValue.replaceAt(nIndex,rQuot.getLength(),rQuotToReplace);
- } while (nIndex != -1);
- }
-
- rNewValue += rQuot;
- return rNewValue;
+ // Replace quotes with double quotes or the parser gets into problems
+ if (!rQuote.empty())
+ return rQuote + rValue.replaceAll(rQuote, rQuoteToReplace) + rQuote;
+ return rValue;
}
bool columnMatchP(const connectivity::OSQLParseNode* pSubTree, const connectivity::SQLParseNodeParameter& rParam)
@@ -758,7 +746,7 @@ void OSQLParseNode::impl_parseLikeNodeToString_throw( OUStringBuffer& rString, c
{
OUString aStr = ConvertLikeToken(pParaNode, pEscNode, rParam.bInternational);
rString.append(" ");
- rString.append(SetQuotation(aStr, "\'", u"\'\'"));
+ rString.append(SetQuotation(aStr, u"\'", u"\'\'"));
}
else
pParaNode->impl_parseNodeToString_throw( rString, aNewParam, false );
@@ -2432,7 +2420,7 @@ void OSQLParseNode::parseLeaf(OUStringBuffer& rString, const SQLParseNodeParamet
case SQLNodeType::String:
if (!rString.isEmpty())
rString.append(" ");
- rString.append(SetQuotation(m_aNodeValue, "\'", u"\'\'"));
+ rString.append(SetQuotation(m_aNodeValue, u"\'", u"\'\'"));
break;
case SQLNodeType::Name:
if (!rString.isEmpty())