Utils: Remove more SmallStringView member

With C++ 23 we can hopefully remove the completely.

Change-Id: Ia656bf23bf8e80a3737d37c8b7321aa839c04b69
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2025-02-27 17:16:39 +01:00
parent 3e1049e536
commit 993e88e088
6 changed files with 8 additions and 171 deletions

View File

@@ -191,7 +191,7 @@ void SqlStatementBuilder::clearSqlStatement()
void SqlStatementBuilder::checkIfPlaceHolderExists(Utils::SmallStringView name) const
{
if (name.size() < 2 || !name.startsWith('$') || !m_sqlTemplate.contains(name))
if (name.size() < 2 || !name.starts_with('$') || !m_sqlTemplate.contains(name))
throwException("SqlStatementBuilder::bind: placeholder name does not exist!", name.data());
}

View File

@@ -13,12 +13,6 @@
#include <string>
#include <string_view>
#if __cpp_lib_constexpr_string >= 201907L
#define constexpr_string constexpr
#else
#define constexpr_string
#endif
namespace Utils {
template <typename String>
@@ -36,41 +30,14 @@ class SmallStringView : public std::string_view
public:
using std::string_view::string_view;
constexpr SmallStringView(const_iterator begin, const_iterator end) noexcept
: std::string_view{std::addressof(*begin), static_cast<std::size_t>(std::distance(begin, end))}
{}
#ifdef Q_CC_MSVC
constexpr SmallStringView(const char *const begin, const char *const end) noexcept
: std::string_view{begin, static_cast<std::size_t>(std::distance(begin, end))}
{}
#endif
template<typename String, typename Utils::enable_if_has_char_data_pointer<String> = 0>
constexpr SmallStringView(const String &string) noexcept
: std::string_view{string.data(), static_cast<std::size_t>(string.size())}
{}
static constexpr SmallStringView fromUtf8(const char *const characterPointer)
{
return SmallStringView(characterPointer);
}
constexpr size_type isEmpty() const noexcept { return empty(); }
constexpr
SmallStringView mid(size_type position) const noexcept
{
return SmallStringView(data() + position, size() - position);
}
constexpr
SmallStringView mid(size_type position, size_type length) const noexcept
{
return SmallStringView(data() + position, length);
}
constexpr_string operator std::string() const { return std::string(data(), size()); }
operator std::string() const { return std::string(data(), size()); }
explicit operator QString() const { return QString::fromUtf8(data(), int(size())); }
@@ -89,25 +56,6 @@ public:
{
return QUtf8StringView(data(), Utils::ssize(*this));
}
constexpr bool startsWith(SmallStringView subStringToSearch) const noexcept
{
if (size() >= subStringToSearch.size())
return !std::char_traits<char>::compare(data(),
subStringToSearch.data(),
subStringToSearch.size());
return false;
}
constexpr bool startsWith(char characterToSearch) const noexcept
{
return *begin() == characterToSearch;
}
constexpr bool endsWith(SmallStringView ending) const noexcept
{
return size() >= ending.size() && std::equal(ending.rbegin(), ending.rend(), rbegin());
}
};
inline constexpr auto operator<=>(const SmallStringView &first, const SmallStringView &second)

View File

@@ -79,7 +79,7 @@ public:
SourceContextId sourceContextId(Utils::SmallStringView sourceContextPath) const override
{
Utils::SmallStringView path = sourceContextPath.back() == '/'
? sourceContextPath.mid(0, sourceContextPath.size() - 1)
? sourceContextPath.substr(0, sourceContextPath.size() - 1)
: sourceContextPath;
return m_sourceContextPathCache.id(path);

View File

@@ -51,13 +51,13 @@ public:
Utils::SmallStringView directory() const noexcept
{
return mid(0, std::size_t(std::max(std::ptrdiff_t(0), m_slashIndex)));
return substr(0, std::size_t(std::max(std::ptrdiff_t(0), m_slashIndex)));
}
Utils::SmallStringView name() const noexcept
{
return mid(std::size_t(m_slashIndex + 1),
std::size_t(std::ptrdiff_t(size()) - m_slashIndex - std::ptrdiff_t(1)));
return substr(std::size_t(m_slashIndex + 1),
std::size_t(std::ptrdiff_t(size()) - m_slashIndex - std::ptrdiff_t(1)));
}
static

View File

@@ -100,13 +100,13 @@ auto makeCollectorDispatcherChain(ImageCacheCollector &nodeInstanceCollector,
std::make_pair([](Utils::SmallStringView filePath,
[[maybe_unused]] Utils::SmallStringView state,
[[maybe_unused]] const QmlDesigner::ImageCache::AuxiliaryData
&auxiliaryData) { return filePath.endsWith(".qml"); },
&auxiliaryData) { return filePath.ends_with(".qml"); },
&nodeInstanceCollector),
std::make_pair(
[](Utils::SmallStringView filePath,
[[maybe_unused]] Utils::SmallStringView state,
[[maybe_unused]] const QmlDesigner::ImageCache::AuxiliaryData &auxiliaryData) {
return filePath.endsWith(".mesh") || filePath.startsWith("#");
return filePath.ends_with(".mesh") || filePath.starts_with("#");
},
&meshImageCollector),
std::make_pair(

View File

@@ -726,44 +726,6 @@ TYPED_TEST(SmallString, from_q_byte_array)
ASSERT_THAT(text, SmallString("short string"));
}
TYPED_TEST(SmallString, mid_one_parameter)
{
using SmallString = typename TestFixture::String;
SmallString text("some text");
auto midString = text.mid(5);
ASSERT_THAT(midString, Eq(SmallString("text")));
}
TYPED_TEST(SmallString, mid_two_parameter)
{
using SmallString = typename TestFixture::String;
SmallString text("some text and more");
auto midString = text.mid(5, 4);
ASSERT_THAT(midString, Eq(SmallString("text")));
}
TYPED_TEST(SmallString, small_string_view_mid_one_parameter)
{
SmallStringView text("some text");
auto midString = text.mid(5);
ASSERT_THAT(midString, Eq(SmallStringView("text")));
}
TYPED_TEST(SmallString, small_string_view_mid_two_parameter)
{
SmallStringView text("some text and more");
auto midString = text.mid(5, 4);
ASSERT_THAT(midString, Eq(SmallStringView("text")));
}
TYPED_TEST(SmallString, size_of_empty_stringl)
{
using SmallString = typename TestFixture::String;
@@ -1442,79 +1404,6 @@ TYPED_TEST(SmallString, dont_reserve_if_nothing_is_replaced_for_shorter_replacem
ASSERT_TRUE(text.isReadOnlyReference());
}
TYPED_TEST(SmallString, starts_with)
{
using SmallString = typename TestFixture::String;
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('@'));
}
TYPED_TEST(SmallString, starts_with_string_view)
{
SmallStringView 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('@'));
}
TYPED_TEST(SmallString, starts_with_qstringview)
{
using SmallString = typename TestFixture::String;
using namespace Qt::StringLiterals;
SmallString text("$column");
ASSERT_FALSE(text.startsWith(u"$columnxxx"_s));
ASSERT_TRUE(text.startsWith(u"$column"_s));
ASSERT_TRUE(text.startsWith(u"$col"_s));
ASSERT_FALSE(text.startsWith(u"col"_s));
ASSERT_TRUE(text.startsWith(u"$"_s));
ASSERT_FALSE(text.startsWith(u"@"_s));
}
TYPED_TEST(SmallString, ends_with)
{
using SmallString = typename TestFixture::String;
SmallString text("/my/path");
ASSERT_TRUE(text.endsWith("/my/path"));
ASSERT_TRUE(text.endsWith("path"));
ASSERT_FALSE(text.endsWith("paths"));
ASSERT_TRUE(text.endsWith('h'));
ASSERT_FALSE(text.endsWith('x'));
}
TYPED_TEST(SmallString, ends_with_string_view)
{
SmallStringView text("/my/path");
ASSERT_TRUE(text.endsWith("/my/path"));
ASSERT_TRUE(text.endsWith("path"));
ASSERT_FALSE(text.endsWith("paths"));
}
TYPED_TEST(SmallString, ends_with_small_string)
{
using SmallString = typename TestFixture::String;
SmallString text("/my/path");
ASSERT_TRUE(text.endsWith(SmallString("path")));
ASSERT_TRUE(text.endsWith('h'));
}
TYPED_TEST(SmallString, reserve_smaller_than_short_string_capacity)
{
using SmallString = typename TestFixture::String;