Skip to content

Commit

Permalink
Use StringRef::{starts,ends}_with (NFC)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kazutakahirata committed Dec 16, 2023
1 parent ee667db commit b8f89b8
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/index/remote/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ std::unique_ptr<Logger> makeLogger(llvm::StringRef LogPrefix,
void log(Level L, const char *Fmt,
const llvm::formatv_object_base &Message) override {
if (Context::current().get(CurrentRequest) == nullptr ||
llvm::StringRef(Fmt).startswith("[public]"))
llvm::StringRef(Fmt).starts_with("[public]"))
return StreamLogger::log(L, Fmt, Message);
if (L >= Error)
return StreamLogger::log(L, Fmt,
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Index/recursive-cxx-member-calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ using namespace clang;

AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
llvm::StringRef AttrName = Name->getName();
if (AttrName.startswith("__") && AttrName.endswith("__"))
if (AttrName.starts_with("__") && AttrName.ends_with("__"))
AttrName = AttrName.substr(2, AttrName.size() - 4);

return llvm::StringSwitch < AttributeList::Kind > (AttrName)
Expand Down
6 changes: 3 additions & 3 deletions libc/utils/HdrGen/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void Generator::parseCommandArgs(llvm::StringRef ArgStr, ArgVector &Args) {
ArgStr.split(Args, ",");
for (llvm::StringRef &A : Args) {
A = A.trim(' ');
if (A.startswith(ParamNamePrefix) && A.endswith(ParamNameSuffix)) {
if (A.starts_with(ParamNamePrefix) && A.ends_with(ParamNameSuffix)) {
A = A.drop_front(ParamNamePrefixSize).drop_back(ParamNameSuffixSize);
A = ArgMap[std::string(A)];
}
Expand All @@ -80,7 +80,7 @@ void Generator::generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
Content = P.second;

llvm::StringRef Line = P.first.trim(' ');
if (Line.startswith(CommandPrefix)) {
if (Line.starts_with(CommandPrefix)) {
Line = Line.drop_front(CommandPrefixSize);

P = Line.split("(");
Expand All @@ -107,7 +107,7 @@ void Generator::generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
Command::ErrorReporter Reporter(
llvm::SMLoc::getFromPointer(CommandName.data()), SrcMgr);
Cmd->run(OS, Args, StdHeader, Records, Reporter);
} else if (!Line.startswith(CommentPrefix)) {
} else if (!Line.starts_with(CommentPrefix)) {
// There is no comment or command on this line so we just write it as is.
OS << P.first << "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch2/toyc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int dumpMLIR() {

// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
!llvm::StringRef(inputFilename).ends_with(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch3/toyc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
!llvm::StringRef(inputFilename).ends_with(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch4/toyc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
!llvm::StringRef(inputFilename).ends_with(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch5/toyc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
!llvm::StringRef(inputFilename).ends_with(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch6/toyc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int loadMLIR(mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
!llvm::StringRef(inputFilename).ends_with(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch7/toyc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int loadMLIR(mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
!llvm::StringRef(inputFilename).ends_with(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ struct GenericKernelTy {
/// Return true if this kernel is a constructor or destructor.
bool isCtorOrDtor() const {
// TODO: This is not a great solution and should be revisited.
return StringRef(Name).endswith("tor");
return StringRef(Name).ends_with("tor");
}

/// Get the kernel image.
Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ struct CUDAPluginTy final : public GenericPluginTy {

StringRef ArchStr(Info->Arch);
StringRef PrefixStr("sm_");
if (!ArchStr.startswith(PrefixStr))
if (!ArchStr.starts_with(PrefixStr))
return Plugin::error("Unrecognized image arch %s", ArchStr.data());

int32_t ImageMajor = ArchStr[PrefixStr.size() + 0] - '0';
Expand Down

0 comments on commit b8f89b8

Please sign in to comment.