forked from qt-creator/qt-creator
Utils: Add endsWith to SmallStringView
Change-Id: Iea8286b46c28a68b26904e256b9f084c32c79909 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -106,6 +106,11 @@ public:
|
||||
{
|
||||
return *begin() == characterToSearch;
|
||||
}
|
||||
|
||||
constexpr bool endsWith(SmallStringView ending) const noexcept
|
||||
{
|
||||
return size() >= ending.size() && std::equal(ending.rbegin(), ending.rend(), rbegin());
|
||||
}
|
||||
};
|
||||
|
||||
constexpr bool operator==(SmallStringView first, SmallStringView second) noexcept
|
||||
|
@@ -1296,6 +1296,15 @@ TEST(SmallString, EndsWith)
|
||||
ASSERT_FALSE(text.endsWith('x'));
|
||||
}
|
||||
|
||||
TEST(SmallString, EndsWithStringView)
|
||||
{
|
||||
SmallStringView text("/my/path");
|
||||
|
||||
ASSERT_TRUE(text.endsWith("/my/path"));
|
||||
ASSERT_TRUE(text.endsWith("path"));
|
||||
ASSERT_FALSE(text.endsWith("paths"));
|
||||
}
|
||||
|
||||
TEST(SmallString, EndsWithSmallString)
|
||||
{
|
||||
SmallString text("/my/path");
|
||||
|
Reference in New Issue
Block a user