forked from qt-creator/qt-creator
preprocessor: streamline ByteArrayRef
Change-Id: Iec09651a6aa2fe3b8a50e631fd2fdc57830892a5 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
|
||||
using namespace CPlusPlus::Internal;
|
||||
|
||||
const QByteArray ByteArrayRef::m_emptyByteArray;
|
||||
|
||||
bool ByteArrayRef::startsWith(const char *s) const
|
||||
{
|
||||
int l = std::strlen(s);
|
||||
|
||||
@@ -13,20 +13,17 @@ class CPLUSPLUS_EXPORT ByteArrayRef
|
||||
{
|
||||
public:
|
||||
ByteArrayRef()
|
||||
: m_ref(&m_emptyByteArray)
|
||||
, m_offset(0)
|
||||
: m_start("")
|
||||
, m_length(0)
|
||||
{}
|
||||
|
||||
ByteArrayRef(const QByteArray *ref)
|
||||
: m_ref(ref)
|
||||
, m_offset(0)
|
||||
: m_start(ref->constData())
|
||||
, m_length(ref->length())
|
||||
{}
|
||||
|
||||
ByteArrayRef(const QByteArray *ref, int offset, int length)
|
||||
: m_ref(ref)
|
||||
, m_offset(offset)
|
||||
: m_start(ref->constData() + offset)
|
||||
, m_length(length)
|
||||
{
|
||||
Q_ASSERT(ref);
|
||||
@@ -36,7 +33,7 @@ public:
|
||||
}
|
||||
|
||||
inline const char *start() const
|
||||
{ return m_ref->constData() + m_offset; }
|
||||
{ return m_start; }
|
||||
|
||||
inline int length() const
|
||||
{ return m_length; }
|
||||
@@ -45,21 +42,21 @@ public:
|
||||
{ return length(); }
|
||||
|
||||
inline char at(int pos) const
|
||||
{ return pos >= 0 && pos < m_length ? m_ref->at(m_offset + pos) : '\0'; }
|
||||
{ return pos >= 0 && pos < m_length ? m_start[pos] : '\0'; }
|
||||
|
||||
inline char operator[](int pos) const
|
||||
{ return at(pos); }
|
||||
|
||||
QByteArray toByteArray() const
|
||||
{ return QByteArray(m_ref->constData() + m_offset, m_length); }
|
||||
{ return QByteArray(m_start, m_length); }
|
||||
|
||||
bool operator==(const QByteArray &other) const
|
||||
{ return m_length == other.length() && !qstrncmp(m_ref->constData() + m_offset, other.constData(), m_length); }
|
||||
{ return m_length == other.length() && !qstrncmp(m_start, other.constData(), m_length); }
|
||||
bool operator!=(const QByteArray &other) const
|
||||
{ return !this->operator==(other); }
|
||||
|
||||
bool operator==(const char *other) const
|
||||
{ return qstrncmp(m_ref->constData() + m_offset, other, strlen(other)) == 0; }
|
||||
{ return qstrncmp(m_start, other, strlen(other)) == 0; }
|
||||
bool operator!=(const char *other) const
|
||||
{ return !this->operator==(other); }
|
||||
|
||||
@@ -68,9 +65,7 @@ public:
|
||||
int count(char c) const;
|
||||
|
||||
private:
|
||||
const static QByteArray m_emptyByteArray;
|
||||
const QByteArray * const m_ref;
|
||||
const int m_offset;
|
||||
const char *m_start;
|
||||
const int m_length;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user