connectivity/source/parse/sqlnode.cxx | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-)
New commits: commit 4182f3cda4add3920c797087872b81f0212c2ae7 Author: Julien Nabet <serval2...@yahoo.fr> AuthorDate: Mon Sep 5 21:59:04 2022 +0200 Commit: Julien Nabet <serval2...@yahoo.fr> CommitDate: Thu Sep 8 18:56:52 2022 +0200 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 <serval2...@yahoo.fr> Reviewed-by: Julien Nabet <serval2...@yahoo.fr> 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())