Utils: Add more conversion operators to SmallString

An explicit operator for QLatin1StringView. That is dangerous if the
string is not ASCII and one for QUtf8StringView.

Change-Id: I2d0a0ca3854b47595563a19263aacd7f8825d026
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2023-09-06 16:50:45 +02:00
parent 1e35f3cf19
commit a4f8cf709e
2 changed files with 18 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
#pragma once
#include "algorithm.h"
#include "smallstringfwd.h"
#include "smallstringiterator.h"
@@ -76,11 +77,17 @@ public:
return QString::fromUtf8(data(), int(size()));
}
explicit operator QByteArray() const
explicit operator QByteArray() const { return QByteArray(data(), int(size())); }
explicit operator QLatin1StringView() const noexcept
{
return QByteArray(data(), int(size()));
return QLatin1StringView(data(), Utils::ssize(*this));
}
operator QUtf8StringView() const noexcept
{
return QUtf8StringView(data(), Utils::ssize(*this));
}
constexpr bool startsWith(SmallStringView subStringToSearch) const noexcept
{
if (size() >= subStringToSearch.size())