Commit daa3aad6 authored by Marco Bubke's avatar Marco Bubke

Utils: Add startWith to string view

We will add more function if they are needed.

Change-Id: Iac6b432327be32a0778a82c23ed2de5996c555a1
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 19e01596
......@@ -116,6 +116,19 @@ public:
return std::string(data(), size());
}
bool startsWith(SmallStringView subStringToSearch) const noexcept
{
if (size() >= subStringToSearch.size())
return !std::memcmp(m_pointer, subStringToSearch.data(), subStringToSearch.size());
return false;
}
bool startsWith(char characterToSearch) const noexcept
{
return m_pointer[0] == characterToSearch;
}
private:
const char *m_pointer;
size_type m_size;
......
......@@ -866,6 +866,19 @@ TEST(SmallString, StartsWith)
{
SmallString text("$column");
ASSERT_FALSE(text.startsWith("$columnxxx"));
ASSERT_TRUE(text.startsWith("$column"));
ASSERT_TRUE(text.startsWith("$col"));
ASSERT_FALSE(text.startsWith("col"));
ASSERT_TRUE(text.startsWith('$'));
ASSERT_FALSE(text.startsWith('@'));
}
TEST(SmallString, StartsWithStringView)
{
SmallStringView text("$column");
ASSERT_FALSE(text.startsWith("$columnxxx"));
ASSERT_TRUE(text.startsWith("$column"));
ASSERT_TRUE(text.startsWith("$col"));
ASSERT_FALSE(text.startsWith("col"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment