Skip to content

Rename StringRef::endswith references to StringRef::ends_with #72744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/FineGrainedDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ template <typename GraphT> class DotFileEmitter {
includeExternals || n->getKey().getKind() != NodeKind::externalDepend;
bool apiPredicate =
includeAPINotes ||
!StringRef(n->getKey().humanReadableName()).endswith(".apinotes");
!StringRef(n->getKey().humanReadableName()).ends_with(".apinotes");
return externalPredicate && apiPredicate;
}
bool includeGraphArc(const NodeT *def, const NodeT *use) const {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11782,7 +11782,7 @@ bool MacroDecl::isUniqueMacroName(StringRef name) {
name = name.drop_back();

// Check for fMu.
return name.endswith("fMu");
return name.ends_with("fMu");
}

bool MacroDecl::isUniqueMacroName(DeclBaseName name) {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/FineGrainedDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::optional<SourceFileDepGraph>
SourceFileDepGraph::loadFromPath(StringRef path, const bool allowSwiftModule) {
const bool treatAsModule =
allowSwiftModule &&
path.endswith(file_types::getExtension(file_types::TY_SwiftModuleFile));
path.ends_with(file_types::getExtension(file_types::TY_SwiftModuleFile));
auto bufferOrError = llvm::MemoryBuffer::getFile(path);
if (!bufferOrError)
return std::nullopt;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ModuleDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
std::error_code EC;
for (auto F = FS.dir_begin(RuntimeLibPath, EC);
!EC && F != llvm::vfs::directory_iterator(); F.increment(EC)) {
if (F->path().endswith(".yaml"))
if (F->path().ends_with(".yaml"))
CommonDependencyFiles.emplace_back(F->path().str());
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Basic/EditorPlaceholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using namespace swift;
std::optional<EditorPlaceholderData>
swift::parseEditorPlaceholder(llvm::StringRef PlaceholderText) {
if (!PlaceholderText.starts_with("<#") ||
!PlaceholderText.endswith("#>"))
!PlaceholderText.ends_with("#>"))
return std::nullopt;

PlaceholderText = PlaceholderText.drop_front(2).drop_back(2);
Expand Down
2 changes: 1 addition & 1 deletion lib/Basic/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ std::string swift::getSDKBuildVersion(StringRef Path) {
std::string swift::getSDKName(StringRef Path) {
std::string Name = getPlistEntry(llvm::Twine(Path)+"/SDKSettings.plist",
"CanonicalName");
if (Name.empty() && Path.endswith(".sdk")) {
if (Name.empty() && Path.ends_with(".sdk")) {
Name = llvm::sys::path::filename(Path).drop_back(strlen(".sdk")).str();
}
return Name;
Expand Down
2 changes: 1 addition & 1 deletion lib/Basic/PrettyStackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void PrettyStackTraceStringAction::print(llvm::raw_ostream &out) const {
void PrettyStackTraceFileContents::print(llvm::raw_ostream &out) const {
out << "Contents of " << Buffer.getBufferIdentifier() << ":\n---\n"
<< Buffer.getBuffer();
if (!Buffer.getBuffer().endswith("\n"))
if (!Buffer.getBuffer().ends_with("\n"))
out << '\n';
out << "---\n";
}
Expand Down
18 changes: 9 additions & 9 deletions lib/Basic/StringExtras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ PartOfSpeech swift::getPartOfSpeech(StringRef word) {
#include "PartsOfSpeech.def"

// Identify gerunds, which always end in "ing".
if (word.endswith("ing") && word.size() > 4) {
if (word.ends_with("ing") && word.size() > 4) {
StringRef possibleVerb = word.drop_back(3);

// If what remains is a verb, we have a gerund.
Expand Down Expand Up @@ -417,7 +417,7 @@ static std::optional<StringRef> skipTypeSuffix(StringRef typeName) {
}

// _t.
if (typeName.size() > 2 && typeName.endswith("_t")) {
if (typeName.size() > 2 && typeName.ends_with("_t")) {
return typeName.drop_back(2);
}
return std::nullopt;
Expand Down Expand Up @@ -555,7 +555,7 @@ static StringRef omitNeedlessWordsFromPrefix(StringRef name,
if (firstWord == "By") {
StringRef nextWord = camel_case::getFirstWord(
newName.substr(firstWord.size()));
if (nextWord.endswith("ing")) {
if (nextWord.ends_with("ing")) {
return newName.substr(firstWord.size());
}
}
Expand Down Expand Up @@ -1404,27 +1404,27 @@ bool swift::omitNeedlessWords(

std::optional<StringRef>
swift::stripWithCompletionHandlerSuffix(StringRef name) {
if (name.endswith("WithCompletionHandler")) {
if (name.ends_with("WithCompletionHandler")) {
return name.drop_back(strlen("WithCompletionHandler"));
}

if (name.endswith("WithCompletion")) {
if (name.ends_with("WithCompletion")) {
return name.drop_back(strlen("WithCompletion"));
}

if (name.endswith("WithCompletionBlock")) {
if (name.ends_with("WithCompletionBlock")) {
return name.drop_back(strlen("WithCompletionBlock"));
}

if (name.endswith("WithBlock")) {
if (name.ends_with("WithBlock")) {
return name.drop_back(strlen("WithBlock"));
}

if (name.endswith("WithReplyTo")) {
if (name.ends_with("WithReplyTo")) {
return name.drop_back(strlen("WithReplyTo"));
}

if (name.endswith("WithReply")) {
if (name.ends_with("WithReply")) {
return name.drop_back(strlen("WithReply"));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/CFTypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ StringRef importer::getCFTypeName(
if (auto pointee = CFPointeeInfo::classifyTypedef(decl)) {
auto name = decl->getName();
if (pointee.isRecord() || pointee.isTypedef())
if (name.endswith(SWIFT_CFTYPE_SUFFIX))
if (name.ends_with(SWIFT_CFTYPE_SUFFIX))
return name.drop_back(strlen(SWIFT_CFTYPE_SUFFIX));

return name;
Expand Down
4 changes: 2 additions & 2 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ static bool clangSupportsPragmaAttributeWithSwiftAttr() {

static inline bool isPCHFilenameExtension(StringRef path) {
return llvm::sys::path::extension(path)
.endswith(file_types::getExtension(file_types::TY_PCH));
.ends_with(file_types::getExtension(file_types::TY_PCH));
}

void importer::getNormalInvocationArguments(
Expand Down Expand Up @@ -7034,7 +7034,7 @@ bool ClangImporter::isUnsafeCXXMethod(const FuncDecl *func) {
if (!func->hasName())
return false;
auto id = func->getBaseName().userFacingName();
return id.starts_with("__") && id.endswith("Unsafe");
return id.starts_with("__") && id.ends_with("Unsafe");
}

bool ClangImporter::isAnnotatedWith(const clang::CXXMethodDecl *method,
Expand Down
10 changes: 5 additions & 5 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3392,8 +3392,8 @@ namespace {
sourceManager.getFileID(decl->getLocation()))) {
auto filename = file->getName();
if ((file->getDir() == owningModule->Directory) &&
(filename.endswith("cmath") || filename.endswith("math.h") ||
filename.endswith("stdlib.h") || filename.endswith("cstdlib"))) {
(filename.ends_with("cmath") || filename.ends_with("math.h") ||
filename.ends_with("stdlib.h") || filename.ends_with("cstdlib"))) {
return nullptr;
}
}
Expand Down Expand Up @@ -8433,9 +8433,9 @@ void ClangImporter::Implementation::importAttributes(
// such as CGColorRelease(CGColorRef).
if (auto FD = dyn_cast<clang::FunctionDecl>(ClangDecl)) {
if (FD->getNumParams() == 1 && FD->getDeclName().isIdentifier() &&
(FD->getName().endswith("Release") ||
FD->getName().endswith("Retain") ||
FD->getName().endswith("Autorelease")) &&
(FD->getName().ends_with("Release") ||
FD->getName().ends_with("Retain") ||
FD->getName().ends_with("Autorelease")) &&
!FD->getAttr<clang::SwiftNameAttr>()) {
if (auto t = FD->getParamDecl(0)->getType()->getAs<clang::TypedefType>()){
if (isCFTypeDecl(t->getDecl())) {
Expand Down
6 changes: 3 additions & 3 deletions lib/ClangImporter/ImportEnumInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ StringRef importer::getCommonPluralPrefix(StringRef singular,

// Is the plural string just "[singular]s"?
plural = plural.drop_back();
if (plural.endswith(firstLeftoverWord))
if (plural.ends_with(firstLeftoverWord))
return commonPrefixPlusWord;

if (plural.empty() || plural.back() != 'e')
return commonPrefix;

// Is the plural string "[singular]es"?
plural = plural.drop_back();
if (plural.endswith(firstLeftoverWord))
if (plural.ends_with(firstLeftoverWord))
return commonPrefixPlusWord;

if (plural.empty() || !(plural.back() == 'i' && singular.back() == 'y'))
Expand All @@ -236,7 +236,7 @@ StringRef importer::getCommonPluralPrefix(StringRef singular,
// Is the plural string "[prefix]ies" and the singular "[prefix]y"?
plural = plural.drop_back();
firstLeftoverWord = firstLeftoverWord.drop_back();
if (plural.endswith(firstLeftoverWord))
if (plural.ends_with(firstLeftoverWord))
return commonPrefixPlusWord;

return commonPrefix;
Expand Down
8 changes: 4 additions & 4 deletions lib/ClangImporter/ImportName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ static StringRef stripLeadingK(StringRef name) {
StringRef importer::stripNotification(StringRef name) {
name = stripLeadingK(name);
StringRef notification = "Notification";
if (name.size() <= notification.size() || !name.endswith(notification))
if (name.size() <= notification.size() || !name.ends_with(notification))
return {};
return name.drop_back(notification.size());
}
Expand Down Expand Up @@ -1160,9 +1160,9 @@ NameImporter::considerErrorImport(const clang::ObjCMethodDecl *clangDecl,
StringRef suffixToStrip;
StringRef origBaseName = baseName;
if (adjustName && index == 0 && paramNames[0].empty()) {
if (baseName.endswith(ErrorSuffix))
if (baseName.ends_with(ErrorSuffix))
suffixToStrip = ErrorSuffix;
else if (baseName.endswith(AltErrorSuffix))
else if (baseName.ends_with(AltErrorSuffix))
suffixToStrip = AltErrorSuffix;

if (!suffixToStrip.empty()) {
Expand Down Expand Up @@ -1438,7 +1438,7 @@ bool NameImporter::hasErrorMethodNameCollision(
auto &ctx = method->getASTContext();
if (paramIndex == 0 && !suffixToStrip.empty()) {
StringRef name = chunks[0]->getName();
assert(name.endswith(suffixToStrip));
assert(name.ends_with(suffixToStrip));
name = name.drop_back(suffixToStrip.size());
chunks[0] = &ctx.Idents.get(name);
} else if (paramIndex != 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImporterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
void setSinglePCHImport(std::optional<std::string> PCHFilename) {
if (PCHFilename.has_value()) {
assert(llvm::sys::path::extension(PCHFilename.value())
.endswith(file_types::getExtension(file_types::TY_PCH)) &&
.ends_with(file_types::getExtension(file_types::TY_PCH)) &&
"Single PCH imported filename doesn't have .pch extension!");
}
SinglePCHImport = PCHFilename;
Expand Down
28 changes: 14 additions & 14 deletions lib/Demangling/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ static llvm::StringRef stripSuffix(llvm::StringRef Name) {

// Removes a 'TQ<index>' or 'TY<index>' from \p Name.
static llvm::StringRef stripAsyncContinuation(llvm::StringRef Name) {
if (!Name.endswith("_"))
if (!Name.ends_with("_"))
return Name;

StringRef Stripped = Name.drop_back();
while (!Stripped.empty() && swift::Mangle::isDigit(Stripped.back()))
Stripped = Stripped.drop_back();

if (Stripped.endswith("TQ") || Stripped.endswith("TY"))
if (Stripped.ends_with("TQ") || Stripped.ends_with("TY"))
return Stripped.drop_back(2);

return Name;
Expand All @@ -113,14 +113,14 @@ bool Context::isThunkSymbol(llvm::StringRef MangledName) {
if (isMangledName(MangledName)) {
MangledName = stripAsyncContinuation(stripSuffix(MangledName));
// First do a quick check
if (MangledName.endswith("TA") || // partial application forwarder
MangledName.endswith("Ta") || // ObjC partial application forwarder
MangledName.endswith("To") || // swift-as-ObjC thunk
MangledName.endswith("TO") || // ObjC-as-swift thunk
MangledName.endswith("TR") || // reabstraction thunk helper function
MangledName.endswith("Tr") || // reabstraction thunk
MangledName.endswith("TW") || // protocol witness thunk
MangledName.endswith("fC")) { // allocating constructor
if (MangledName.ends_with("TA") || // partial application forwarder
MangledName.ends_with("Ta") || // ObjC partial application forwarder
MangledName.ends_with("To") || // swift-as-ObjC thunk
MangledName.ends_with("TO") || // ObjC-as-swift thunk
MangledName.ends_with("TR") || // reabstraction thunk helper function
MangledName.ends_with("Tr") || // reabstraction thunk
MangledName.ends_with("TW") || // protocol witness thunk
MangledName.ends_with("fC")) { // allocating constructor

// To avoid false positives, we need to fully demangle the symbol.
NodePointer Nd = D->demangleSymbol(MangledName);
Expand Down Expand Up @@ -171,12 +171,12 @@ std::string Context::getThunkTarget(llvm::StringRef MangledName) {
MangledName = stripAsyncContinuation(MangledName);

// The targets of those thunks not derivable from the mangling.
if (MangledName.endswith("TR") ||
MangledName.endswith("Tr") ||
MangledName.endswith("TW") )
if (MangledName.ends_with("TR") ||
MangledName.ends_with("Tr") ||
MangledName.ends_with("TW") )
return std::string();

if (MangledName.endswith("fC")) {
if (MangledName.ends_with("fC")) {
std::string target = MangledName.str();
target[target.size() - 1] = 'c';
return target;
Expand Down
4 changes: 2 additions & 2 deletions lib/Driver/DarwinToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static void addLinkRuntimeLibRPath(const ArgList &Args,
// so we should make sure we add the rpaths last, after all user-specified
// rpaths. This is currently true from this place, but we need to be
// careful if this function is ever called before user's rpaths are emitted.
assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library");
assert(DarwinLibName.ends_with(".dylib") && "must be a dynamic library");

// Add @executable_path to rpath to support having the dylib copied with
// the executable.
Expand Down Expand Up @@ -727,7 +727,7 @@ void toolchains::Darwin::addPlatformSpecificPluginFrontendArgs(
llvm::sys::path::remove_filename(platformPath); // Developer

StringRef platformName = llvm::sys::path::filename(platformPath);
if (platformName.endswith("Simulator.platform")){
if (platformName.ends_with("Simulator.platform")){
StringRef devicePlatformName =
platformName.drop_back(strlen("Simulator.platform"));
llvm::sys::path::remove_filename(platformPath); // Platform
Expand Down
4 changes: 2 additions & 2 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static void validateSearchPathArgs(DiagnosticEngine &diags,
const ArgList &args) {
for (const Arg *A : args.filtered(options::OPT_F, options::OPT_Fsystem)) {
StringRef name = A->getValue();
if (name.endswith(".framework") || name.endswith(".framework/"))
if (name.ends_with(".framework") || name.ends_with(".framework/"))
diags.diagnose(SourceLoc(),
diag::framework_search_path_includes_framework_extension,
name);
Expand Down Expand Up @@ -1830,7 +1830,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
if (auto *IA = dyn_cast<InputAction>(A)) {
StringRef ObjectName = IA->getInputArg().getValue();
if (Triple.getObjectFormat() == llvm::Triple::ELF &&
ObjectName.endswith(".so"))
ObjectName.ends_with(".so"))
continue;
}
AutolinkExtractInputs.push_back(A);
Expand Down
2 changes: 1 addition & 1 deletion lib/DriverTool/swift_api_digester_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class RemovedAddedNodeMatcher : public NodeMatcher, public MatchedNodeListener {
if (((StringRef)LL).starts_with((llvm::Twine("ns") + RR).str()) ||
((StringRef)RR).starts_with((llvm::Twine("ns") + LL).str()))
return true;
if (((StringRef)LL).endswith(RR) || ((StringRef)RR).endswith(LL))
if (((StringRef)LL).ends_with(RR) || ((StringRef)RR).ends_with(LL))
return true;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/DriverTool/swift_cache_tool_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class SwiftCacheToolInvocation {
}
// drop swift-frontend executable path and leading `-frontend` from
// command-line.
if (StringRef(FrontendArgs[0]).endswith("swift-frontend"))
if (StringRef(FrontendArgs[0]).ends_with("swift-frontend"))
FrontendArgs.erase(FrontendArgs.begin());
if (StringRef(FrontendArgs[0]).equals("-frontend"))
FrontendArgs.erase(FrontendArgs.begin());
Expand Down
2 changes: 1 addition & 1 deletion lib/DriverTool/swift_parse_test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static void _loadSwiftFilesRecursively(
I != E; I.increment(err)) {
_loadSwiftFilesRecursively(I->path(), buffers);
}
} else if (path.endswith(".swift")) {
} else if (path.ends_with(".swift")) {
if (auto buffer = llvm::MemoryBuffer::getFile(path)) {
buffers.push_back(std::move(*buffer));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ getVersionedPrebuiltModulePath(std::optional<llvm::VersionTuple> sdkVer,
llvm::sys::path::append(pathWithSDKVer, vs);
if (llvm::sys::fs::exists(pathWithSDKVer)) {
return pathWithSDKVer.str().str();
} else if (vs.endswith(".0")) {
} else if (vs.ends_with(".0")) {
vs = vs.substr(0, vs.size() - 2);
} else {
return defaultPrebuiltPath.str();
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ SourceFile *CompilerInstance::getIDEInspectionFile() const {

static inline bool isPCHFilenameExtension(StringRef path) {
return llvm::sys::path::extension(path)
.endswith(file_types::getExtension(file_types::TY_PCH));
.ends_with(file_types::getExtension(file_types::TY_PCH));
}

std::string CompilerInstance::getBridgingHeaderPath() const {
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/FrontendInputsAndOutputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ unsigned FrontendInputsAndOutputs::numberOfPrimaryInputsEndingWith(
StringRef extension) const {
unsigned n = 0;
(void)forEachPrimaryInput([&](const InputFile &input) -> bool {
if (llvm::sys::path::extension(input.getFileName()).endswith(extension))
if (llvm::sys::path::extension(input.getFileName()).ends_with(extension))
++n;
return false;
});
Expand Down
Loading