[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.
This commit is contained in:
parent
76bbbcb41b
commit
d5953e3e30
@ -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(
|
||||
|
||||
@ -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("."));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -610,7 +610,7 @@ private:
|
||||
// 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 @@ private:
|
||||
|
||||
// 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 @@ public:
|
||||
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;
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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?
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -82,7 +82,7 @@ public:
|
||||
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 @@ private:
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 different than rest of the places.
|
||||
if (AST.tuPath().endswith(PHeader))
|
||||
if (AST.tuPath().ends_with(PHeader))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -1040,7 +1040,7 @@ private:
|
||||
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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -288,7 +288,7 @@ public:
|
||||
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();
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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 << " ";
|
||||
}
|
||||
}
|
||||
|
||||
@ -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() &&
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -38,7 +38,7 @@ public:
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)) {
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -262,7 +262,7 @@ public:
|
||||
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 @@ private:
|
||||
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.
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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 @@ private:
|
||||
// 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);
|
||||
|
||||
@ -39,7 +39,7 @@ public:
|
||||
// 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)));
|
||||
}
|
||||
|
||||
@ -563,7 +563,7 @@ public:
|
||||
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);
|
||||
|
||||
@ -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));
|
||||
};
|
||||
|
||||
@ -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; }
|
||||
|
||||
@ -1935,7 +1935,7 @@ $fix[[ $diag[[#include "unused.h"]]
|
||||
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(
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user