forked from qt-creator/qt-creator
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:
@@ -203,6 +203,15 @@ public:
|
|||||||
SmallStringView toStringView() const noexcept { return SmallStringView(data(), size()); }
|
SmallStringView toStringView() const noexcept { return SmallStringView(data(), size()); }
|
||||||
|
|
||||||
operator SmallStringView() const noexcept { return SmallStringView(data(), size()); }
|
operator SmallStringView() const noexcept { return SmallStringView(data(), size()); }
|
||||||
|
explicit operator QLatin1StringView() const noexcept
|
||||||
|
{
|
||||||
|
return QLatin1StringView(data(), Utils::ssize(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
operator QUtf8StringView() const noexcept
|
||||||
|
{
|
||||||
|
return QUtf8StringView(data(), Utils::ssize(*this));
|
||||||
|
}
|
||||||
|
|
||||||
explicit operator QString() const noexcept { return toQString(); }
|
explicit operator QString() const noexcept { return toQString(); }
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "algorithm.h"
|
||||||
#include "smallstringfwd.h"
|
#include "smallstringfwd.h"
|
||||||
#include "smallstringiterator.h"
|
#include "smallstringiterator.h"
|
||||||
|
|
||||||
@@ -76,11 +77,17 @@ public:
|
|||||||
return QString::fromUtf8(data(), int(size()));
|
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
|
constexpr bool startsWith(SmallStringView subStringToSearch) const noexcept
|
||||||
{
|
{
|
||||||
if (size() >= subStringToSearch.size())
|
if (size() >= subStringToSearch.size())
|
||||||
|
|||||||
Reference in New Issue
Block a user