Skip to content

Commit 293a434

Browse files
authored
Merge pull request #72744 from bnbarham/rename-endswith
Rename `StringRef::endswith` references to `StringRef::ends_with`
2 parents e6a2021 + 1fdda02 commit 293a434

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+99
-99
lines changed

include/swift/AST/FineGrainedDependencies.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ template <typename GraphT> class DotFileEmitter {
989989
includeExternals || n->getKey().getKind() != NodeKind::externalDepend;
990990
bool apiPredicate =
991991
includeAPINotes ||
992-
!StringRef(n->getKey().humanReadableName()).endswith(".apinotes");
992+
!StringRef(n->getKey().humanReadableName()).ends_with(".apinotes");
993993
return externalPredicate && apiPredicate;
994994
}
995995
bool includeGraphArc(const NodeT *def, const NodeT *use) const {

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11765,7 +11765,7 @@ bool MacroDecl::isUniqueMacroName(StringRef name) {
1176511765
name = name.drop_back();
1176611766

1176711767
// Check for fMu.
11768-
return name.endswith("fMu");
11768+
return name.ends_with("fMu");
1176911769
}
1177011770

1177111771
bool MacroDecl::isUniqueMacroName(DeclBaseName name) {

lib/AST/FineGrainedDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ std::optional<SourceFileDepGraph>
4646
SourceFileDepGraph::loadFromPath(StringRef path, const bool allowSwiftModule) {
4747
const bool treatAsModule =
4848
allowSwiftModule &&
49-
path.endswith(file_types::getExtension(file_types::TY_SwiftModuleFile));
49+
path.ends_with(file_types::getExtension(file_types::TY_SwiftModuleFile));
5050
auto bufferOrError = llvm::MemoryBuffer::getFile(path);
5151
if (!bufferOrError)
5252
return std::nullopt;

lib/AST/ModuleDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
535535
std::error_code EC;
536536
for (auto F = FS.dir_begin(RuntimeLibPath, EC);
537537
!EC && F != llvm::vfs::directory_iterator(); F.increment(EC)) {
538-
if (F->path().endswith(".yaml"))
538+
if (F->path().ends_with(".yaml"))
539539
CommonDependencyFiles.emplace_back(F->path().str());
540540
}
541541
}

lib/Basic/EditorPlaceholder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ using namespace swift;
3939
std::optional<EditorPlaceholderData>
4040
swift::parseEditorPlaceholder(llvm::StringRef PlaceholderText) {
4141
if (!PlaceholderText.starts_with("<#") ||
42-
!PlaceholderText.endswith("#>"))
42+
!PlaceholderText.ends_with("#>"))
4343
return std::nullopt;
4444

4545
PlaceholderText = PlaceholderText.drop_front(2).drop_back(2);

lib/Basic/Platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ std::string swift::getSDKBuildVersion(StringRef Path) {
580580
std::string swift::getSDKName(StringRef Path) {
581581
std::string Name = getPlistEntry(llvm::Twine(Path)+"/SDKSettings.plist",
582582
"CanonicalName");
583-
if (Name.empty() && Path.endswith(".sdk")) {
583+
if (Name.empty() && Path.ends_with(".sdk")) {
584584
Name = llvm::sys::path::filename(Path).drop_back(strlen(".sdk")).str();
585585
}
586586
return Name;

lib/Basic/PrettyStackTrace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void PrettyStackTraceStringAction::print(llvm::raw_ostream &out) const {
3030
void PrettyStackTraceFileContents::print(llvm::raw_ostream &out) const {
3131
out << "Contents of " << Buffer.getBufferIdentifier() << ":\n---\n"
3232
<< Buffer.getBuffer();
33-
if (!Buffer.getBuffer().endswith("\n"))
33+
if (!Buffer.getBuffer().ends_with("\n"))
3434
out << '\n';
3535
out << "---\n";
3636
}

lib/Basic/StringExtras.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ PartOfSpeech swift::getPartOfSpeech(StringRef word) {
6969
#include "PartsOfSpeech.def"
7070

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

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

419419
// _t.
420-
if (typeName.size() > 2 && typeName.endswith("_t")) {
420+
if (typeName.size() > 2 && typeName.ends_with("_t")) {
421421
return typeName.drop_back(2);
422422
}
423423
return std::nullopt;
@@ -555,7 +555,7 @@ static StringRef omitNeedlessWordsFromPrefix(StringRef name,
555555
if (firstWord == "By") {
556556
StringRef nextWord = camel_case::getFirstWord(
557557
newName.substr(firstWord.size()));
558-
if (nextWord.endswith("ing")) {
558+
if (nextWord.ends_with("ing")) {
559559
return newName.substr(firstWord.size());
560560
}
561561
}
@@ -1404,27 +1404,27 @@ bool swift::omitNeedlessWords(
14041404

14051405
std::optional<StringRef>
14061406
swift::stripWithCompletionHandlerSuffix(StringRef name) {
1407-
if (name.endswith("WithCompletionHandler")) {
1407+
if (name.ends_with("WithCompletionHandler")) {
14081408
return name.drop_back(strlen("WithCompletionHandler"));
14091409
}
14101410

1411-
if (name.endswith("WithCompletion")) {
1411+
if (name.ends_with("WithCompletion")) {
14121412
return name.drop_back(strlen("WithCompletion"));
14131413
}
14141414

1415-
if (name.endswith("WithCompletionBlock")) {
1415+
if (name.ends_with("WithCompletionBlock")) {
14161416
return name.drop_back(strlen("WithCompletionBlock"));
14171417
}
14181418

1419-
if (name.endswith("WithBlock")) {
1419+
if (name.ends_with("WithBlock")) {
14201420
return name.drop_back(strlen("WithBlock"));
14211421
}
14221422

1423-
if (name.endswith("WithReplyTo")) {
1423+
if (name.ends_with("WithReplyTo")) {
14241424
return name.drop_back(strlen("WithReplyTo"));
14251425
}
14261426

1427-
if (name.endswith("WithReply")) {
1427+
if (name.ends_with("WithReply")) {
14281428
return name.drop_back(strlen("WithReply"));
14291429
}
14301430

lib/ClangImporter/CFTypeInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ StringRef importer::getCFTypeName(
102102
if (auto pointee = CFPointeeInfo::classifyTypedef(decl)) {
103103
auto name = decl->getName();
104104
if (pointee.isRecord() || pointee.isTypedef())
105-
if (name.endswith(SWIFT_CFTYPE_SUFFIX))
105+
if (name.ends_with(SWIFT_CFTYPE_SUFFIX))
106106
return name.drop_back(strlen(SWIFT_CFTYPE_SUFFIX));
107107

108108
return name;

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ static bool clangSupportsPragmaAttributeWithSwiftAttr() {
458458

459459
static inline bool isPCHFilenameExtension(StringRef path) {
460460
return llvm::sys::path::extension(path)
461-
.endswith(file_types::getExtension(file_types::TY_PCH));
461+
.ends_with(file_types::getExtension(file_types::TY_PCH));
462462
}
463463

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

70407040
bool ClangImporter::isAnnotatedWith(const clang::CXXMethodDecl *method,

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,8 +3392,8 @@ namespace {
33923392
sourceManager.getFileID(decl->getLocation()))) {
33933393
auto filename = file->getName();
33943394
if ((file->getDir() == owningModule->Directory) &&
3395-
(filename.endswith("cmath") || filename.endswith("math.h") ||
3396-
filename.endswith("stdlib.h") || filename.endswith("cstdlib"))) {
3395+
(filename.ends_with("cmath") || filename.ends_with("math.h") ||
3396+
filename.ends_with("stdlib.h") || filename.ends_with("cstdlib"))) {
33973397
return nullptr;
33983398
}
33993399
}
@@ -8433,9 +8433,9 @@ void ClangImporter::Implementation::importAttributes(
84338433
// such as CGColorRelease(CGColorRef).
84348434
if (auto FD = dyn_cast<clang::FunctionDecl>(ClangDecl)) {
84358435
if (FD->getNumParams() == 1 && FD->getDeclName().isIdentifier() &&
8436-
(FD->getName().endswith("Release") ||
8437-
FD->getName().endswith("Retain") ||
8438-
FD->getName().endswith("Autorelease")) &&
8436+
(FD->getName().ends_with("Release") ||
8437+
FD->getName().ends_with("Retain") ||
8438+
FD->getName().ends_with("Autorelease")) &&
84398439
!FD->getAttr<clang::SwiftNameAttr>()) {
84408440
if (auto t = FD->getParamDecl(0)->getType()->getAs<clang::TypedefType>()){
84418441
if (isCFTypeDecl(t->getDecl())) {

lib/ClangImporter/ImportEnumInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ StringRef importer::getCommonPluralPrefix(StringRef singular,
219219

220220
// Is the plural string just "[singular]s"?
221221
plural = plural.drop_back();
222-
if (plural.endswith(firstLeftoverWord))
222+
if (plural.ends_with(firstLeftoverWord))
223223
return commonPrefixPlusWord;
224224

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

228228
// Is the plural string "[singular]es"?
229229
plural = plural.drop_back();
230-
if (plural.endswith(firstLeftoverWord))
230+
if (plural.ends_with(firstLeftoverWord))
231231
return commonPrefixPlusWord;
232232

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

242242
return commonPrefix;

lib/ClangImporter/ImportName.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ static StringRef stripLeadingK(StringRef name) {
464464
StringRef importer::stripNotification(StringRef name) {
465465
name = stripLeadingK(name);
466466
StringRef notification = "Notification";
467-
if (name.size() <= notification.size() || !name.endswith(notification))
467+
if (name.size() <= notification.size() || !name.ends_with(notification))
468468
return {};
469469
return name.drop_back(notification.size());
470470
}
@@ -1160,9 +1160,9 @@ NameImporter::considerErrorImport(const clang::ObjCMethodDecl *clangDecl,
11601160
StringRef suffixToStrip;
11611161
StringRef origBaseName = baseName;
11621162
if (adjustName && index == 0 && paramNames[0].empty()) {
1163-
if (baseName.endswith(ErrorSuffix))
1163+
if (baseName.ends_with(ErrorSuffix))
11641164
suffixToStrip = ErrorSuffix;
1165-
else if (baseName.endswith(AltErrorSuffix))
1165+
else if (baseName.ends_with(AltErrorSuffix))
11661166
suffixToStrip = AltErrorSuffix;
11671167

11681168
if (!suffixToStrip.empty()) {
@@ -1438,7 +1438,7 @@ bool NameImporter::hasErrorMethodNameCollision(
14381438
auto &ctx = method->getASTContext();
14391439
if (paramIndex == 0 && !suffixToStrip.empty()) {
14401440
StringRef name = chunks[0]->getName();
1441-
assert(name.endswith(suffixToStrip));
1441+
assert(name.ends_with(suffixToStrip));
14421442
name = name.drop_back(suffixToStrip.size());
14431443
chunks[0] = &ctx.Idents.get(name);
14441444
} else if (paramIndex != 0) {

lib/ClangImporter/ImporterImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
18211821
void setSinglePCHImport(std::optional<std::string> PCHFilename) {
18221822
if (PCHFilename.has_value()) {
18231823
assert(llvm::sys::path::extension(PCHFilename.value())
1824-
.endswith(file_types::getExtension(file_types::TY_PCH)) &&
1824+
.ends_with(file_types::getExtension(file_types::TY_PCH)) &&
18251825
"Single PCH imported filename doesn't have .pch extension!");
18261826
}
18271827
SinglePCHImport = PCHFilename;

lib/Demangling/Context.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ static llvm::StringRef stripSuffix(llvm::StringRef Name) {
9696

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

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

106-
if (Stripped.endswith("TQ") || Stripped.endswith("TY"))
106+
if (Stripped.ends_with("TQ") || Stripped.ends_with("TY"))
107107
return Stripped.drop_back(2);
108108

109109
return Name;
@@ -113,14 +113,14 @@ bool Context::isThunkSymbol(llvm::StringRef MangledName) {
113113
if (isMangledName(MangledName)) {
114114
MangledName = stripAsyncContinuation(stripSuffix(MangledName));
115115
// First do a quick check
116-
if (MangledName.endswith("TA") || // partial application forwarder
117-
MangledName.endswith("Ta") || // ObjC partial application forwarder
118-
MangledName.endswith("To") || // swift-as-ObjC thunk
119-
MangledName.endswith("TO") || // ObjC-as-swift thunk
120-
MangledName.endswith("TR") || // reabstraction thunk helper function
121-
MangledName.endswith("Tr") || // reabstraction thunk
122-
MangledName.endswith("TW") || // protocol witness thunk
123-
MangledName.endswith("fC")) { // allocating constructor
116+
if (MangledName.ends_with("TA") || // partial application forwarder
117+
MangledName.ends_with("Ta") || // ObjC partial application forwarder
118+
MangledName.ends_with("To") || // swift-as-ObjC thunk
119+
MangledName.ends_with("TO") || // ObjC-as-swift thunk
120+
MangledName.ends_with("TR") || // reabstraction thunk helper function
121+
MangledName.ends_with("Tr") || // reabstraction thunk
122+
MangledName.ends_with("TW") || // protocol witness thunk
123+
MangledName.ends_with("fC")) { // allocating constructor
124124

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

173173
// The targets of those thunks not derivable from the mangling.
174-
if (MangledName.endswith("TR") ||
175-
MangledName.endswith("Tr") ||
176-
MangledName.endswith("TW") )
174+
if (MangledName.ends_with("TR") ||
175+
MangledName.ends_with("Tr") ||
176+
MangledName.ends_with("TW") )
177177
return std::string();
178178

179-
if (MangledName.endswith("fC")) {
179+
if (MangledName.ends_with("fC")) {
180180
std::string target = MangledName.str();
181181
target[target.size() - 1] = 'c';
182182
return target;

lib/Driver/DarwinToolChains.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static void addLinkRuntimeLibRPath(const ArgList &Args,
157157
// so we should make sure we add the rpaths last, after all user-specified
158158
// rpaths. This is currently true from this place, but we need to be
159159
// careful if this function is ever called before user's rpaths are emitted.
160-
assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library");
160+
assert(DarwinLibName.ends_with(".dylib") && "must be a dynamic library");
161161

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

729729
StringRef platformName = llvm::sys::path::filename(platformPath);
730-
if (platformName.endswith("Simulator.platform")){
730+
if (platformName.ends_with("Simulator.platform")){
731731
StringRef devicePlatformName =
732732
platformName.drop_back(strlen("Simulator.platform"));
733733
llvm::sys::path::remove_filename(platformPath); // Platform

lib/Driver/Driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static void validateSearchPathArgs(DiagnosticEngine &diags,
274274
const ArgList &args) {
275275
for (const Arg *A : args.filtered(options::OPT_F, options::OPT_Fsystem)) {
276276
StringRef name = A->getValue();
277-
if (name.endswith(".framework") || name.endswith(".framework/"))
277+
if (name.ends_with(".framework") || name.ends_with(".framework/"))
278278
diags.diagnose(SourceLoc(),
279279
diag::framework_search_path_includes_framework_extension,
280280
name);
@@ -1830,7 +1830,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
18301830
if (auto *IA = dyn_cast<InputAction>(A)) {
18311831
StringRef ObjectName = IA->getInputArg().getValue();
18321832
if (Triple.getObjectFormat() == llvm::Triple::ELF &&
1833-
ObjectName.endswith(".so"))
1833+
ObjectName.ends_with(".so"))
18341834
continue;
18351835
}
18361836
AutolinkExtractInputs.push_back(A);

lib/DriverTool/swift_api_digester_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class RemovedAddedNodeMatcher : public NodeMatcher, public MatchedNodeListener {
294294
if (((StringRef)LL).starts_with((llvm::Twine("ns") + RR).str()) ||
295295
((StringRef)RR).starts_with((llvm::Twine("ns") + LL).str()))
296296
return true;
297-
if (((StringRef)LL).endswith(RR) || ((StringRef)RR).endswith(LL))
297+
if (((StringRef)LL).ends_with(RR) || ((StringRef)RR).ends_with(LL))
298298
return true;
299299
return false;
300300
}

lib/DriverTool/swift_cache_tool_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class SwiftCacheToolInvocation {
187187
}
188188
// drop swift-frontend executable path and leading `-frontend` from
189189
// command-line.
190-
if (StringRef(FrontendArgs[0]).endswith("swift-frontend"))
190+
if (StringRef(FrontendArgs[0]).ends_with("swift-frontend"))
191191
FrontendArgs.erase(FrontendArgs.begin());
192192
if (StringRef(FrontendArgs[0]).equals("-frontend"))
193193
FrontendArgs.erase(FrontendArgs.begin());

lib/DriverTool/swift_parse_test_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static void _loadSwiftFilesRecursively(
200200
I != E; I.increment(err)) {
201201
_loadSwiftFilesRecursively(I->path(), buffers);
202202
}
203-
} else if (path.endswith(".swift")) {
203+
} else if (path.ends_with(".swift")) {
204204
if (auto buffer = llvm::MemoryBuffer::getFile(path)) {
205205
buffers.push_back(std::move(*buffer));
206206
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ getVersionedPrebuiltModulePath(std::optional<llvm::VersionTuple> sdkVer,
115115
llvm::sys::path::append(pathWithSDKVer, vs);
116116
if (llvm::sys::fs::exists(pathWithSDKVer)) {
117117
return pathWithSDKVer.str().str();
118-
} else if (vs.endswith(".0")) {
118+
} else if (vs.ends_with(".0")) {
119119
vs = vs.substr(0, vs.size() - 2);
120120
} else {
121121
return defaultPrebuiltPath.str();

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ SourceFile *CompilerInstance::getIDEInspectionFile() const {
867867

868868
static inline bool isPCHFilenameExtension(StringRef path) {
869869
return llvm::sys::path::extension(path)
870-
.endswith(file_types::getExtension(file_types::TY_PCH));
870+
.ends_with(file_types::getExtension(file_types::TY_PCH));
871871
}
872872

873873
std::string CompilerInstance::getBridgingHeaderPath() const {

lib/Frontend/FrontendInputsAndOutputs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ unsigned FrontendInputsAndOutputs::numberOfPrimaryInputsEndingWith(
171171
StringRef extension) const {
172172
unsigned n = 0;
173173
(void)forEachPrimaryInput([&](const InputFile &input) -> bool {
174-
if (llvm::sys::path::extension(input.getFileName()).endswith(extension))
174+
if (llvm::sys::path::extension(input.getFileName()).ends_with(extension))
175175
++n;
176176
return false;
177177
});

0 commit comments

Comments
 (0)