diff options
author | Kazu Hirata <kazu@google.com> | 2023-12-09 14:28:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-09 14:28:45 -0800 |
commit | cc4ecfd68b79a44f101fe9924d088a83477797c0 (patch) | |
tree | 4d63911ccc3d757fc04a6706d6726e6ae765bd60 /llvm | |
parent | 5c8755f9f40e5b5f4e26a9a0fdb4993cb8a57202 (diff) | |
download | llvm-cc4ecfd68b79a44f101fe9924d088a83477797c0.zip llvm-cc4ecfd68b79a44f101fe9924d088a83477797c0.tar.gz llvm-cc4ecfd68b79a44f101fe9924d088a83477797c0.tar.bz2 |
[ADT] Rename SmallString::{starts,ends}with to {starts,ends}_with (#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.
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/ADT/SmallString.h | 12 | ||||
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/Path.inc | 4 | ||||
-rw-r--r-- | llvm/tools/dsymutil/DebugMap.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageReport.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-ml/llvm-ml.cpp | 2 | ||||
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 12 |
9 files changed, 18 insertions, 22 deletions
diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h index 0052c86..02fa28f 100644 --- a/llvm/include/llvm/ADT/SmallString.h +++ b/llvm/include/llvm/ADT/SmallString.h @@ -120,15 +120,11 @@ public: /// @name String Predicates /// @{ - /// startswith - Check if this string starts with the given \p Prefix. - bool startswith(StringRef Prefix) const { - return str().startswith(Prefix); - } + /// starts_with - Check if this string starts with the given \p Prefix. + bool starts_with(StringRef Prefix) const { return str().starts_with(Prefix); } - /// endswith - Check if this string ends with the given \p Suffix. - bool endswith(StringRef Suffix) const { - return str().endswith(Suffix); - } + /// ends_with - Check if this string ends with the given \p Suffix. + bool ends_with(StringRef Suffix) const { return str().ends_with(Suffix); } /// @} /// @name String Searching diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 16cc83b..9827bd3 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1048,7 +1048,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock( } else { Name += FunctionSectionName; if (TM.getUniqueBasicBlockSectionNames()) { - if (!Name.endswith(".")) + if (!Name.ends_with(".")) Name += "."; Name += MBB.getSymbol()->getName(); } else { diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index e4563fd..168a63b 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -76,7 +76,7 @@ std::error_code widenPath(const Twine &Path8, SmallVectorImpl<wchar_t> &Path16, // If the path is a long path, mangled into forward slashes, normalize // back to backslashes here. - if (Path8Str.startswith("//?/")) + if (Path8Str.starts_with("//?/")) llvm::sys::path::native(Path8Str, path::Style::windows_backslash); if (std::error_code EC = UTF8ToUTF16(Path8Str, Path16)) @@ -96,7 +96,7 @@ std::error_code widenPath(const Twine &Path8, SmallVectorImpl<wchar_t> &Path16, const char *const LongPathPrefix = "\\\\?\\"; if ((Path16.size() + CurPathLen) < MaxPathLen || - Path8Str.startswith(LongPathPrefix)) + Path8Str.starts_with(LongPathPrefix)) return std::error_code(); if (!IsAbsolute) { diff --git a/llvm/tools/dsymutil/DebugMap.cpp b/llvm/tools/dsymutil/DebugMap.cpp index dcdecdf..8724b70 100644 --- a/llvm/tools/dsymutil/DebugMap.cpp +++ b/llvm/tools/dsymutil/DebugMap.cpp @@ -287,7 +287,7 @@ MappingTraits<dsymutil::DebugMapObject>::YamlDMO::denormalize(IO &IO) { } uint8_t Type = MachO::N_OSO; - if (Path.endswith(".dylib")) { + if (Path.ends_with(".dylib")) { // FIXME: find a more resilient way Type = MachO::N_LIB; } diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index b5d763d..c1e3e2c 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -502,7 +502,7 @@ void CodeCoverageTool::remapPathNames(const CoverageMapping &Coverage) { SmallString<128> NativeFilename; sys::path::native(Filename, NativeFilename); sys::path::remove_dots(NativeFilename, true); - if (NativeFilename.startswith(RemapFrom)) { + if (NativeFilename.starts_with(RemapFrom)) { RemappedFilenames[Filename] = RemapTo + NativeFilename.substr(RemapFrom.size()).str(); } diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp index 060733b..eae2653 100644 --- a/llvm/tools/llvm-cov/CoverageReport.cpp +++ b/llvm/tools/llvm-cov/CoverageReport.cpp @@ -211,7 +211,7 @@ void CoverageReport::render(const FileCoverageSummary &File, sys::path::native(FileName); // remove_dots will remove trailing slash, so we need to check before it. - auto IsDir = FileName.endswith(sys::path::get_separator()); + auto IsDir = FileName.ends_with(sys::path::get_separator()); sys::path::remove_dots(FileName, /*remove_dot_dot=*/true); if (IsDir) FileName += sys::path::get_separator(); diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp index 79a0494..d0a2e44 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -639,7 +639,7 @@ struct CoveragePrinterHTMLDirectory::Reporter : public DirectoryCoverageReport { sys::path::native(LinkTextStr); // remove_dots will remove trailing slash, so we need to check before it. - auto IsDir = LinkTextStr.endswith(sys::path::get_separator()); + auto IsDir = LinkTextStr.ends_with(sys::path::get_separator()); sys::path::remove_dots(LinkTextStr, /*remove_dot_dot=*/true); SmallString<128> LinkTargetStr(LinkTextStr); diff --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp index 4d6bd90..1c71330 100644 --- a/llvm/tools/llvm-ml/llvm-ml.cpp +++ b/llvm/tools/llvm-ml/llvm-ml.cpp @@ -83,7 +83,7 @@ static Triple GetTriple(StringRef ProgName, opt::InputArgList &Args) { StringRef DefaultBitness = "32"; SmallString<255> Program = ProgName; sys::path::replace_extension(Program, ""); - if (Program.endswith("ml64")) + if (Program.ends_with("ml64")) DefaultBitness = "64"; StringRef TripleName = diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index 35a01aa..a7b7e6a 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -882,7 +882,7 @@ TEST_F(FileSystemTest, TempFiles) { int FD2; SmallString<64> TempPath2; ASSERT_NO_ERROR(fs::createTemporaryFile("prefix", "temp", FD2, TempPath2)); - ASSERT_TRUE(TempPath2.endswith(".temp")); + ASSERT_TRUE(TempPath2.ends_with(".temp")); ASSERT_NE(TempPath.str(), TempPath2.str()); fs::file_status A, B; @@ -908,7 +908,7 @@ TEST_F(FileSystemTest, TempFiles) { SmallString<64> TempPath3; ASSERT_NO_ERROR(fs::createTemporaryFile("prefix", "", TempPath3)); - ASSERT_FALSE(TempPath3.endswith(".")); + ASSERT_FALSE(TempPath3.ends_with(".")); FileRemover Cleanup3(TempPath3); // Create a hard link to Temp1. @@ -1515,13 +1515,13 @@ TEST(Support, NormalizePath) { const char *Path7a = "~/aaa"; SmallString<64> Path7(Path7a); path::native(Path7, path::Style::windows_backslash); - EXPECT_TRUE(Path7.endswith("\\aaa")); - EXPECT_TRUE(Path7.startswith(PathHome)); + EXPECT_TRUE(Path7.ends_with("\\aaa")); + EXPECT_TRUE(Path7.starts_with(PathHome)); EXPECT_EQ(Path7.size(), PathHome.size() + strlen(Path7a + 1)); Path7 = Path7a; path::native(Path7, path::Style::windows_slash); - EXPECT_TRUE(Path7.endswith("/aaa")); - EXPECT_TRUE(Path7.startswith(PathHome)); + EXPECT_TRUE(Path7.ends_with("/aaa")); + EXPECT_TRUE(Path7.starts_with(PathHome)); EXPECT_EQ(Path7.size(), PathHome.size() + strlen(Path7a + 1)); const char *Path8a = "~"; |