Qt 4.8
Static Public Functions | List of all members
QCss::Scanner Class Reference

#include <qcssparser_p.h>

Static Public Functions

static QString preprocess (const QString &input, bool *hasEscapeSequences=0)
 
static void scan (const QString &preprocessedInput, QVector< Symbol > *symbols)
 

Detailed Description

Definition at line 742 of file qcssparser_p.h.

Functions

◆ preprocess()

QString Scanner::preprocess ( const QString input,
bool *  hasEscapeSequences = 0 
)
static

Definition at line 2012 of file qcssparser.cpp.

Referenced by QCss::Parser::init().

2013 {
2014  QString output = input;
2015 
2016  if (hasEscapeSequences)
2017  *hasEscapeSequences = false;
2018 
2019  int i = 0;
2020  while (i < output.size()) {
2021  if (output.at(i) == QLatin1Char('\\')) {
2022 
2023  ++i;
2024  // test for unicode hex escape
2025  int hexCount = 0;
2026  const int hexStart = i;
2027  while (i < output.size()
2028  && isHexDigit(output.at(i).toLatin1())
2029  && hexCount < 7) {
2030  ++hexCount;
2031  ++i;
2032  }
2033  if (hexCount == 0) {
2034  if (hasEscapeSequences)
2035  *hasEscapeSequences = true;
2036  continue;
2037  }
2038 
2039  hexCount = qMin(hexCount, 6);
2040  bool ok = false;
2041  ushort code = output.mid(hexStart, hexCount).toUShort(&ok, 16);
2042  if (ok) {
2043  output.replace(hexStart - 1, hexCount + 1, QChar(code));
2044  i = hexStart;
2045  } else {
2046  i = hexStart;
2047  }
2048  } else {
2049  ++i;
2050  }
2051  }
2052  return output;
2053 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort toUShort(bool *ok=0, int base=10) const
Returns the string converted to an unsigned short using base base, which is 10 by default and must be...
Definition: qstring.cpp:6180
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
static bool isHexDigit(const char c)
unsigned short ushort
Definition: qglobal.h:995
char toLatin1() const
Returns the Latin-1 character equivalent to the QChar, or 0.
Definition: qchar.h:376
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ scan()

void Scanner::scan ( const QString preprocessedInput,
QVector< Symbol > *  symbols 
)
static

Definition at line 2068 of file qcssparser.cpp.

Referenced by QCss::Parser::init().

2069 {
2070  QCssScanner_Generated scanner(preprocessedInput);
2071  Symbol sym;
2072  int tok = scanner.lex();
2073  while (tok != -1) {
2074  sym.token = static_cast<QCss::TokenType>(tok);
2075  sym.text = scanner.input;
2076  sym.start = scanner.lexemStart;
2077  sym.len = scanner.lexemLength;
2078  symbols->append(sym);
2079  tok = scanner.lex();
2080  }
2081 }
QString text
Definition: qcssparser_p.h:737
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
TokenType token
Definition: qcssparser_p.h:736

The documentation for this class was generated from the following files: