================ @@ -0,0 +1,106 @@ +//===--- UseStartsEndsWithCheck.cpp - clang-tidy --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "UseStartsEndsWithCheck.h" + +#include "../utils/OptionsUtils.h" +#include "clang/Lex/Lexer.h" + +#include <string> + +using namespace clang::ast_matchers; + +namespace clang::tidy::performance { + +const auto DefaultStringLikeClasses = + "::std::basic_string;::std::basic_string_view"; + +UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name, + ClangTidyContext *Context) + : ClangTidyCheck(Name, Context), + StringLikeClasses(utils::options::parseStringList( + Options.get("StringLikeClasses", DefaultStringLikeClasses))) {} + +void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) { + const auto ZeroLiteral = integerLiteral(equals(0)); + const auto StringClassMatcher = cxxRecordDecl(hasAnyName(StringLikeClasses)); + const auto StringType = hasUnqualifiedDesugaredType( + recordType(hasDeclaration(StringClassMatcher))); + + const auto StringFind = cxxMemberCallExpr( + // .find()-call on a string... + callee(cxxMethodDecl(hasName("find")).bind("findfun")), + on(hasType(StringType)), ---------------- PiotrZSL wrote:
this wont work with class inheritence, if someone derive from std::string, instead you could use: callee(cxxMethodDecl(ofClass(hasAnyName....))) https://github.com/llvm/llvm-project/pull/72385 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits