[clang-tools-extra] d5953e3 - [clangd] Use StringRef::{starts,ends}_with (NFC)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 13 23:26:15 PST 2023


Author: Kazu Hirata
Date: 2023-12-13T23:26:09-08:00
New Revision: d5953e3e3092f7142a07aa012fc9665ede09e53b

URL: https://github.com/llvm/llvm-project/commit/d5953e3e3092f7142a07aa012fc9665ede09e53b
DIFF: https://github.com/llvm/llvm-project/commit/d5953e3e3092f7142a07aa012fc9665ede09e53b.diff

LOG: [clangd] Use StringRef::{starts,ends}_with (NFC)

This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.

Added: 
    

Modified: 
    clang-tools-extra/clangd/AST.cpp
    clang-tools-extra/clangd/ClangdServer.cpp
    clang-tools-extra/clangd/CodeComplete.cpp
    clang-tools-extra/clangd/CodeCompletionStrings.cpp
    clang-tools-extra/clangd/CompileCommands.cpp
    clang-tools-extra/clangd/ConfigCompile.cpp
    clang-tools-extra/clangd/DumpAST.cpp
    clang-tools-extra/clangd/FileDistance.cpp
    clang-tools-extra/clangd/FindSymbols.cpp
    clang-tools-extra/clangd/Format.cpp
    clang-tools-extra/clangd/Headers.cpp
    clang-tools-extra/clangd/Hover.cpp
    clang-tools-extra/clangd/IncludeCleaner.cpp
    clang-tools-extra/clangd/IncludeFixer.cpp
    clang-tools-extra/clangd/InlayHints.cpp
    clang-tools-extra/clangd/JSONTransport.cpp
    clang-tools-extra/clangd/ParsedAST.cpp
    clang-tools-extra/clangd/PathMapping.cpp
    clang-tools-extra/clangd/Protocol.cpp
    clang-tools-extra/clangd/SourceCode.cpp
    clang-tools-extra/clangd/SystemIncludeExtractor.cpp
    clang-tools-extra/clangd/URI.cpp
    clang-tools-extra/clangd/index/Merge.cpp
    clang-tools-extra/clangd/index/Serialization.cpp
    clang-tools-extra/clangd/index/StdLib.cpp
    clang-tools-extra/clangd/index/SymbolCollector.cpp
    clang-tools-extra/clangd/index/dex/Dex.cpp
    clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
    clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
    clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
    clang-tools-extra/clangd/support/Markup.cpp
    clang-tools-extra/clangd/support/ThreadsafeFS.cpp
    clang-tools-extra/clangd/tool/ClangdMain.cpp
    clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
    clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
    clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
    clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
    clang-tools-extra/clangd/unittests/IndexActionTests.cpp
    clang-tools-extra/clangd/unittests/InlayHintTests.cpp
    clang-tools-extra/clangd/unittests/InsertionPointTests.cpp
    clang-tools-extra/clangd/unittests/StdLibTests.cpp
    clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp
index 5b81ec213ff984..ae79eb21de9470 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -193,7 +193,7 @@ std::string printQualifiedName(const NamedDecl &ND) {
   Policy.AnonymousTagLocations = false;
   ND.printQualifiedName(OS, Policy);
   OS.flush();
-  assert(!StringRef(QName).startswith("::"));
+  assert(!StringRef(QName).starts_with("::"));
   return QName;
 }
 
@@ -696,7 +696,7 @@ std::string getQualification(ASTContext &Context,
                              const NamedDecl *ND,
                              llvm::ArrayRef<std::string> VisibleNamespaces) {
   for (llvm::StringRef NS : VisibleNamespaces) {
-    assert(NS.endswith("::"));
+    assert(NS.ends_with("::"));
     (void)NS;
   }
   return getQualification(

diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 13d788162817fb..6fb2641e8793db 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -437,7 +437,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
     ParseInputs ParseInput{IP->Command, &getHeaderFS(), IP->Contents.str()};
     // FIXME: Add traling new line if there is none at eof, workaround a crash,
     // see https://github.com/clangd/clangd/issues/332
-    if (!IP->Contents.endswith("\n"))
+    if (!IP->Contents.ends_with("\n"))
       ParseInput.Contents.append("\n");
     ParseInput.Index = Index;
 
@@ -488,7 +488,7 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos,
     ParseInputs ParseInput{IP->Command, &getHeaderFS(), IP->Contents.str()};
     // FIXME: Add traling new line if there is none at eof, workaround a crash,
     // see https://github.com/clangd/clangd/issues/332
-    if (!IP->Contents.endswith("\n"))
+    if (!IP->Contents.ends_with("\n"))
       ParseInput.Contents.append("\n");
     ParseInput.Index = Index;
     CB(clangd::signatureHelp(File, Pos, *PreambleData, ParseInput,
@@ -661,7 +661,7 @@ void ClangdServer::codeAction(const CodeActionInputs &Params,
             return true;
           return llvm::any_of(Only, [&](llvm::StringRef Base) {
             return Kind.consume_front(Base) &&
-                   (Kind.empty() || Kind.startswith("."));
+                   (Kind.empty() || Kind.starts_with("."));
           });
         };
 

diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 5eef43e93cb519..0e5f08cec440ce 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -610,7 +610,7 @@ struct CodeCompletionBuilder {
       //   foo<${1:class}>(${2:int p1}).
       //   We transform this pattern to '<$1>()$0' or '<$0>()'.
 
-      bool EmptyArgs = llvm::StringRef(*Snippet).endswith("()");
+      bool EmptyArgs = llvm::StringRef(*Snippet).ends_with("()");
       if (Snippet->front() == '<')
         return EmptyArgs ? "<$1>()$0" : "<$1>($0)";
       if (Snippet->front() == '(')
@@ -625,7 +625,7 @@ struct CodeCompletionBuilder {
 
       // Classes and template using aliases can only have template arguments,
       // e.g. Foo<${1:class}>.
-      if (llvm::StringRef(*Snippet).endswith("<>"))
+      if (llvm::StringRef(*Snippet).ends_with("<>"))
         return "<>"; // can happen with defaulted template arguments.
       return "<$0>";
     }
@@ -1748,7 +1748,7 @@ class CodeCompleteFlow {
         S.append("::"); // visibleNamespaces doesn't include trailing ::.
     if (HeuristicPrefix.Qualifier.empty())
       AllScopes = Opts.AllScopes;
-    else if (HeuristicPrefix.Qualifier.startswith("::")) {
+    else if (HeuristicPrefix.Qualifier.starts_with("::")) {
       Scopes.QueryScopes = {""};
       Scopes.UnresolvedQualifier =
           std::string(HeuristicPrefix.Qualifier.drop_front(2));
@@ -2130,7 +2130,7 @@ CompletionPrefix guessCompletionPrefix(llvm::StringRef Content,
   Result.Name = Content.slice(Rest.size(), Offset);
 
   // Consume qualifiers.
-  while (Rest.consume_back("::") && !Rest.endswith(":")) // reject ::::
+  while (Rest.consume_back("::") && !Rest.ends_with(":")) // reject ::::
     while (!Rest.empty() && isAsciiIdentifierContinue(Rest.back()))
       Rest = Rest.drop_back();
   Result.Qualifier =
@@ -2175,7 +2175,7 @@ CodeCompleteResult codeCompleteComment(PathRef FileName, unsigned Offset,
   Result.CompletionRange = CompletionRange;
   Result.Context = CodeCompletionContext::CCC_NaturalLanguage;
   for (llvm::StringRef Name : ParamNames) {
-    if (!Name.startswith(Prefix))
+    if (!Name.starts_with(Prefix))
       continue;
     CodeCompletion Item;
     Item.Name = Name.str() + "=*/";
@@ -2197,7 +2197,7 @@ maybeFunctionArgumentCommentStart(llvm::StringRef Content) {
   while (!Content.empty() && isAsciiIdentifierContinue(Content.back()))
     Content = Content.drop_back();
   Content = Content.rtrim();
-  if (Content.endswith("/*"))
+  if (Content.ends_with("/*"))
     return Content.size() - 2;
   return std::nullopt;
 }
@@ -2408,12 +2408,12 @@ bool allowImplicitCompletion(llvm::StringRef Content, unsigned Offset) {
     Content = Content.substr(Pos + 1);
 
   // Complete after scope operators.
-  if (Content.endswith(".") || Content.endswith("->") ||
-      Content.endswith("::") || Content.endswith("/*"))
+  if (Content.ends_with(".") || Content.ends_with("->") ||
+      Content.ends_with("::") || Content.ends_with("/*"))
     return true;
   // Complete after `#include <` and #include `<foo/`.
-  if ((Content.endswith("<") || Content.endswith("\"") ||
-       Content.endswith("/")) &&
+  if ((Content.ends_with("<") || Content.ends_with("\"") ||
+       Content.ends_with("/")) &&
       isIncludeFile(Content))
     return true;
 

diff  --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
index 8dffed0f9c3662..2075e5965f181e 100644
--- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -23,7 +23,7 @@ namespace {
 
 bool isInformativeQualifierChunk(CodeCompletionString::Chunk const &Chunk) {
   return Chunk.Kind == CodeCompletionString::CK_Informative &&
-         llvm::StringRef(Chunk.Text).endswith("::");
+         llvm::StringRef(Chunk.Text).ends_with("::");
 }
 
 void appendEscapeSnippet(const llvm::StringRef Text, std::string *Out) {
@@ -165,7 +165,7 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature,
       //   Completing a method declaration itself (not a method expression) is
       //   similar except that we use the `RequiredQualifiers` to store the
       //   text before the selector, e.g. `- (void)`.
-      if (!llvm::StringRef(Chunk.Text).endswith(":")) { // Treat as C++.
+      if (!llvm::StringRef(Chunk.Text).ends_with(":")) { // Treat as C++.
         if (RequiredQualifiers)
           *RequiredQualifiers = std::move(*Signature);
         Signature->clear();

diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp b/clang-tools-extra/clangd/CompileCommands.cpp
index e116a739774b85..f43ce928463b90 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -338,7 +338,7 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
   };
 
   llvm::erase_if(Cmd, [](llvm::StringRef Elem) {
-    return Elem.startswith("--save-temps") || Elem.startswith("-save-temps");
+    return Elem.starts_with("--save-temps") || Elem.starts_with("-save-temps");
   });
 
   std::vector<std::string> ToAppend;
@@ -587,7 +587,7 @@ const ArgStripper::Rule *ArgStripper::matchingRule(llvm::StringRef Arg,
       continue; // not applicable to current driver mode
     if (BestRule && BestRule->Priority < R.Priority)
       continue; // lower-priority than best candidate.
-    if (!Arg.startswith(R.Text))
+    if (!Arg.starts_with(R.Text))
       continue; // current arg doesn't match the prefix string
     bool PrefixMatch = Arg.size() > R.Text.size();
     // Can rule apply as an exact/prefix match?

diff  --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index 0c9fc27643be87..5bb2eb4a9f803f 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -490,7 +490,7 @@ struct FragmentCompiler {
     StringRef Str = StringRef(*Arg).trim();
     // Don't support negating here, its handled if the item is in the Add or
     // Remove list.
-    if (Str.startswith("-") || Str.contains(',')) {
+    if (Str.starts_with("-") || Str.contains(',')) {
       diag(Error, "Invalid clang-tidy check name", Arg.Range);
       return;
     }

diff  --git a/clang-tools-extra/clangd/DumpAST.cpp b/clang-tools-extra/clangd/DumpAST.cpp
index 85f2592445f2a5..b0cec65c39fa31 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -118,8 +118,8 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
   std::string getKind(const Decl *D) { return D->getDeclKindName(); }
   std::string getKind(const Stmt *S) {
     std::string Result = S->getStmtClassName();
-    if (llvm::StringRef(Result).endswith("Stmt") ||
-        llvm::StringRef(Result).endswith("Expr"))
+    if (llvm::StringRef(Result).ends_with("Stmt") ||
+        llvm::StringRef(Result).ends_with("Expr"))
       Result.resize(Result.size() - 4);
     return Result;
   }

diff  --git a/clang-tools-extra/clangd/FileDistance.cpp b/clang-tools-extra/clangd/FileDistance.cpp
index 09a9e80b7847a6..06c1a8bc92a862 100644
--- a/clang-tools-extra/clangd/FileDistance.cpp
+++ b/clang-tools-extra/clangd/FileDistance.cpp
@@ -201,7 +201,7 @@ createScopeFileDistance(llvm::ArrayRef<std::string> QueryScopes) {
     // place of enclosing namespaces (e.g. in implementation files).
     if (S == Preferred)
       Param.Cost = S == "" ? 4 : 0;
-    else if (Preferred.startswith(S) && !S.empty())
+    else if (Preferred.starts_with(S) && !S.empty())
       continue; // just rely on up-traversals.
     else
       Param.Cost = S == "" ? 6 : 2;

diff  --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp
index 790ee9af8f4acf..5b3e46a7b4dc16 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -41,8 +41,8 @@ struct ScoredSymbolGreater {
 
 // Returns true if \p Query can be found as a sub-sequence inside \p Scope.
 bool approximateScopeMatch(llvm::StringRef Scope, llvm::StringRef Query) {
-  assert(Scope.empty() || Scope.endswith("::"));
-  assert(Query.empty() || Query.endswith("::"));
+  assert(Scope.empty() || Scope.ends_with("::"));
+  assert(Query.empty() || Query.ends_with("::"));
   while (!Scope.empty() && !Query.empty()) {
     auto Colons = Scope.find("::");
     assert(Colons != llvm::StringRef::npos);

diff  --git a/clang-tools-extra/clangd/Format.cpp b/clang-tools-extra/clangd/Format.cpp
index c3e92636d19572..272a34d4ed7972 100644
--- a/clang-tools-extra/clangd/Format.cpp
+++ b/clang-tools-extra/clangd/Format.cpp
@@ -180,7 +180,7 @@ IncrementalChanges getIncrementalChangesAfterNewline(llvm::StringRef Code,
   bool NewLineIsComment = !commentMarker(Indentation).empty();
   if (!CommentMarker.empty() &&
       (NewLineIsComment || !commentMarker(NextLine).empty() ||
-       (!TrailingTrim.empty() && !TrailingTrim.startswith("//")))) {
+       (!TrailingTrim.empty() && !TrailingTrim.starts_with("//")))) {
     // We indent the new comment to match the previous one.
     StringRef PreComment =
         Leading.take_front(CommentMarker.data() - Leading.data());
@@ -197,8 +197,8 @@ IncrementalChanges getIncrementalChangesAfterNewline(llvm::StringRef Code,
   }
 
   // If we put a the newline inside a {} pair, put } on its own line...
-  if (CommentMarker.empty() && Leading.endswith("{") &&
-      Trailing.startswith("}")) {
+  if (CommentMarker.empty() && Leading.ends_with("{") &&
+      Trailing.starts_with("}")) {
     cantFail(
         Result.Changes.add(replacement(Code, Trailing.take_front(1), "\n}")));
     // ...and format it.

diff  --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp
index 6005069be01160..076e636e0e2819 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -82,7 +82,7 @@ class IncludeStructure::RecordHeaders : public PPCallbacks {
     if (File) {
       auto IncludingFileEntry = SM.getFileEntryRefForID(SM.getFileID(HashLoc));
       if (!IncludingFileEntry) {
-        assert(SM.getBufferName(HashLoc).startswith("<") &&
+        assert(SM.getBufferName(HashLoc).starts_with("<") &&
                "Expected #include location to be a file or <built-in>");
         // Treat as if included from the main file.
         IncludingFileEntry = SM.getFileEntryRefForID(MainFID);
@@ -131,7 +131,7 @@ class IncludeStructure::RecordHeaders : public PPCallbacks {
 };
 
 bool isLiteralInclude(llvm::StringRef Include) {
-  return Include.startswith("<") || Include.startswith("\"");
+  return Include.starts_with("<") || Include.starts_with("\"");
 }
 
 bool HeaderFile::valid() const {
@@ -316,7 +316,7 @@ IncludeInserter::insert(llvm::StringRef VerbatimHeader,
   std::optional<TextEdit> Edit;
   if (auto Insertion =
           Inserter.insert(VerbatimHeader.trim("\"<>"),
-                          VerbatimHeader.startswith("<"), Directive))
+                          VerbatimHeader.starts_with("<"), Directive))
     Edit = replacementToEdit(Code, *Insertion);
   return Edit;
 }

diff  --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp
index a868d3bb4e3fa1..82323fe16c82b6 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -960,7 +960,7 @@ std::optional<HoverInfo> getHoverContents(const Attr *A, ParsedAST &AST) {
 }
 
 bool isParagraphBreak(llvm::StringRef Rest) {
-  return Rest.ltrim(" \t").startswith("\n");
+  return Rest.ltrim(" \t").starts_with("\n");
 }
 
 bool punctuationIndicatesLineBreak(llvm::StringRef Line) {
@@ -984,7 +984,7 @@ bool isHardLineBreakIndicator(llvm::StringRef Rest) {
 
   if (llvm::isDigit(Rest.front())) {
     llvm::StringRef AfterDigit = Rest.drop_while(llvm::isDigit);
-    if (AfterDigit.startswith(".") || AfterDigit.startswith(")"))
+    if (AfterDigit.starts_with(".") || AfterDigit.starts_with(")"))
       return true;
   }
   return false;

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp
index dda7c9f581f69c..2f34c949349200 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -95,7 +95,7 @@ bool mayConsiderUnused(const Inclusion &Inc, ParsedAST &AST,
       // Since most private -> public mappings happen in a verbatim way, we
       // check textually here. This might go wrong in presence of symlinks or
       // header mappings. But that's not 
diff erent than rest of the places.
-      if (AST.tuPath().endswith(PHeader))
+      if (AST.tuPath().ends_with(PHeader))
         return false;
     }
   }

diff  --git a/clang-tools-extra/clangd/IncludeFixer.cpp b/clang-tools-extra/clangd/IncludeFixer.cpp
index 0c4d011b80372b..fadd1105691fc0 100644
--- a/clang-tools-extra/clangd/IncludeFixer.cpp
+++ b/clang-tools-extra/clangd/IncludeFixer.cpp
@@ -416,7 +416,7 @@ std::optional<CheapUnresolvedName> extractUnresolvedNameCheaply(
         //     namespace clang { clangd::X; }
         // In this case, we use the "typo" specifier as extra scope instead
         // of using the scope assumed by sema.
-        if (!Spelling || llvm::StringRef(SpecifiedNS).endswith(*Spelling)) {
+        if (!Spelling || llvm::StringRef(SpecifiedNS).ends_with(*Spelling)) {
           Result.ResolvedScope = std::move(SpecifiedNS);
         } else {
           Result.UnresolvedScope = std::move(*Spelling);

diff  --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp
index b540c273cbd596..6fbb310b660a17 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -1040,7 +1040,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
     if (!SourcePrefix.consume_back(ParamName))
       return false;
     SourcePrefix = SourcePrefix.rtrim(IgnoreChars);
-    return SourcePrefix.endswith("/*");
+    return SourcePrefix.ends_with("/*");
   }
 
   // If "E" spells a single unqualified identifier, return that name.

diff  --git a/clang-tools-extra/clangd/JSONTransport.cpp b/clang-tools-extra/clangd/JSONTransport.cpp
index 9dc0df807aa346..346c7dfb66a1db 100644
--- a/clang-tools-extra/clangd/JSONTransport.cpp
+++ b/clang-tools-extra/clangd/JSONTransport.cpp
@@ -240,7 +240,7 @@ bool JSONTransport::readStandardMessage(std::string &JSON) {
     // We allow comments in headers. Technically this isn't part
 
     // of the LSP specification, but makes writing tests easier.
-    if (LineRef.startswith("#"))
+    if (LineRef.starts_with("#"))
       continue;
 
     // Content-Length is a mandatory header, and the only one we handle.
@@ -304,7 +304,7 @@ bool JSONTransport::readDelimitedMessage(std::string &JSON) {
   while (readLine(In, Line)) {
     InMirror << Line;
     auto LineRef = Line.str().trim();
-    if (LineRef.startswith("#")) // comment
+    if (LineRef.starts_with("#")) // comment
       continue;
 
     // found a delimiter

diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp
index edd0f77b1031ef..d91ce7283ecee4 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -288,7 +288,7 @@ class TidyDiagnosticGroups {
       if (Glob) {
         // Is this clang-diagnostic-*, or *, or so?
         // (We ignore all other types of globs).
-        if (CDPrefix.startswith(Check)) {
+        if (CDPrefix.starts_with(Check)) {
           Default = Enable;
           Exceptions.clear();
         }

diff  --git a/clang-tools-extra/clangd/PathMapping.cpp b/clang-tools-extra/clangd/PathMapping.cpp
index 2554d34d96b9df..4b93ff2c60c5c6 100644
--- a/clang-tools-extra/clangd/PathMapping.cpp
+++ b/clang-tools-extra/clangd/PathMapping.cpp
@@ -21,7 +21,7 @@ std::optional<std::string> doPathMapping(llvm::StringRef S,
                                          PathMapping::Direction Dir,
                                          const PathMappings &Mappings) {
   // Return early to optimize for the common case, wherein S is not a file URI
-  if (!S.startswith("file://"))
+  if (!S.starts_with("file://"))
     return std::nullopt;
   auto Uri = URI::parse(S);
   if (!Uri) {

diff  --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp
index e44aee2d478194..a6370649f5ad1c 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -844,7 +844,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const SymbolDetails &S) {
   if (!S.containerName.empty()) {
     O << S.containerName;
     llvm::StringRef ContNameRef;
-    if (!ContNameRef.endswith("::")) {
+    if (!ContNameRef.ends_with("::")) {
       O << " ";
     }
   }

diff  --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp
index 31323c08cf1ddf..835038423fdf37 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -891,10 +891,10 @@ llvm::StringSet<> collectWords(llvm::StringRef Content) {
 static bool isLikelyIdentifier(llvm::StringRef Word, llvm::StringRef Before,
                                llvm::StringRef After) {
   // `foo` is an identifier.
-  if (Before.endswith("`") && After.startswith("`"))
+  if (Before.ends_with("`") && After.starts_with("`"))
     return true;
   // In foo::bar, both foo and bar are identifiers.
-  if (Before.endswith("::") || After.startswith("::"))
+  if (Before.ends_with("::") || After.starts_with("::"))
     return true;
   // Doxygen tags like \c foo indicate identifiers.
   // Don't search too far back.
@@ -1180,7 +1180,7 @@ EligibleRegion getEligiblePoints(llvm::StringRef Code,
     }
 
     // Ignore namespaces that are not a prefix of the target.
-    if (!FullyQualifiedName.startswith(CurrentNamespace))
+    if (!FullyQualifiedName.starts_with(CurrentNamespace))
       return;
 
     // Prefer the namespace that shares the longest prefix with target.
@@ -1213,14 +1213,14 @@ bool isHeaderFile(llvm::StringRef FileName,
 
 bool isProtoFile(SourceLocation Loc, const SourceManager &SM) {
   auto FileName = SM.getFilename(Loc);
-  if (!FileName.endswith(".proto.h") && !FileName.endswith(".pb.h"))
+  if (!FileName.ends_with(".proto.h") && !FileName.ends_with(".pb.h"))
     return false;
   auto FID = SM.getFileID(Loc);
   // All proto generated headers should start with this line.
   static const char *ProtoHeaderComment =
       "// Generated by the protocol buffer compiler.  DO NOT EDIT!";
   // Double check that this is an actual protobuf header.
-  return SM.getBufferData(FID).startswith(ProtoHeaderComment);
+  return SM.getBufferData(FID).starts_with(ProtoHeaderComment);
 }
 
 SourceLocation translatePreamblePatchLocation(SourceLocation Loc,
@@ -1230,7 +1230,7 @@ SourceLocation translatePreamblePatchLocation(SourceLocation Loc,
     auto IncludeLoc = SM.getIncludeLoc(DefFile);
     // Preamble patch is included inside the builtin file.
     if (IncludeLoc.isValid() && SM.isWrittenInBuiltinFile(IncludeLoc) &&
-        FE->getName().endswith(PreamblePatch::HeaderName)) {
+        FE->getName().ends_with(PreamblePatch::HeaderName)) {
       auto Presumed = SM.getPresumedLoc(Loc);
       // Check that line directive is pointing at main file.
       if (Presumed.isValid() && Presumed.getFileID().isInvalid() &&

diff  --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index ea98c7d948a2f6..d4b9b173d149da 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -146,13 +146,13 @@ struct DriverArgs {
           Stdlib = Cmd.CommandLine[I + 1];
       } else if (Arg.consume_front("-stdlib=")) {
         Stdlib = Arg.str();
-      } else if (Arg.startswith("-specs=")) {
+      } else if (Arg.starts_with("-specs=")) {
         // clang requires a single token like `-specs=file` or `--specs=file`,
         // but gcc will accept two tokens like `--specs file`. Since the
         // compilation database is presumably correct, we just forward the flags
         // as-is.
         Specs.push_back(Arg.str());
-      } else if (Arg.startswith("--specs=")) {
+      } else if (Arg.starts_with("--specs=")) {
         Specs.push_back(Arg.str());
       } else if (Arg == "--specs" && I + 1 < E) {
         Specs.push_back(Arg.str());
@@ -282,7 +282,7 @@ std::optional<DriverInfo> parseDriverOutput(llvm::StringRef Output) {
       if (!SeenIncludes && Line.trim() == SIS) {
         SeenIncludes = true;
         State = IncludesExtracting;
-      } else if (!SeenTarget && Line.trim().startswith(TS)) {
+      } else if (!SeenTarget && Line.trim().starts_with(TS)) {
         SeenTarget = true;
         llvm::StringRef TargetLine = Line.trim();
         TargetLine.consume_front(TS);
@@ -448,7 +448,7 @@ tooling::CompileCommand &setTarget(tooling::CompileCommand &Cmd,
   if (!Target.empty()) {
     // We do not want to override existing target with extracted one.
     for (llvm::StringRef Arg : Cmd.CommandLine) {
-      if (Arg == "-target" || Arg.startswith("--target="))
+      if (Arg == "-target" || Arg.starts_with("--target="))
         return Cmd;
     }
     // Just append when `--` isn't present.

diff  --git a/clang-tools-extra/clangd/URI.cpp b/clang-tools-extra/clangd/URI.cpp
index ca65df329aeebf..11d70dc917f56b 100644
--- a/clang-tools-extra/clangd/URI.cpp
+++ b/clang-tools-extra/clangd/URI.cpp
@@ -38,7 +38,7 @@ class FileSystemScheme : public URIScheme {
   llvm::Expected<std::string>
   getAbsolutePath(llvm::StringRef Authority, llvm::StringRef Body,
                   llvm::StringRef /*HintPath*/) const override {
-    if (!Body.startswith("/"))
+    if (!Body.starts_with("/"))
       return error("File scheme: expect body to be an absolute path starting "
                    "with '/': {0}",
                    Body);
@@ -153,7 +153,7 @@ URI::URI(llvm::StringRef Scheme, llvm::StringRef Authority,
          llvm::StringRef Body)
     : Scheme(Scheme), Authority(Authority), Body(Body) {
   assert(!Scheme.empty());
-  assert((Authority.empty() || Body.startswith("/")) &&
+  assert((Authority.empty() || Body.starts_with("/")) &&
          "URI body must start with '/' when authority is present.");
 }
 
@@ -165,8 +165,7 @@ std::string URI::toString() const {
     return Result;
   // If authority if empty, we only print body if it starts with "/"; otherwise,
   // the URI is invalid.
-  if (!Authority.empty() || llvm::StringRef(Body).startswith("/"))
-  {
+  if (!Authority.empty() || llvm::StringRef(Body).starts_with("/")) {
     Result.append("//");
     percentEncode(Authority, Result);
   }

diff  --git a/clang-tools-extra/clangd/index/Merge.cpp b/clang-tools-extra/clangd/index/Merge.cpp
index 9687b36252e12c..8221d4b1f44405 100644
--- a/clang-tools-extra/clangd/index/Merge.cpp
+++ b/clang-tools-extra/clangd/index/Merge.cpp
@@ -197,7 +197,7 @@ static bool prefer(const SymbolLocation &L, const SymbolLocation &R) {
   auto HasCodeGenSuffix = [](const SymbolLocation &Loc) {
     constexpr static const char *CodegenSuffixes[] = {".proto"};
     return llvm::any_of(CodegenSuffixes, [&](llvm::StringRef Suffix) {
-      return llvm::StringRef(Loc.FileURI).endswith(Suffix);
+      return llvm::StringRef(Loc.FileURI).ends_with(Suffix);
     });
   };
   return HasCodeGenSuffix(L) && !HasCodeGenSuffix(R);

diff  --git a/clang-tools-extra/clangd/index/Serialization.cpp b/clang-tools-extra/clangd/index/Serialization.cpp
index b905f580c281c9..72a4e8b007668f 100644
--- a/clang-tools-extra/clangd/index/Serialization.cpp
+++ b/clang-tools-extra/clangd/index/Serialization.cpp
@@ -692,7 +692,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const IndexFileOut &O) {
 
 llvm::Expected<IndexFileIn> readIndexFile(llvm::StringRef Data,
                                           SymbolOrigin Origin) {
-  if (Data.startswith("RIFF")) {
+  if (Data.starts_with("RIFF")) {
     return readRIFF(Data, Origin);
   }
   if (auto YAMLContents = readYAML(Data, Origin)) {

diff  --git a/clang-tools-extra/clangd/index/StdLib.cpp b/clang-tools-extra/clangd/index/StdLib.cpp
index 390c2e41f6c0f9..921ab5d1c96d5c 100644
--- a/clang-tools-extra/clangd/index/StdLib.cpp
+++ b/clang-tools-extra/clangd/index/StdLib.cpp
@@ -167,7 +167,7 @@ SymbolSlab filter(SymbolSlab Slab, const StdLibLocation &Loc) {
         R.first->second = llvm::any_of(
             StdLibURIPrefixes,
             [&, URIStr(llvm::StringRef(URI))](const std::string &Prefix) {
-              return URIStr.startswith(Prefix);
+              return URIStr.starts_with(Prefix);
             });
       }
     }

diff  --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index aac6676a995fed..cf6102db8dd317 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -262,7 +262,7 @@ class SymbolCollector::HeaderFileURICache {
     if (Canonical.empty())
       return "";
     // If we had a mapping, always use it.
-    assert(Canonical.startswith("<") || Canonical.startswith("\""));
+    assert(Canonical.starts_with("<") || Canonical.starts_with("\""));
     return Canonical;
   }
 
@@ -414,7 +414,7 @@ class SymbolCollector::HeaderFileURICache {
                                         PP->getHeaderSearchInfo())) {
       // A .inc or .def file is often included into a real header to define
       // symbols (e.g. LLVM tablegen files).
-      if (Filename.endswith(".inc") || Filename.endswith(".def"))
+      if (Filename.ends_with(".inc") || Filename.ends_with(".def"))
         // Don't use cache reentrantly due to iterator invalidation.
         return getIncludeHeaderUncached(SM.getFileID(SM.getIncludeLoc(FID)));
       // Conservatively refuse to insert #includes to files without guards.

diff  --git a/clang-tools-extra/clangd/index/dex/Dex.cpp b/clang-tools-extra/clangd/index/dex/Dex.cpp
index 8f504fb9b7ea30..19dc3080f9f897 100644
--- a/clang-tools-extra/clangd/index/dex/Dex.cpp
+++ b/clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -395,7 +395,7 @@ generateProximityURIs(llvm::StringRef URI) {
       return Result;
   }
   // The root foo://bar/ is a proximity URI.
-  if (Path.startswith("/"))
+  if (Path.starts_with("/"))
     Result.push_back(URI.substr(0, Path.begin() + 1 - URI.data()));
   return Result;
 }

diff  --git a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
index 392960d6d6660d..cea59ae409914c 100644
--- a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -372,7 +372,7 @@ struct {
 };
 
 std::unique_ptr<SymbolIndex> openIndex(llvm::StringRef Index) {
-  return Index.startswith("remote:")
+  return Index.starts_with("remote:")
              ? remote::getClient(Index.drop_front(strlen("remote:")),
                                  ProjectRoot)
              : loadIndex(Index, SymbolOrigin::Static, /*UseDex=*/true);
@@ -424,7 +424,7 @@ int main(int argc, const char *argv[]) {
   llvm::cl::ResetCommandLineParser(); // We reuse it for REPL commands.
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
 
-  bool RemoteMode = llvm::StringRef(IndexLocation).startswith("remote:");
+  bool RemoteMode = llvm::StringRef(IndexLocation).starts_with("remote:");
   if (RemoteMode && ProjectRoot.empty()) {
     llvm::errs() << "--project-root is required in remote mode\n";
     return -1;

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
index ca96da34e09201..00c05ebdb52166 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -352,7 +352,7 @@ bool AddUsing::prepare(const Selection &Inputs) {
       splitQualifiedName(SpelledRange.text(SM));
   QualifierToSpell = getNNSLAsString(
       QualifierToRemove, Inputs.AST->getASTContext().getPrintingPolicy());
-  if (!llvm::StringRef(QualifierToSpell).endswith(SpelledQualifier) ||
+  if (!llvm::StringRef(QualifierToSpell).ends_with(SpelledQualifier) ||
       SpelledName.empty())
     return false; // What's spelled doesn't match the qualifier.
   return true;

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
index b84ae04072f2c1..fef827a801c339 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -71,7 +71,7 @@ std::optional<Path> getSourceFile(llvm::StringRef FileName,
 // Returns std::nullopt if TargetNS is not a prefix of CurContext.
 std::optional<const DeclContext *>
 findContextForNS(llvm::StringRef TargetNS, const DeclContext *CurContext) {
-  assert(TargetNS.empty() || TargetNS.endswith("::"));
+  assert(TargetNS.empty() || TargetNS.ends_with("::"));
   // Skip any non-namespace contexts, e.g. TagDecls, functions/methods.
   CurContext = CurContext->getEnclosingNamespaceContext();
   // If TargetNS is empty, it means global ns, which is translation unit.
@@ -91,7 +91,7 @@ findContextForNS(llvm::StringRef TargetNS, const DeclContext *CurContext) {
   llvm::StringRef CurrentContextNS(TargetContextNS);
   // If TargetNS is not a prefix of CurrentContext, there's no way to reach
   // it.
-  if (!CurrentContextNS.startswith(TargetNS))
+  if (!CurrentContextNS.starts_with(TargetNS))
     return std::nullopt;
 
   while (CurrentContextNS != TargetNS) {

diff  --git a/clang-tools-extra/clangd/support/Markup.cpp b/clang-tools-extra/clangd/support/Markup.cpp
index 4d17a2bf2b2b86..63aff96b02056d 100644
--- a/clang-tools-extra/clangd/support/Markup.cpp
+++ b/clang-tools-extra/clangd/support/Markup.cpp
@@ -47,7 +47,7 @@ bool looksLikeTag(llvm::StringRef Contents) {
   for (; !Contents.empty(); Contents = Contents.drop_front()) {
     if (llvm::isAlnum(Contents.front()) || llvm::isSpace(Contents.front()))
       continue;
-    if (Contents.front() == '>' || Contents.startswith("/>"))
+    if (Contents.front() == '>' || Contents.starts_with("/>"))
       return true; // May close the tag.
     if (Contents.front() == '=')
       return true; // Don't try to parse attribute values.
@@ -75,7 +75,7 @@ bool needsLeadingEscape(char C, llvm::StringRef Before, llvm::StringRef After,
   };
   auto IsBullet = [&]() {
     return StartsLine && Before.empty() &&
-           (After.empty() || After.startswith(" "));
+           (After.empty() || After.starts_with(" "));
   };
   auto SpaceSurrounds = [&]() {
     return (After.empty() || llvm::isSpace(After.front())) &&
@@ -94,12 +94,12 @@ bool needsLeadingEscape(char C, llvm::StringRef Before, llvm::StringRef After,
     // anywhere (including on another line). We must escape them all.
     return true;
   case '~': // Code block
-    return StartsLine && Before.empty() && After.startswith("~~");
+    return StartsLine && Before.empty() && After.starts_with("~~");
   case '#': { // ATX heading.
     if (!StartsLine || !Before.empty())
       return false;
     llvm::StringRef Rest = After.ltrim(C);
-    return Rest.empty() || Rest.startswith(" ");
+    return Rest.empty() || Rest.starts_with(" ");
   }
   case ']': // Link or link reference.
     // We escape ] rather than [ here, because it's more constrained:
@@ -109,7 +109,7 @@ bool needsLeadingEscape(char C, llvm::StringRef Before, llvm::StringRef After,
     //   ] by itself is a shortcut link
     //   ][...] is an out-of-line link
     // Because we never emit link references, we don't need to handle these.
-    return After.startswith(":") || After.startswith("(");
+    return After.starts_with(":") || After.starts_with("(");
   case '=': // Setex heading.
     return RulerLength() > 0;
   case '_': // Horizontal ruler or matched delimiter.
@@ -145,7 +145,7 @@ bool needsLeadingEscape(char C, llvm::StringRef Before, llvm::StringRef After,
   case '.': // Numbered list indicator. Escape 12. -> 12\. at start of line.
   case ')':
     return StartsLine && !Before.empty() &&
-           llvm::all_of(Before, llvm::isDigit) && After.startswith(" ");
+           llvm::all_of(Before, llvm::isDigit) && After.starts_with(" ");
   default:
     return false;
   }
@@ -180,12 +180,12 @@ std::string renderInlineBlock(llvm::StringRef Input) {
   }
   // If results starts with a backtick, add spaces on both sides. The spaces
   // are ignored by markdown renderers.
-  if (llvm::StringRef(R).startswith("`") || llvm::StringRef(R).endswith("`"))
+  if (llvm::StringRef(R).starts_with("`") || llvm::StringRef(R).ends_with("`"))
     return "` " + std::move(R) + " `";
   // Markdown render should ignore first and last space if both are there. We
   // add an extra pair of spaces in that case to make sure we render what the
   // user intended.
-  if (llvm::StringRef(R).startswith(" ") && llvm::StringRef(R).endswith(" "))
+  if (llvm::StringRef(R).starts_with(" ") && llvm::StringRef(R).ends_with(" "))
     return "` " + std::move(R) + " `";
   return "`" + std::move(R) + "`";
 }
@@ -250,7 +250,7 @@ std::string renderBlocks(llvm::ArrayRef<std::unique_ptr<Block>> Children,
                   return !llvm::StringRef(TrimmedText.data(),
                                           &C - TrimmedText.data() + 1)
                               // We allow at most two newlines.
-                              .endswith("\n\n\n");
+                              .ends_with("\n\n\n");
                 });
 
   return AdjustedResult;
@@ -301,7 +301,7 @@ class CodeBlock : public Block {
 // Inserts two spaces after each `\n` to indent each line. First line is not
 // indented.
 std::string indentLines(llvm::StringRef Input) {
-  assert(!Input.endswith("\n") && "Input should've been trimmed.");
+  assert(!Input.ends_with("\n") && "Input should've been trimmed.");
   std::string IndentedR;
   // We'll add 2 spaces after each new line.
   IndentedR.reserve(Input.size() + Input.count('\n') * 2);

diff  --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
index 87babef4ee8c88..0e249d07d2fd91 100644
--- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
+++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
@@ -39,7 +39,7 @@ class VolatileFileSystem : public llvm::vfs::ProxyFileSystem {
     // Try to guess preamble files, they can be memory-mapped even on Windows as
     // clangd has exclusive access to those and nothing else should touch them.
     llvm::StringRef FileName = llvm::sys::path::filename(Path);
-    if (FileName.startswith("preamble-") && FileName.endswith(".pch"))
+    if (FileName.starts_with("preamble-") && FileName.ends_with(".pch"))
       return File;
     return std::unique_ptr<VolatileFile>(new VolatileFile(std::move(*File)));
   }

diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 9fd002d0eebba5..c3ba655ee2dc6a 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -563,7 +563,7 @@ class TestScheme : public URIScheme {
     using namespace llvm::sys;
     // Still require "/" in body to mimic file scheme, as we want lengths of an
     // equivalent URI in both schemes to be the same.
-    if (!Body.startswith("/"))
+    if (!Body.starts_with("/"))
       return error(
           "Expect URI body to be an absolute path starting with '/': {0}",
           Body);

diff  --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
index e5c9fc54088068..e51942462fbdf8 100644
--- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -132,11 +132,11 @@ TEST_F(BackgroundIndexTest, Config) {
   BackgroundIndex::Options Opts;
   Opts.ContextProvider = [](PathRef P) {
     Config C;
-    if (P.endswith("foo.cpp"))
+    if (P.ends_with("foo.cpp"))
       C.CompileFlags.Edits.push_back([](std::vector<std::string> &Argv) {
         Argv = tooling::getInsertArgumentAdjuster("-Done=two")(Argv, "");
       });
-    if (P.endswith("baz.cpp"))
+    if (P.ends_with("baz.cpp"))
       C.Index.Background = Config::BackgroundPolicy::Skip;
     return Context::current().derive(Config::Key, std::move(C));
   };

diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 692c6db3c51bed..6d387fec9b3851 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -59,7 +59,7 @@ MATCHER_P(named, Name, "") { return arg.Name == Name; }
 MATCHER_P(mainFileRefs, Refs, "") { return arg.MainFileRefs == Refs; }
 MATCHER_P(scopeRefs, Refs, "") { return arg.ScopeRefsInFile == Refs; }
 MATCHER_P(nameStartsWith, Prefix, "") {
-  return llvm::StringRef(arg.Name).startswith(Prefix);
+  return llvm::StringRef(arg.Name).starts_with(Prefix);
 }
 MATCHER_P(filterText, F, "") { return arg.FilterText == F; }
 MATCHER_P(scope, S, "") { return arg.Scope == S; }

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index a52b647b0029b4..37643e5afa2304 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1935,7 +1935,7 @@ TEST(DiagnosticsTest, IncludeCleaner) {
   Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
   // Set filtering.
   Cfg.Diagnostics.Includes.IgnoreHeader.emplace_back(
-      [](llvm::StringRef Header) { return Header.endswith("ignore.h"); });
+      [](llvm::StringRef Header) { return Header.ends_with("ignore.h"); });
   WithContextValue WithCfg(Config::Key, std::move(Cfg));
   auto AST = TU.build();
   EXPECT_THAT(

diff  --git a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
index 38bf66a1e25eb5..2a6ae9c325b736 100644
--- a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -228,14 +228,14 @@ TEST(GlobalCompilationDatabaseTest, DiscoveryWithNestedCDBs) {
     DirectoryBasedGlobalCompilationDatabase::Options Opts(FS);
     Opts.ContextProvider = [&](llvm::StringRef Path) {
       Config Cfg;
-      if (Path.endswith("a.cc")) {
+      if (Path.ends_with("a.cc")) {
         // a.cc uses another directory's CDB, so it won't be discovered.
         Cfg.CompileFlags.CDBSearch.Policy = Config::CDBSearchSpec::FixedDir;
         Cfg.CompileFlags.CDBSearch.FixedCDBPath = testPath("foo");
-      } else if (Path.endswith("gen.cc")) {
+      } else if (Path.ends_with("gen.cc")) {
         // gen.cc has CDB search disabled, so it won't be discovered.
         Cfg.CompileFlags.CDBSearch.Policy = Config::CDBSearchSpec::NoCDBSearch;
-      } else if (Path.endswith("gen2.cc")) {
+      } else if (Path.ends_with("gen2.cc")) {
         // gen2.cc explicitly lists this directory, so it will be discovered.
         Cfg.CompileFlags.CDBSearch.Policy = Config::CDBSearchSpec::FixedDir;
         Cfg.CompileFlags.CDBSearch.FixedCDBPath = testRoot();

diff  --git a/clang-tools-extra/clangd/unittests/IndexActionTests.cpp b/clang-tools-extra/clangd/unittests/IndexActionTests.cpp
index fad751bd0f7dc2..fa3d9c3212f9ca 100644
--- a/clang-tools-extra/clangd/unittests/IndexActionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IndexActionTests.cpp
@@ -280,7 +280,7 @@ TEST_F(IndexActionTest, SkipFiles) {
     auto unskippable2() { return S(); }
   )cpp");
   Opts.FileFilter = [](const SourceManager &SM, FileID F) {
-    return !SM.getFileEntryRefForID(F)->getName().endswith("bad.h");
+    return !SM.getFileEntryRefForID(F)->getName().ends_with("bad.h");
   };
   IndexFileIn IndexFile = runIndexingAction(MainFilePath, {"-std=c++14"});
   EXPECT_THAT(*IndexFile.Symbols,
@@ -333,7 +333,7 @@ TEST_F(IndexActionTest, SymbolFromCC) {
  void foo();
  )cpp");
   Opts.FileFilter = [](const SourceManager &SM, FileID F) {
-    return !SM.getFileEntryRefForID(F)->getName().endswith("main.h");
+    return !SM.getFileEntryRefForID(F)->getName().ends_with("main.h");
   };
   IndexFileIn IndexFile = runIndexingAction(MainFilePath, {"-std=c++14"});
   EXPECT_THAT(*IndexFile.Symbols,

diff  --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 6e91053632e00b..0ca95b5fed5d31 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -58,8 +58,8 @@ struct ExpectedHint {
 MATCHER_P2(HintMatcher, Expected, Code, llvm::to_string(Expected)) {
   llvm::StringRef ExpectedView(Expected.Label);
   if (arg.label != ExpectedView.trim(" ") ||
-      arg.paddingLeft != ExpectedView.startswith(" ") ||
-      arg.paddingRight != ExpectedView.endswith(" ")) {
+      arg.paddingLeft != ExpectedView.starts_with(" ") ||
+      arg.paddingRight != ExpectedView.ends_with(" ")) {
     *result_listener << "label is '" << arg.label << "'";
     return false;
   }

diff  --git a/clang-tools-extra/clangd/unittests/InsertionPointTests.cpp b/clang-tools-extra/clangd/unittests/InsertionPointTests.cpp
index 62c06bb863772f..3d5365a099f0ad 100644
--- a/clang-tools-extra/clangd/unittests/InsertionPointTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InsertionPointTests.cpp
@@ -38,7 +38,7 @@ TEST(InsertionPointTests, Generic) {
       [&](llvm::StringLiteral S) -> std::function<bool(const Decl *)> {
     return [S](const Decl *D) {
       if (const auto *ND = llvm::dyn_cast<NamedDecl>(D))
-        return llvm::StringRef(ND->getNameAsString()).startswith(S);
+        return llvm::StringRef(ND->getNameAsString()).starts_with(S);
       return false;
     };
   };

diff  --git a/clang-tools-extra/clangd/unittests/StdLibTests.cpp b/clang-tools-extra/clangd/unittests/StdLibTests.cpp
index ef47141bade153..a39d34ea33811a 100644
--- a/clang-tools-extra/clangd/unittests/StdLibTests.cpp
+++ b/clang-tools-extra/clangd/unittests/StdLibTests.cpp
@@ -126,7 +126,7 @@ TEST(StdLibTests, StdLibSet) {
 
 MATCHER_P(StdlibSymbol, Name, "") {
   return arg.Name == Name && arg.Includes.size() == 1 &&
-         llvm::StringRef(arg.Includes.front().Header).startswith("<");
+         llvm::StringRef(arg.Includes.front().Header).starts_with("<");
 }
 
 TEST(StdLibTests, EndToEnd) {

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp b/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
index 51071d89a66e51..81e65ede00781a 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
@@ -43,7 +43,7 @@ llvm::StringRef unwrap(Context Ctx, llvm::StringRef Outer) {
   auto Wrapping = wrapping(Ctx);
   // Unwrap only if the code matches the expected wrapping.
   // Don't allow the begin/end wrapping to overlap!
-  if (Outer.startswith(Wrapping.first) && Outer.endswith(Wrapping.second) &&
+  if (Outer.starts_with(Wrapping.first) && Outer.ends_with(Wrapping.second) &&
       Outer.size() >= Wrapping.first.size() + Wrapping.second.size())
     return Outer.drop_front(Wrapping.first.size())
         .drop_back(Wrapping.second.size());


        


More information about the cfe-commits mailing list