/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Find various of type rtl::O[U]String that can be converted to std::[u16]string_view instead.
// This can generate false positives e.g. // OUString sSave( aToken ); // aToken.append("foo"); // aToken = sSave; // where the data that is backing the view is modified and then the view is used to assign to // the same source data.
DeclRefExpr const* relevantCXXMemberCallExpr(CXXMemberCallExpr const* expr)
{
StringType t = relevantStringType(expr->getObjectType()); if (t == StringType::None)
{ return nullptr;
} bool good = false; autoconst d = expr->getMethodDecl(); if (d->getOverloadedOperator() == OO_Subscript)
{
good = true;
} elseif (autoconst i = d->getIdentifier())
{ autoconst n = i->getName(); if (n == "endsWith" || n == "isEmpty" || n == "startsWith" || n == "subView"
|| n == "indexOf" || n == "lastIndexOf" || n == "compareTo" || n == "match"
|| n == "trim" || n == "toInt32" || n == "toInt64" || n == "toDouble"
|| n == "equalsIgnoreAsciiCase" || n == "compareToIgnoreAsciiCase" || n == "getToken"
|| n == "copy" || n == "iterateCodePoints")
{
good = true;
} #if 0 //TODO: rtl::O[U]String::getLength would be awkward to replace with // std::[u16]string_view::length/size due to the sal_Int32 vs. std::size_t return type // mismatch (C++20 ssize might make that easier, though); and while rtl::OString::getStr is // documented to be NUL-terminated (so not eligible for replacement with // std::string_view::data in general), rtl::OUString::getStr is not (so should be eligible // for replacement with std::u16string_view::data, but some call sites might nevertheless // incorrectly rely on NUL termination, so any replacement would need careful review): if (n == "getLength" || (t == StringType::RtlOustring && n == "getStr"))
{
good = true;
} #endif
} if (!good)
{ return nullptr;
} return relevantDeclRefExpr(expr->getImplicitObjectArgument());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.