Skip to content

Commit cc4ecfd

Browse files
[ADT] Rename SmallString::{starts,ends}with to {starts,ends}_with (llvm#74916)
This patch renames {starts,ends}with to {starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. Since there are only a handful of occurrences, this patch skips the deprecation phase and simply renames them.
1 parent 5c8755f commit cc4ecfd

File tree

21 files changed

+33
-37
lines changed

21 files changed

+33
-37
lines changed

clang-tools-extra/clang-doc/Mapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ llvm::SmallString<128> MapASTVisitor::getFile(const NamedDecl *D,
103103
.getPresumedLoc(D->getBeginLoc())
104104
.getFilename());
105105
IsFileInRootDir = false;
106-
if (RootDir.empty() || !File.startswith(RootDir))
106+
if (RootDir.empty() || !File.starts_with(RootDir))
107107
return File;
108108
IsFileInRootDir = true;
109109
llvm::SmallString<128> Prefix(RootDir);

clang-tools-extra/modularize/ModuleAssistant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static bool addModuleDescription(Module *RootModule,
175175
llvm::SmallString<256> NativePath, NativePrefix;
176176
llvm::sys::path::native(HeaderFilePath, NativePath);
177177
llvm::sys::path::native(HeaderPrefix, NativePrefix);
178-
if (NativePath.startswith(NativePrefix))
178+
if (NativePath.starts_with(NativePrefix))
179179
FilePath = std::string(NativePath.substr(NativePrefix.size() + 1));
180180
else
181181
FilePath = std::string(HeaderFilePath);

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,14 +3809,14 @@ void MicrosoftMangleContextImpl::mangleCXXRTTICompleteObjectLocator(
38093809
llvm::raw_svector_ostream Stream(VFTableMangling);
38103810
mangleCXXVFTable(Derived, BasePath, Stream);
38113811

3812-
if (VFTableMangling.startswith("??@")) {
3813-
assert(VFTableMangling.endswith("@"));
3812+
if (VFTableMangling.starts_with("??@")) {
3813+
assert(VFTableMangling.ends_with("@"));
38143814
Out << VFTableMangling << "??_R4@";
38153815
return;
38163816
}
38173817

3818-
assert(VFTableMangling.startswith("??_7") ||
3819-
VFTableMangling.startswith("??_S"));
3818+
assert(VFTableMangling.starts_with("??_7") ||
3819+
VFTableMangling.starts_with("??_S"));
38203820

38213821
Out << "??_R4" << VFTableMangling.str().drop_front(4);
38223822
}

clang/lib/Basic/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature) {
8989
// where both are valid examples of the same platform+environment but in the
9090
// variant (2) the simulator is hardcoded as part of the platform name. Both
9191
// forms above should match for "iossimulator" requirement.
92-
if (Target.getTriple().isOSDarwin() && PlatformEnv.endswith("simulator"))
92+
if (Target.getTriple().isOSDarwin() && PlatformEnv.ends_with("simulator"))
9393
return PlatformEnv == Feature || CmpPlatformEnv(PlatformEnv, Feature);
9494

9595
return PlatformEnv == Feature;

clang/lib/CrossTU/CrossTranslationUnit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ CrossTranslationUnitContext::ASTLoader::load(StringRef Identifier) {
551551
// Normalize by removing relative path components.
552552
llvm::sys::path::remove_dots(Path, /*remove_dot_dot*/ true, PathStyle);
553553

554-
if (Path.endswith(".ast"))
554+
if (Path.ends_with(".ast"))
555555
return loadFromDump(Path);
556556
else
557557
return loadFromSource(Path);

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ bool Driver::getCrashDiagnosticFile(StringRef ReproCrashFilename,
15221522
// (or /Library/Logs/DiagnosticReports for root) and has the filename pattern
15231523
// clang-<VERSION>_<YYYY-MM-DD-HHMMSS>_<hostname>.crash.
15241524
path::home_directory(CrashDiagDir);
1525-
if (CrashDiagDir.startswith("/var/root"))
1525+
if (CrashDiagDir.starts_with("/var/root"))
15261526
CrashDiagDir = "/";
15271527
path::append(CrashDiagDir, "Library/Logs/DiagnosticReports");
15281528
int PID =

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
12811281
// rpaths. This is currently true from this place, but we need to be
12821282
// careful if this function is ever called before user's rpaths are emitted.
12831283
if (Opts & RLO_AddRPath) {
1284-
assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library");
1284+
assert(DarwinLibName.ends_with(".dylib") && "must be a dynamic library");
12851285

12861286
// Add @executable_path to rpath to support having the dylib copied with
12871287
// the executable.

clang/lib/Lex/ModuleMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ void ModuleMapParser::diagnosePrivateModules(SourceLocation ExplicitLoc,
18641864
continue;
18651865

18661866
SmallString<128> FullName(ActiveModule->getFullModuleName());
1867-
if (!FullName.startswith(M->Name) && !FullName.endswith("Private"))
1867+
if (!FullName.starts_with(M->Name) && !FullName.ends_with("Private"))
18681868
continue;
18691869
SmallString<128> FixedPrivModDecl;
18701870
SmallString<128> Canonical(M->Name);

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10112,7 +10112,7 @@ void Sema::CodeCompleteIncludedFile(llvm::StringRef Dir, bool Angled) {
1011210112
const StringRef &Dirname = llvm::sys::path::filename(Dir);
1011310113
const bool isQt = Dirname.startswith("Qt") || Dirname == "ActiveQt";
1011410114
const bool ExtensionlessHeaders =
10115-
IsSystem || isQt || Dir.endswith(".framework/Headers");
10115+
IsSystem || isQt || Dir.ends_with(".framework/Headers");
1011610116
std::error_code EC;
1011710117
unsigned Count = 0;
1011810118
for (auto It = FS.dir_begin(Dir, EC);

lld/COFF/PDB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void PDBLinker::pdbMakeAbsolute(SmallVectorImpl<char> &fileName) {
268268
// decide that it's a unix path if we're fairly certain. Specifically, if
269269
// it starts with a forward slash.
270270
SmallString<128> absoluteFileName = ctx.config.pdbSourcePath;
271-
sys::path::Style guessedStyle = absoluteFileName.startswith("/")
271+
sys::path::Style guessedStyle = absoluteFileName.starts_with("/")
272272
? sys::path::Style::posix
273273
: sys::path::Style::windows;
274274
sys::path::append(absoluteFileName, guessedStyle, fileName);

0 commit comments

Comments
 (0)