39 #ifndef QBYTEARRAYVIEW_H
40 #define QBYTEARRAYVIEW_H
42 #include <QtCore/qbytearrayalgorithms.h>
53 template <
typename Byte>
55 : std::integral_constant<bool,
56 std::is_same_v<Byte, char> ||
57 std::is_same_v<Byte, uchar> ||
58 std::is_same_v<Byte, signed char> ||
59 std::is_same_v<Byte, std::byte>> {};
61 template <
typename Byte>
64 typename std::remove_cv_t<typename std::remove_reference_t<Byte>>> {};
66 template <
typename Po
inter>
68 template <
typename Byte>
71 template<
typename Po
inter>
74 typename std::remove_cv_t<typename std::remove_reference_t<Pointer>>> {};
76 template <
typename T,
typename Enable =
void>
84 IsCompatibleByteArrayPointer<decltype(std::data(std::declval<const T &>()))>,
86 std::is_convertible<decltype(std::size(std::declval<const T &>())), qsizetype>,
88 IsCompatibleByteType<typename std::iterator_traits<decltype(
89 std::begin(std::declval<const T &>()))>::value_type>,
90 std::is_convertible<decltype(std::begin(std::declval<const T &>())
91 != std::end(std::declval<const T &>())),
95 std::negation<std::is_same<std::decay_t<T>, QByteArray>>,
98 std::negation<std::is_array<T>>,
101 std::negation<std::is_same<std::decay_t<T>, QByteArrayView>>>>> : std::true_type {};
123 template <
typename Byte>
124 using if_compatible_byte =
127 template <
typename Po
inter>
128 using if_compatible_pointer =
132 template <
typename T>
133 using if_compatible_qbytearray_like =
134 typename std::enable_if_t<std::is_same_v<T, QByteArray>,
bool>;
136 template <
typename T>
137 using if_compatible_container =
141 template <
typename Char>
147 template <
typename Container>
153 static constexpr
qsizetype lengthHelperCharArray(
const char *
data,
size_t size) noexcept
160 template <
typename Byte>
161 static const storage_type *castHelper(
const Byte *
data) noexcept
162 {
return reinterpret_cast<const storage_type*
>(
data); }
163 static constexpr
const storage_type *castHelper(
const storage_type *
data) noexcept
168 : m_size(0), m_data(
nullptr) {}
172 template <
typename Byte, if_compatible_
byte<Byte> = true>
175 m_data(castHelper(
data)) {}
177 template <
typename Byte, if_compatible_
byte<Byte> = true>
182 template <
typename Byte>
185 template <
typename Po
inter, if_compatible_po
inter<Po
inter> = true>
194 template <
typename ByteArray, if_compatible_q
bytearray_like<ByteArray> = true>
199 template <
typename Container, if_compatible_container<Container> = true>
202 template <
size_t Size>
207 template <
typename Byte,
size_t Size>
209 template <
typename Byte,
size_t Size, if_compatible_
byte<Byte> = true>
213 [[nodiscard]]
inline QByteArray toByteArray()
const;
247 {
return QtPrivate::toIntegral<short>(*
this,
ok,
base); }
249 {
return QtPrivate::toIntegral<ushort>(*
this,
ok,
base); }
251 {
return QtPrivate::toIntegral<int>(*
this,
ok,
base); }
253 {
return QtPrivate::toIntegral<uint>(*
this,
ok,
base); }
255 {
return QtPrivate::toIntegral<long>(*
this,
ok,
base); }
257 {
return QtPrivate::toIntegral<ulong>(*
this,
ok,
base); }
259 {
return QtPrivate::toIntegral<qlonglong>(*
this,
ok,
base); }
261 {
return QtPrivate::toIntegral<qulonglong>(*
this,
ok,
base); }
267 return r.value_or(0.0f);
274 return r.value_or(0.0);
280 {
return !empty() && front() ==
c; }
285 {
return !empty() && back() ==
c; }
326 [[nodiscard]] constexpr
char front()
const {
Q_ASSERT(!empty());
return m_data[0]; }
327 [[nodiscard]] constexpr
char back()
const {
Q_ASSERT(!empty());
return m_data[m_size - 1]; }
332 [[nodiscard]] constexpr
bool isNull()
const noexcept {
return !m_data; }
333 [[nodiscard]] constexpr
bool isEmpty()
const noexcept {
return empty(); }
336 [[nodiscard]] constexpr
char first()
const {
return front(); }
337 [[nodiscard]] constexpr
char last()
const {
return back(); }
342 {
return !(lhs ==
rhs); }
348 {
return !(lhs <=
rhs); }
350 {
return !(lhs <
rhs); }
354 const storage_type *m_data;
358 template<
typename QByteArrayLike,
359 std::enable_if_t<std::is_same_v<QByteArrayLike, QByteArray>,
bool> =
true>
369 #if QT_DEPRECATED_SINCE(6, 0)
The QByteArray class provides an array of bytes.
qsizetype size() const noexcept
quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard)
int qstrnicmp(const char *str1, const char *str2, size_t len)
bool isNull() const noexcept
constexpr char front() const
constexpr bool isNull() const noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
constexpr char first() const
qsizetype lastIndexOf(QByteArrayView a, qsizetype from) const noexcept
friend bool operator==(QByteArrayView lhs, QByteArrayView rhs) 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
constexpr const_iterator end() const noexcept
qlonglong toLongLong(bool *ok=nullptr, int base=10) 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
friend bool operator>=(QByteArrayView lhs, QByteArrayView rhs) 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
value_type & const_reference
constexpr const_reverse_iterator rbegin() const noexcept
friend bool operator<=(QByteArrayView lhs, QByteArrayView rhs) noexcept
bool endsWith(QByteArrayView other) const noexcept
ulong toULong(bool *ok=nullptr, int base=10) const
short toShort(bool *ok=nullptr, int base=10) const
constexpr QByteArrayView sliced(qsizetype pos) const
constexpr QByteArrayView first(qsizetype n) const
const_pointer const_iterator
constexpr void truncate(qsizetype n)
bool endsWith(char c) const noexcept
constexpr bool isEmpty() const 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
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
constexpr static QByteArrayView fromArray(const Byte(&data)[Size]) noexcept
bool startsWith(char c) const noexcept
friend bool operator!=(QByteArrayView lhs, QByteArrayView rhs) noexcept
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
auto it unsigned count const
QT_BEGIN_NAMESPACE bool operator<(const QMimeType &t1, const QMimeType &t2)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QByteArrayView haystack, QByteArrayView 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 lastIndexOf(QByteArrayView haystack, qsizetype from, 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 qsizetype findByteArray(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION ParsedNumber< double > toDouble(QByteArrayView a) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf8(QByteArrayView s) noexcept
int distance(TestIterator &a, TestIterator &b)
QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept
Q_DECLARE_TYPEINFO(QByteArrayView, Q_PRIMITIVE_TYPE)
constexpr bool operator>(const QFixed &f, int i)
#define QT_DEPRECATED_VERSION_X_6_0(text)
GLenum GLuint GLenum GLsizei length
GLboolean GLboolean GLboolean b
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)
QT_BEGIN_NAMESPACE typedef char Char
void compare(Input input, FnUnderTest fn_under_test, const QByteArray &output)
QDomElement find(const QString &tagName, const QDomElement &e)