Skip to content

Commit 2f06eda

Browse files
authored
Support building in Qt5, QByteArrayView compat (dail8859#944)
Make it buildable on Debian 13. `QByteArrayView` referenced in `ByteArrayUtils.h` was introduced in QT6.
1 parent a432c82 commit 2f06eda

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/NotepadNext/ByteArrayUtils.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,36 @@
1818
#pragma once
1919

2020
#include <QByteArray>
21+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
2122
#include <QByteArrayView>
23+
#else
24+
#include <QtGlobal>
25+
#include <cstring>
26+
27+
// WARNING: Dirty QT5 compat. Tested on Debian 13.
28+
class QByteArrayView
29+
{
30+
public:
31+
QByteArrayView() : m_data(nullptr), m_size(0) {}
32+
QByteArrayView(const char* data, qsizetype size) : m_data(data), m_size(size) {}
33+
QByteArrayView(const QByteArray& ba) : m_data(ba.constData()), m_size(ba.size()) {}
34+
const char* data() const { return m_data; }
35+
qsizetype size() const { return m_size; }
36+
bool isEmpty() const { return m_size == 0; }
37+
bool operator==(const QByteArrayView& other) const
38+
{
39+
return m_size == other.m_size && (m_data == other.m_data || (m_size > 0 && std::memcmp(m_data, other.m_data, m_size) == 0));
40+
}
41+
bool operator!=(const QByteArrayView& other) const { return !(*this == other); }
42+
43+
private:
44+
const char* m_data;
45+
qsizetype m_size;
46+
};
47+
#endif
2248
#include <QList>
2349
#include <QSet>
50+
#include <algorithm>
2451
#include <cstring>
2552
#include <unordered_set>
2653

0 commit comments

Comments
 (0)