#ifndef KHTMLSTRING_H
#define KHTMLSTRING_H
#include "dom/dom_string.h"
#include <qstring.h>
#include <assert.h>
namespace khtml
{
class DOMStringIt
{
public:
DOMStringIt()
{ s = 0, l = 0; lines = 0; }
DOMStringIt(QChar *str, uint len)
{ s = str, l = len; lines = 0; }
DOMStringIt(const QString &str)
{ s = str.unicode(); l = str.length(); lines = 0; }
DOMStringIt(const DOM::DOMString &str)
{ s = str.unicode(); l = str.length(); lines = 0; }
DOMStringIt *operator++()
{
if (!pushedChar1.isNull()) {
pushedChar1 = pushedChar2;
pushedChar2 = 0;
} else if (l > 0) {
if (*s == '\n')
lines++;
s++, l--;
}
return this;
}
void push(const QChar& c) {
if (pushedChar1.isNull())
pushedChar1 = c;
else {
assert(pushedChar2.isNull());
pushedChar2 = c;
}
}
const QChar *current() const {
if (!pushedChar1.isNull())
return &pushedChar1;
if (!pushedChar2.isNull())
return &pushedChar2;
return s;
}
const QChar& operator*() const { return *current(); }
const QChar* operator->() const { return current(); }
bool escaped() const { return !pushedChar1.isNull(); }
uint length() const { return l + !pushedChar1.isNull() + !pushedChar2.isNull(); }
int lineCount() const { return lines; }
protected:
QChar pushedChar1;
QChar pushedChar2;
const QChar *s;
int l;
int lines;
};
}
#endif