2012-03-26 15:18:01 +02:00
|
|
|
#ifndef CPLUSPLUS_INTERNAL_PPTOKEN_H
|
|
|
|
|
#define CPLUSPLUS_INTERNAL_PPTOKEN_H
|
|
|
|
|
|
|
|
|
|
#include <CPlusPlus.h>
|
|
|
|
|
#include <Token.h>
|
|
|
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
|
|
|
|
|
|
namespace CPlusPlus {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class CPLUSPLUS_EXPORT ByteArrayRef
|
|
|
|
|
{
|
|
|
|
|
public:
|
2012-04-16 11:33:36 +02:00
|
|
|
ByteArrayRef()
|
2012-04-18 12:04:05 +02:00
|
|
|
: m_start("")
|
2012-04-16 11:33:36 +02:00
|
|
|
, m_length(0)
|
|
|
|
|
{}
|
2012-03-26 15:18:01 +02:00
|
|
|
|
|
|
|
|
ByteArrayRef(const QByteArray *ref)
|
2012-04-18 12:04:05 +02:00
|
|
|
: m_start(ref->constData())
|
2012-03-26 15:18:01 +02:00
|
|
|
, m_length(ref->length())
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
ByteArrayRef(const QByteArray *ref, int offset, int length)
|
2012-04-18 12:04:05 +02:00
|
|
|
: m_start(ref->constData() + offset)
|
2012-03-26 15:18:01 +02:00
|
|
|
, m_length(length)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(ref);
|
|
|
|
|
Q_ASSERT(offset >= 0);
|
|
|
|
|
Q_ASSERT(length >= 0);
|
|
|
|
|
Q_ASSERT(offset + length <= ref->size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline const char *start() const
|
2012-04-18 12:04:05 +02:00
|
|
|
{ return m_start; }
|
2012-03-26 15:18:01 +02:00
|
|
|
|
|
|
|
|
inline int length() const
|
|
|
|
|
{ return m_length; }
|
|
|
|
|
|
|
|
|
|
inline int size() const
|
|
|
|
|
{ return length(); }
|
|
|
|
|
|
|
|
|
|
inline char at(int pos) const
|
2012-04-18 12:04:05 +02:00
|
|
|
{ return pos >= 0 && pos < m_length ? m_start[pos] : '\0'; }
|
2012-03-26 15:18:01 +02:00
|
|
|
|
|
|
|
|
inline char operator[](int pos) const
|
|
|
|
|
{ return at(pos); }
|
|
|
|
|
|
|
|
|
|
QByteArray toByteArray() const
|
2012-04-18 12:04:05 +02:00
|
|
|
{ return QByteArray(m_start, m_length); }
|
2012-03-26 15:18:01 +02:00
|
|
|
|
|
|
|
|
bool operator==(const QByteArray &other) const
|
2012-04-18 12:04:05 +02:00
|
|
|
{ return m_length == other.length() && !qstrncmp(m_start, other.constData(), m_length); }
|
2012-03-26 15:18:01 +02:00
|
|
|
bool operator!=(const QByteArray &other) const
|
|
|
|
|
{ return !this->operator==(other); }
|
|
|
|
|
|
2012-04-18 11:54:36 +02:00
|
|
|
bool operator==(const char *other) const
|
2012-04-18 12:04:05 +02:00
|
|
|
{ return qstrncmp(m_start, other, strlen(other)) == 0; }
|
2012-04-18 11:54:36 +02:00
|
|
|
bool operator!=(const char *other) const
|
|
|
|
|
{ return !this->operator==(other); }
|
|
|
|
|
|
2012-03-26 15:18:01 +02:00
|
|
|
bool startsWith(const char *ch) const;
|
|
|
|
|
|
|
|
|
|
int count(char c) const;
|
|
|
|
|
|
|
|
|
|
private:
|
2012-04-18 12:04:05 +02:00
|
|
|
const char *m_start;
|
2012-04-16 11:33:36 +02:00
|
|
|
const int m_length;
|
2012-03-26 15:18:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inline bool operator==(const QByteArray &other, const ByteArrayRef &ref)
|
|
|
|
|
{ return ref == other; }
|
|
|
|
|
|
|
|
|
|
inline bool operator!=(const QByteArray &other, const ByteArrayRef &ref)
|
|
|
|
|
{ return ref != other; }
|
|
|
|
|
|
|
|
|
|
class CPLUSPLUS_EXPORT PPToken: public Token
|
|
|
|
|
{
|
|
|
|
|
public:
|
2012-04-16 11:17:55 +02:00
|
|
|
PPToken() {}
|
2012-03-26 15:18:01 +02:00
|
|
|
|
|
|
|
|
PPToken(const QByteArray &src)
|
|
|
|
|
: m_src(src)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void setSource(const QByteArray &src)
|
|
|
|
|
{ m_src = src; }
|
|
|
|
|
|
|
|
|
|
const QByteArray &source() const
|
|
|
|
|
{ return m_src; }
|
|
|
|
|
|
|
|
|
|
const char *start() const
|
|
|
|
|
{ return m_src.constData() + offset; }
|
|
|
|
|
|
|
|
|
|
ByteArrayRef asByteArrayRef() const
|
|
|
|
|
{ return ByteArrayRef(&m_src, offset, length()); }
|
|
|
|
|
|
|
|
|
|
bool isValid() const
|
|
|
|
|
{ return !m_src.isEmpty(); }
|
|
|
|
|
|
|
|
|
|
void squeeze();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QByteArray m_src;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace CPlusPlus
|
|
|
|
|
|
|
|
|
|
#endif // CPLUSPLUS_INTERNAL_PPTOKEN_H
|