3#ifndef QBYTEARRAYVIEW_H
4#define QBYTEARRAYVIEW_H
6#include <QtCore/qbytearrayalgorithms.h>
7#include <QtCore/qcompare.h>
8#include <QtCore/qstringfwd.h>
9#include <QtCore/qarraydata.h>
13#include <QtCore/q20type_traits.h>
19template <
typename Byte>
21 : std::integral_constant<bool,
22 std::is_same_v<Byte, char> ||
23 std::is_same_v<Byte, uchar> ||
24 std::is_same_v<Byte, signed char> ||
25 std::is_same_v<Byte, std::byte>> {};
27template <
typename Byte>
31template <
typename Po
inter>
33template <
typename Byte>
35 : IsCompatibleByteType<Byte> {};
36template<
typename Po
inter>
40template <
typename T,
typename Enable =
void>
48 IsCompatibleByteArrayPointer<decltype(std::data(std::declval<const T &>()))>,
50 std::is_convertible<decltype(std::size(std::declval<const T &>())), qsizetype>,
52 IsCompatibleByteType<typename std::iterator_traits<decltype(
53 std::begin(std::declval<const T &>()))>::value_type>,
54 std::is_convertible<decltype(std::begin(std::declval<const T &>())
55 != std::end(std::declval<const T &>())),
59 std::negation<std::is_same<std::decay_t<T>, QByteArray>>,
62 std::negation<std::is_array<T>>,
65 std::negation<std::is_same<std::decay_t<T>, QByteArrayView>>>>> : std::true_type {};
68template <
typename Char>
94 template <
typename Byte>
95 using if_compatible_byte =
96 typename std::enable_if_t<QtPrivate::IsCompatibleByteType<Byte>::value,
bool>;
98 template <
typename Po
inter>
99 using if_compatible_pointer =
100 typename std::enable_if_t<QtPrivate::IsCompatibleByteArrayPointer<Pointer>::value,
103 template <
typename T>
104 using if_compatible_qbytearray_like =
105 typename std::enable_if_t<std::is_same_v<T, QByteArray>,
bool>;
107 template <
typename T>
108 using if_compatible_container =
109 typename std::enable_if_t<QtPrivate::IsContainerCompatibleWithQByteArrayView<T>::value,
112 template <
typename Container>
113 static constexpr qsizetype lengthHelperContainer(
const Container &
c)
noexcept
118 static constexpr qsizetype lengthHelperCharArray(
const char *
data,
size_t size)
noexcept
120 const auto it = std::char_traits<char>::find(
data,
size,
'\0');
125 template <
typename Byte>
126 static const storage_type *castHelper(
const Byte *
data)
noexcept
127 {
return reinterpret_cast<const storage_type*
>(
data); }
128 static constexpr const storage_type *castHelper(
const storage_type *
data)
noexcept
133 : m_size(0),
m_data(
nullptr) {}
137 template <
typename Byte, if_compatible_
byte<Byte> = true>
142 template <
typename Byte, if_compatible_
byte<Byte> = true>
147 template <
typename Byte>
150 template <
typename Po
inter, if_compatible_po
inter<Po
inter> = true>
159 template <
typename ByteArray, if_compatible_q
bytearray_like<ByteArray> = true>
164 template <
typename Container, if_compatible_container<Container> = true>
167 template <
size_t Size>
175 template <
typename Byte,
size_t Size>
177 template <
typename Byte,
size_t Size, if_compatible_
byte<Byte> = true>
181 [[nodiscard]]
inline QByteArray toByteArray()
const;
196 { verify(0,
n);
return sliced(0,
n); }
198 { verify(0,
n);
return sliced(
size() -
n,
n); }
204 { verify(0,
len);
return sliced(0,
size() -
len); }
219 { verify(0,
n); m_size =
n; }
221 { verify(0,
n); m_size -=
n; }
227 {
return QtPrivate::toIntegral<short>(*
this,
ok,
base); }
229 {
return QtPrivate::toIntegral<ushort>(*
this,
ok,
base); }
231 {
return QtPrivate::toIntegral<int>(*
this,
ok,
base); }
233 {
return QtPrivate::toIntegral<uint>(*
this,
ok,
base); }
235 {
return QtPrivate::toIntegral<long>(*
this,
ok,
base); }
237 {
return QtPrivate::toIntegral<ulong>(*
this,
ok,
base); }
239 {
return QtPrivate::toIntegral<qlonglong>(*
this,
ok,
base); }
241 {
return QtPrivate::toIntegral<qulonglong>(*
this,
ok,
base); }
247 return r.value_or(0.0f);
254 return r.value_or(0.0);
260 {
return !empty() && front() ==
c; }
264 [[nodiscard]]
constexpr bool endsWith(
char c)
const noexcept
265 {
return !empty() && back() ==
c; }
305 [[nodiscard]]
constexpr bool empty() const noexcept {
return size() == 0; }
309 [[nodiscard]]
constexpr Q_IMPLICIT operator std::string_view() const noexcept
310 {
return std::string_view(
m_data,
size_t(m_size)); }
315 [[nodiscard]]
constexpr bool isNull() const noexcept {
return !
m_data; }
316 [[nodiscard]]
constexpr bool isEmpty() const noexcept {
return empty(); }
319 [[nodiscard]]
constexpr char first()
const {
return front(); }
320 [[nodiscard]]
constexpr char last()
const {
return back(); }
335 return lhs.size() == rhs.size()
336 && (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
354 friend Q_CORE_EXPORT
bool
358 friend Q_CORE_EXPORT
bool
362#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
368 const storage_type *
m_data;
372template<
typename QByteArrayLike,
373 std::enable_if_t<std::is_same_v<QByteArrayLike, QByteArray>,
bool> =
true>
383#if QT_DEPRECATED_SINCE(6, 0)
386 Qt::ChecksumType standard =
Qt::ChecksumIso3309)
394 if (from < haystack.size()) {
395 const char *
const b = haystack.data();
396 if (
const auto n =
static_cast<const char *
>(
397 memchr(
b + from, needle,
static_cast<size_t>(haystack.size() - from)))) {
constexpr char front() const
constexpr bool isNull() const noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
friend Qt::strong_ordering compareThreeWay(const QByteArrayView &lhs, const char *rhs) noexcept
constexpr char first() const
qsizetype lastIndexOf(QByteArrayView a, qsizetype from) const noexcept
constexpr char back() const
qsizetype lastIndexOf(char ch, qsizetype from=-1) const noexcept
constexpr char operator[](qsizetype n) const
std::reverse_iterator< iterator > reverse_iterator
constexpr QByteArrayView(const Container &c) noexcept
constexpr qsizetype length() const noexcept
bool contains(QByteArrayView a) const noexcept
constexpr const_iterator begin() const noexcept
bool startsWith(QByteArrayView other) const noexcept
constexpr char at(qsizetype n) const
friend bool comparesEqual(const QByteArrayView &lhs, const QByteArrayView &rhs) noexcept
constexpr const_iterator end() const noexcept
qlonglong toLongLong(bool *ok=nullptr, int base=10) const
constexpr QByteArrayView right(qsizetype n) const
int toInt(bool *ok=nullptr, int base=10) const
uint toUInt(bool *ok=nullptr, int base=10) const
qulonglong toULongLong(bool *ok=nullptr, int base=10) const
constexpr QByteArrayView(const Byte *data, qsizetype len)
constexpr const_reverse_iterator rend() const noexcept
constexpr QByteArrayView last(qsizetype n) const
qsizetype count(char ch) const noexcept
ushort toUShort(bool *ok=nullptr, int base=10) const
qsizetype indexOf(char ch, qsizetype from=0) const noexcept
float toFloat(bool *ok=nullptr) const
constexpr char last() const
constexpr QByteArrayView mid(qsizetype pos, qsizetype n=-1) const
value_type & const_reference
constexpr const_reverse_iterator rbegin() const noexcept
bool endsWith(QByteArrayView other) const noexcept
ulong toULong(bool *ok=nullptr, int base=10) const
constexpr bool startsWith(char c) const noexcept
short toShort(bool *ok=nullptr, int base=10) const
constexpr QByteArrayView sliced(qsizetype pos) const
constexpr QByteArrayView first(qsizetype n) const
constexpr bool endsWith(char c) const noexcept
const_pointer const_iterator
constexpr void truncate(qsizetype n)
constexpr bool isEmpty() const noexcept
friend Qt::strong_ordering compareThreeWay(const QByteArrayView &lhs, const QByteArrayView &rhs) noexcept
qsizetype count(QByteArrayView a) const noexcept
constexpr const_reverse_iterator crbegin() const noexcept
constexpr qsizetype size() const noexcept
value_type * const_pointer
constexpr QByteArrayView() noexcept
constexpr const_iterator cbegin() const noexcept
QByteArrayView(const ByteArray &ba) noexcept
constexpr QByteArrayView(const Byte *first, const Byte *last)
constexpr bool empty() const noexcept
static constexpr QByteArrayView fromArray(const Byte(&data)[Size]) noexcept
constexpr QByteArrayView left(qsizetype n) const
qsizetype lastIndexOf(QByteArrayView a) const noexcept
bool contains(char c) const noexcept
int compare(QByteArrayView a, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QByteArrayView chopped(qsizetype len) const
constexpr void chop(qsizetype n)
constexpr QByteArrayView sliced(qsizetype pos, qsizetype n) const
bool isValidUtf8() const noexcept
constexpr const_reverse_iterator crend() const noexcept
constexpr const_pointer data() const noexcept
constexpr QByteArrayView(std::nullptr_t) noexcept
constexpr QByteArrayView(const Pointer &data) noexcept
long toLong(bool *ok=nullptr, int base=10) const
qsizetype indexOf(QByteArrayView a, qsizetype from=0) const noexcept
QByteArrayView trimmed() const noexcept
double toDouble(bool *ok=nullptr) const
constexpr const_iterator cend() const noexcept
constexpr const_pointer constData() const noexcept
constexpr QByteArrayView(const char(&data)[Size]) noexcept
bool isNull() const noexcept
Returns true if this byte array is null; otherwise returns false.
\inmodule QtCore \title Classes and helpers for defining comparison operators \keyword qtcompare
QSet< QString >::iterator it
Combined button and popup list for selecting options.
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QByteArrayView haystack, qsizetype from, char needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
qsizetype findByteArray(QByteArrayView haystack, qsizetype from, char needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QByteArrayView trimmed(QByteArrayView s) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT int compareMemory(QByteArrayView lhs, QByteArrayView rhs)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION ParsedNumber< float > toFloat(QByteArrayView a) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION ParsedNumber< double > toDouble(QByteArrayView a) noexcept
static constexpr qsizetype lengthHelperPointer(const Char *data) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf8(QByteArrayView s) noexcept
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
int qstrnicmp(const char *str1, qsizetype len1, const char *str2, qsizetype len2)
Q_CORE_EXPORT quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard=Qt::ChecksumIso3309)
QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept
#define Q_DECLARE_STRONGLY_ORDERED(...)
bool comparesEqual(const QDir &lhs, const QDir &rhs)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define QT_ASCII_CAST_WARN
#define QT_DEPRECATED_VERSION_X_6_0(text)
static int compare(quint64 a, quint64 b)
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Qt::weak_ordering compareThreeWay(const QUrl &lhs, const QUrl &rhs)