Qt 4.8
Public Functions | Public Variables | List of all members
QCss::Parser Class Reference

#include <qcssparser_p.h>

Public Functions

Symbol errorSymbol ()
 
bool hasNext () const
 
void init (const QString &css, bool file=false)
 
QString lexem () const
 
QString lexemUntil (TokenType t)
 
TokenType lookup () const
 
bool lookupElementName () const
 
TokenType next ()
 
bool next (TokenType t)
 
bool parse (StyleSheet *styleSheet, Qt::CaseSensitivity nameCaseSensitivity=Qt::CaseSensitive)
 
bool parseAttrib (AttributeSelector *attr)
 
bool parseClass (QString *name)
 
bool parseCombinator (BasicSelector::Relation *relation)
 
bool parseElementName (QString *name)
 
bool parseExpr (QVector< Value > *values)
 
bool parseFunction (QString *name, QString *args)
 
bool parseHexColor (QColor *col)
 
bool parseImport (ImportRule *importRule)
 
bool parseMedia (MediaRule *mediaRule)
 
bool parseMedium (QStringList *media)
 
bool parseNextDeclaration (Declaration *declaration)
 
bool parseNextExpr (QVector< Value > *values)
 
bool parseNextFunction (QString *name, QString *args)
 
bool parseNextMedium (QStringList *media)
 
bool parseNextOperator (Value *value)
 
bool parseNextSelector (Selector *sel)
 
bool parseNextSimpleSelector (BasicSelector *basicSel)
 
bool parsePage (PageRule *pageRule)
 
bool parsePrio (Declaration *declaration)
 
bool parseProperty (Declaration *decl)
 
bool parsePseudo (Pseudo *pseudo)
 
bool parsePseudoPage (QString *selector)
 
 Parser ()
 
 Parser (const QString &css, bool file=false)
 
bool parseRuleset (StyleRule *styleRule)
 
bool parseSelector (Selector *sel)
 
bool parseSimpleSelector (BasicSelector *basicSel)
 
bool parseTerm (Value *value)
 
void prev ()
 
bool recordError ()
 
void skipSpace ()
 
const Symbolsymbol () const
 
bool test (TokenType t)
 
bool testAndParseUri (QString *uri)
 
bool testAttrib ()
 
bool testClass ()
 
bool testCombinator ()
 
bool testElementName ()
 
bool testExpr ()
 
bool testFunction ()
 
bool testHexColor ()
 
bool testImport ()
 
bool testMedia ()
 
bool testMedium ()
 
bool testPage ()
 
bool testPrio ()
 
bool testProperty ()
 
bool testPseudo ()
 
bool testPseudoPage ()
 
bool testRuleset ()
 
bool testSelector ()
 
bool testSimpleSelector ()
 
bool testTerm ()
 
bool testTokenAndEndsWith (TokenType t, const QLatin1String &str)
 
QString unquotedLexem () const
 
bool until (TokenType target, TokenType target2=NONE)
 

Public Variables

int errorIndex
 
bool hasEscapeSequences
 
int index
 
QString sourcePath
 
QVector< Symbolsymbols
 

Detailed Description

Definition at line 749 of file qcssparser_p.h.

Constructors and Destructors

◆ Parser() [1/2]

Parser::Parser ( )

Definition at line 2101 of file qcssparser.cpp.

2102 {
2103  index = 0;
2104  errorIndex = -1;
2105  hasEscapeSequences = false;
2106 }
bool hasEscapeSequences
Definition: qcssparser_p.h:832

◆ Parser() [2/2]

Parser::Parser ( const QString css,
bool  file = false 
)

Definition at line 2096 of file qcssparser.cpp.

2097 {
2098  init(css, isFile);
2099 }
void init(const QString &css, bool file=false)

Functions

◆ errorSymbol()

Symbol Parser::errorSymbol ( )

Definition at line 2173 of file qcssparser.cpp.

2174 {
2175  if (errorIndex == -1) return Symbol();
2176  return symbols.at(errorIndex);
2177 }
QVector< Symbol > symbols
Definition: qcssparser_p.h:829

◆ hasNext()

bool QCss::Parser::hasNext ( ) const
inline

Definition at line 811 of file qcssparser_p.h.

811 { return index < symbols.count(); }
QVector< Symbol > symbols
Definition: qcssparser_p.h:829

◆ init()

void Parser::init ( const QString css,
bool  file = false 
)

Definition at line 2108 of file qcssparser.cpp.

2109 {
2110  QString styleSheet = css;
2111  if (isFile) {
2112  QFile file(css);
2113  if (file.open(QFile::ReadOnly)) {
2114  sourcePath = QFileInfo(styleSheet).absolutePath() + QLatin1Char('/');
2115  QTextStream stream(&file);
2116  styleSheet = stream.readAll();
2117  } else {
2118  qWarning() << "QCss::Parser - Failed to load file " << css;
2119  styleSheet.clear();
2120  }
2121  } else {
2122  sourcePath.clear();
2123  }
2124 
2125  hasEscapeSequences = false;
2126  symbols.resize(0);
2127  symbols.reserve(8);
2129  index = 0;
2130  errorIndex = -1;
2131 }
static QString preprocess(const QString &input, bool *hasEscapeSequences=0)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QVector< Symbol > symbols
Definition: qcssparser_p.h:829
static FILE * stream
Q_CORE_EXPORT void qWarning(const char *,...)
static void scan(const QString &preprocessedInput, QVector< Symbol > *symbols)
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QString sourcePath
Definition: qcssparser_p.h:833
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QString absolutePath() const
Returns a file&#39;s path absolute path.
Definition: qfileinfo.cpp:577
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool hasEscapeSequences
Definition: qcssparser_p.h:832

◆ lexem()

QString QCss::Parser::lexem ( ) const
inline

Definition at line 817 of file qcssparser_p.h.

817 { return symbol().lexem(); }
const Symbol & symbol() const
Definition: qcssparser_p.h:816
QString lexem() const

◆ lexemUntil()

QString Parser::lexemUntil ( QCss::TokenType  t)

Definition at line 2709 of file qcssparser.cpp.

2710 {
2711  QString lexem;
2712  while (hasNext() && next() != t)
2713  lexem += symbol().lexem();
2714  return lexem;
2715 }
bool hasNext() const
Definition: qcssparser_p.h:811
The QString class provides a Unicode character string.
Definition: qstring.h:83
const Symbol & symbol() const
Definition: qcssparser_p.h:816
TokenType next()
Definition: qcssparser_p.h:812
QString lexem() const
Definition: qcssparser_p.h:817
QString lexem() const

◆ lookup()

TokenType QCss::Parser::lookup ( ) const
inline

Definition at line 821 of file qcssparser_p.h.

821  {
822  return (index - 1) < symbols.count() ? symbols.at(index - 1).token : NONE;
823  }
QVector< Symbol > symbols
Definition: qcssparser_p.h:829

◆ lookupElementName()

bool QCss::Parser::lookupElementName ( ) const
inline

Definition at line 807 of file qcssparser_p.h.

807 { return lookup() == IDENT || lookup() == STAR; }
TokenType lookup() const
Definition: qcssparser_p.h:821

◆ next() [1/2]

TokenType QCss::Parser::next ( )
inline

Definition at line 812 of file qcssparser_p.h.

812 { return symbols.at(index++).token; }
QVector< Symbol > symbols
Definition: qcssparser_p.h:829

◆ next() [2/2]

bool Parser::next ( QCss::TokenType  t)

Definition at line 2681 of file qcssparser.cpp.

2682 {
2683  if (hasNext() && next() == t)
2684  return true;
2685  return recordError();
2686 }
bool hasNext() const
Definition: qcssparser_p.h:811
bool recordError()
Definition: qcssparser_p.h:827
TokenType next()
Definition: qcssparser_p.h:812

◆ parse()

bool Parser::parse ( StyleSheet styleSheet,
Qt::CaseSensitivity  nameCaseSensitivity = Qt::CaseSensitive 
)

Definition at line 2133 of file qcssparser.cpp.

Referenced by QSvgHandler::characters(), QTextHtmlParser::importStyleSheet(), QTextHtmlParserNode::parseStyleAttribute(), QSvgHandler::processingInstruction(), and QTextDocument::setDefaultStyleSheet().

2134 {
2136  if (!next(STRING)) return false;
2137  if (!next(SEMICOLON)) return false;
2138  }
2139 
2140  while (test(S) || test(CDO) || test(CDC)) {}
2141 
2142  while (testImport()) {
2143  ImportRule rule;
2144  if (!parseImport(&rule)) return false;
2145  styleSheet->importRules.append(rule);
2146  while (test(S) || test(CDO) || test(CDC)) {}
2147  }
2148 
2149  do {
2150  if (testMedia()) {
2151  MediaRule rule;
2152  if (!parseMedia(&rule)) return false;
2153  styleSheet->mediaRules.append(rule);
2154  } else if (testPage()) {
2155  PageRule rule;
2156  if (!parsePage(&rule)) return false;
2157  styleSheet->pageRules.append(rule);
2158  } else if (testRuleset()) {
2159  StyleRule rule;
2160  if (!parseRuleset(&rule)) return false;
2161  styleSheet->styleRules.append(rule);
2162  } else if (test(ATKEYWORD_SYM)) {
2163  if (!until(RBRACE)) return false;
2164  } else if (hasNext()) {
2165  return false;
2166  }
2167  while (test(S) || test(CDO) || test(CDC)) {}
2168  } while (hasNext());
2169  styleSheet->buildIndexes(nameCaseSensitivity);
2170  return true;
2171 }
void buildIndexes(Qt::CaseSensitivity nameCaseSensitivity=Qt::CaseSensitive)
bool testImport()
Definition: qcssparser_p.h:794
bool hasNext() const
Definition: qcssparser_p.h:811
bool parsePage(PageRule *pageRule)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
TokenType next()
Definition: qcssparser_p.h:812
bool parseRuleset(StyleRule *styleRule)
QVector< StyleRule > styleRules
Definition: qcssparser_p.h:639
QVector< MediaRule > mediaRules
Definition: qcssparser_p.h:640
bool testPage()
Definition: qcssparser_p.h:796
bool until(TokenType target, TokenType target2=NONE)
bool testRuleset()
Definition: qcssparser_p.h:782
bool testMedia()
Definition: qcssparser_p.h:795
bool parseMedia(MediaRule *mediaRule)
bool testTokenAndEndsWith(TokenType t, const QLatin1String &str)
bool parseImport(ImportRule *importRule)
QVector< PageRule > pageRules
Definition: qcssparser_p.h:641
bool test(TokenType t)
QVector< ImportRule > importRules
Definition: qcssparser_p.h:642

◆ parseAttrib()

bool Parser::parseAttrib ( AttributeSelector attr)

Definition at line 2433 of file qcssparser.cpp.

2434 {
2435  skipSpace();
2436  if (!next(IDENT)) return false;
2437  attr->name = lexem();
2438  skipSpace();
2439 
2440  if (test(EQUAL)) {
2442  } else if (test(INCLUDES)) {
2444  } else if (test(DASHMATCH)) {
2446  } else {
2447  return next(RBRACKET);
2448  }
2449 
2450  skipSpace();
2451 
2452  if (!test(IDENT) && !test(STRING)) return false;
2453  attr->value = unquotedLexem();
2454 
2455  skipSpace();
2456  return next(RBRACKET);
2457 }
QString unquotedLexem() const
void skipSpace()
Definition: qcssparser_p.h:809
TokenType next()
Definition: qcssparser_p.h:812
ValueMatchType valueMatchCriterium
Definition: qcssparser_p.h:532
QString lexem() const
Definition: qcssparser_p.h:817
bool test(TokenType t)

◆ parseClass()

bool Parser::parseClass ( QString name)

Definition at line 2416 of file qcssparser.cpp.

2417 {
2418  if (!next(IDENT)) return false;
2419  *name = lexem();
2420  return true;
2421 }
TokenType next()
Definition: qcssparser_p.h:812
QString lexem() const
Definition: qcssparser_p.h:817

◆ parseCombinator()

bool Parser::parseCombinator ( BasicSelector::Relation relation)

Definition at line 2285 of file qcssparser.cpp.

2286 {
2287  *relation = BasicSelector::NoRelation;
2288  if (lookup() == S) {
2290  skipSpace();
2291  } else {
2292  prev();
2293  }
2294  if (test(PLUS)) {
2296  } else if (test(GREATER)) {
2298  }
2299  skipSpace();
2300  return true;
2301 }
void skipSpace()
Definition: qcssparser_p.h:809
TokenType lookup() const
Definition: qcssparser_p.h:821
bool test(TokenType t)

◆ parseElementName()

bool Parser::parseElementName ( QString name)

Definition at line 2423 of file qcssparser.cpp.

2424 {
2425  switch (lookup()) {
2426  case STAR: name->clear(); break;
2427  case IDENT: *name = lexem(); break;
2428  default: return false;
2429  }
2430  return true;
2431 }
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
TokenType lookup() const
Definition: qcssparser_p.h:821
QString lexem() const
Definition: qcssparser_p.h:817

◆ parseExpr()

bool Parser::parseExpr ( QVector< Value > *  values)

Definition at line 2515 of file qcssparser.cpp.

2516 {
2517  Value val;
2518  if (!parseTerm(&val)) return false;
2519  values->append(val);
2520  bool onceMore;
2521  do {
2522  onceMore = false;
2523  val = Value();
2524  if (!parseNextOperator(&val)) return false;
2525  if (val.type != QCss::Value::Unknown)
2526  values->append(val);
2527  if (testTerm()) {
2528  onceMore = true;
2529  val = Value();
2530  if (!parseTerm(&val)) return false;
2531  values->append(val);
2532  }
2533  } while (onceMore);
2534  return true;
2535 }
bool parseTerm(Value *value)
bool parseNextOperator(Value *value)
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573

◆ parseFunction()

bool Parser::parseFunction ( QString name,
QString args 
)

Definition at line 2625 of file qcssparser.cpp.

2626 {
2627  *name = lexem();
2628  name->chop(1);
2629  skipSpace();
2630  const int start = index;
2631  if (!until(RPAREN)) return false;
2632  for (int i = start; i < index - 1; ++i)
2633  args->append(symbols.at(i).lexem());
2634  /*
2635  if (!nextExpr(&arguments)) return false;
2636  if (!next(RPAREN)) return false;
2637  */
2638  skipSpace();
2639  return true;
2640 }
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
void skipSpace()
Definition: qcssparser_p.h:809
QVector< Symbol > symbols
Definition: qcssparser_p.h:829
bool until(TokenType target, TokenType target2=NONE)
QString & append(QChar c)
Definition: qstring.cpp:1777
QString lexem() const
Definition: qcssparser_p.h:817

◆ parseHexColor()

bool Parser::parseHexColor ( QColor col)

Definition at line 2642 of file qcssparser.cpp.

2643 {
2644  col->setNamedColor(lexem());
2645  if (!col->isValid()) {
2646  qWarning("QCssParser::parseHexColor: Unknown color name '%s'",lexem().toLatin1().constData());
2647  return false;
2648  }
2649  skipSpace();
2650  return true;
2651 }
void setNamedColor(const QString &name)
Sets the RGB value of this QColor to name, which may be in one of these formats:
Definition: qcolor.cpp:560
void skipSpace()
Definition: qcssparser_p.h:809
Q_CORE_EXPORT void qWarning(const char *,...)
QString lexem() const
Definition: qcssparser_p.h:817
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295

◆ parseImport()

bool Parser::parseImport ( ImportRule importRule)

Definition at line 2188 of file qcssparser.cpp.

2189 {
2190  skipSpace();
2191 
2192  if (test(STRING)) {
2193  importRule->href = lexem();
2194  } else {
2195  if (!testAndParseUri(&importRule->href)) return false;
2196  }
2197  removeOptionalQuotes(&importRule->href);
2198 
2199  skipSpace();
2200 
2201  if (testMedium()) {
2202  if (!parseMedium(&importRule->media)) return false;
2203 
2204  while (test(COMMA)) {
2205  skipSpace();
2206  if (!parseNextMedium(&importRule->media)) return false;
2207  }
2208  }
2209 
2210  if (!next(SEMICOLON)) return false;
2211 
2212  skipSpace();
2213  return true;
2214 }
bool testMedium()
Definition: qcssparser_p.h:791
bool parseMedium(QStringList *media)
void skipSpace()
Definition: qcssparser_p.h:809
static void removeOptionalQuotes(QString *str)
TokenType next()
Definition: qcssparser_p.h:812
bool parseNextMedium(QStringList *media)
Definition: qcssparser_p.h:792
QString lexem() const
Definition: qcssparser_p.h:817
bool test(TokenType t)
bool testAndParseUri(QString *uri)
QStringList media
Definition: qcssparser_p.h:625

◆ parseMedia()

bool Parser::parseMedia ( MediaRule mediaRule)

Definition at line 2216 of file qcssparser.cpp.

2217 {
2218  do {
2219  skipSpace();
2220  if (!parseNextMedium(&mediaRule->media)) return false;
2221  } while (test(COMMA));
2222 
2223  if (!next(LBRACE)) return false;
2224  skipSpace();
2225 
2226  while (testRuleset()) {
2227  StyleRule rule;
2228  if (!parseRuleset(&rule)) return false;
2229  mediaRule->styleRules.append(rule);
2230  }
2231 
2232  if (!next(RBRACE)) return false;
2233  skipSpace();
2234  return true;
2235 }
void skipSpace()
Definition: qcssparser_p.h:809
TokenType next()
Definition: qcssparser_p.h:812
bool parseRuleset(StyleRule *styleRule)
bool parseNextMedium(QStringList *media)
Definition: qcssparser_p.h:792
bool testRuleset()
Definition: qcssparser_p.h:782
QStringList media
Definition: qcssparser_p.h:612
bool test(TokenType t)
QVector< StyleRule > styleRules
Definition: qcssparser_p.h:613

◆ parseMedium()

bool Parser::parseMedium ( QStringList media)

Definition at line 2237 of file qcssparser.cpp.

2238 {
2239  media->append(lexem());
2240  skipSpace();
2241  return true;
2242 }
void skipSpace()
Definition: qcssparser_p.h:809
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QString lexem() const
Definition: qcssparser_p.h:817

◆ parseNextDeclaration()

bool Parser::parseNextDeclaration ( Declaration declaration)

Definition at line 2479 of file qcssparser.cpp.

2480 {
2481  if (!testProperty())
2482  return true; // not an error!
2483  if (!parseProperty(decl)) return false;
2484  if (!next(COLON)) return false;
2485  skipSpace();
2486  if (!parseNextExpr(&decl->d->values)) return false;
2487  if (testPrio())
2488  if (!parsePrio(decl)) return false;
2489  return true;
2490 }
bool parseProperty(Declaration *decl)
bool parsePrio(Declaration *declaration)
void skipSpace()
Definition: qcssparser_p.h:809
bool testProperty()
Definition: qcssparser_p.h:798
TokenType next()
Definition: qcssparser_p.h:812
bool parseNextExpr(QVector< Value > *values)
Definition: qcssparser_p.h:801

◆ parseNextExpr()

bool QCss::Parser::parseNextExpr ( QVector< Value > *  values)
inline

Definition at line 801 of file qcssparser_p.h.

801 { if (!testExpr()) return recordError(); return parseExpr(values); }
bool recordError()
Definition: qcssparser_p.h:827
bool parseExpr(QVector< Value > *values)
bool testExpr()
Definition: qcssparser_p.h:800

◆ parseNextFunction()

bool QCss::Parser::parseNextFunction ( QString name,
QString args 
)
inline

Definition at line 805 of file qcssparser_p.h.

805 { if (!testFunction()) return recordError(); return parseFunction(name, args); }
bool recordError()
Definition: qcssparser_p.h:827
bool parseFunction(QString *name, QString *args)
bool testFunction()
Definition: qcssparser_p.h:804

◆ parseNextMedium()

bool QCss::Parser::parseNextMedium ( QStringList media)
inline

Definition at line 792 of file qcssparser_p.h.

792 { if (!testMedium()) return recordError(); return parseMedium(media); }
bool testMedium()
Definition: qcssparser_p.h:791
bool parseMedium(QStringList *media)
bool recordError()
Definition: qcssparser_p.h:827

◆ parseNextOperator()

bool Parser::parseNextOperator ( Value value)

Definition at line 2274 of file qcssparser.cpp.

2275 {
2276  if (!hasNext()) return true;
2277  switch (next()) {
2278  case SLASH: value->type = Value::TermOperatorSlash; skipSpace(); break;
2279  case COMMA: value->type = Value::TermOperatorComma; skipSpace(); break;
2280  default: prev(); break;
2281  }
2282  return true;
2283 }
bool hasNext() const
Definition: qcssparser_p.h:811
void skipSpace()
Definition: qcssparser_p.h:809
TokenType next()
Definition: qcssparser_p.h:812

◆ parseNextSelector()

bool QCss::Parser::parseNextSelector ( Selector sel)
inline

Definition at line 784 of file qcssparser_p.h.

784 { if (!testSelector()) return recordError(); return parseSelector(sel); }
bool parseSelector(Selector *sel)
bool recordError()
Definition: qcssparser_p.h:827
bool testSelector()
Definition: qcssparser_p.h:783

◆ parseNextSimpleSelector()

bool QCss::Parser::parseNextSimpleSelector ( BasicSelector basicSel)
inline

Definition at line 786 of file qcssparser_p.h.

786 { if (!testSimpleSelector()) return recordError(); return parseSimpleSelector(basicSel); }
bool recordError()
Definition: qcssparser_p.h:827
bool parseSimpleSelector(BasicSelector *basicSel)
bool testSimpleSelector()

◆ parsePage()

bool Parser::parsePage ( PageRule pageRule)

Definition at line 2244 of file qcssparser.cpp.

2245 {
2246  skipSpace();
2247 
2248  if (testPseudoPage())
2249  if (!parsePseudoPage(&pageRule->selector)) return false;
2250 
2251  skipSpace();
2252  if (!next(LBRACE)) return false;
2253 
2254  do {
2255  skipSpace();
2256  Declaration decl;
2257  if (!parseNextDeclaration(&decl)) return false;
2258  if (!decl.isEmpty())
2259  pageRule->declarations.append(decl);
2260  } while (test(SEMICOLON));
2261 
2262  if (!next(RBRACE)) return false;
2263  skipSpace();
2264  return true;
2265 }
QString selector
Definition: qcssparser_p.h:618
void skipSpace()
Definition: qcssparser_p.h:809
TokenType next()
Definition: qcssparser_p.h:812
bool isEmpty() const
Definition: qcssparser_p.h:432
bool parsePseudoPage(QString *selector)
bool testPseudoPage()
Definition: qcssparser_p.h:793
bool parseNextDeclaration(Declaration *declaration)
bool test(TokenType t)
QVector< Declaration > declarations
Definition: qcssparser_p.h:619

◆ parsePrio()

bool Parser::parsePrio ( Declaration declaration)

Definition at line 2508 of file qcssparser.cpp.

2509 {
2510  declaration->d->important = true;
2511  skipSpace();
2512  return true;
2513 }
void skipSpace()
Definition: qcssparser_p.h:809
QExplicitlySharedDataPointer< DeclarationData > d
Definition: qcssparser_p.h:430

◆ parseProperty()

bool Parser::parseProperty ( Declaration decl)

Definition at line 2303 of file qcssparser.cpp.

2304 {
2305  decl->d->property = lexem();
2306  decl->d->propertyId = static_cast<Property>(findKnownValue(decl->d->property, properties, NumProperties));
2307  skipSpace();
2308  return true;
2309 }
void skipSpace()
Definition: qcssparser_p.h:809
QExplicitlySharedDataPointer< DeclarationData > d
Definition: qcssparser_p.h:430
static quint64 findKnownValue(const QString &name, const QCssKnownValue *start, int numValues)
Definition: qcssparser.cpp:357
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
QString lexem() const
Definition: qcssparser_p.h:817

◆ parsePseudo()

bool Parser::parsePseudo ( Pseudo pseudo)

Definition at line 2459 of file qcssparser.cpp.

2460 {
2461  (void)test(COLON);
2462  pseudo->negated = test(EXCLAMATION_SYM);
2463  if (test(IDENT)) {
2464  pseudo->name = lexem();
2465  pseudo->type = static_cast<quint64>(findKnownValue(pseudo->name, pseudos, NumPseudos));
2466  return true;
2467  }
2468  if (!next(FUNCTION)) return false;
2469  pseudo->function = lexem();
2470  // chop off trailing parenthesis
2471  pseudo->function.chop(1);
2472  skipSpace();
2473  if (!test(IDENT)) return false;
2474  pseudo->name = lexem();
2475  skipSpace();
2476  return next(RPAREN);
2477 }
QString function
Definition: qcssparser_p.h:516
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
QString name
Definition: qcssparser_p.h:515
void skipSpace()
Definition: qcssparser_p.h:809
const int NumPseudos
Definition: qcssparser_p.h:509
static const QCssKnownValue pseudos[NumPseudos - 1]
Definition: qcssparser.cpp:262
TokenType next()
Definition: qcssparser_p.h:812
unsigned __int64 quint64
Definition: qglobal.h:943
quint64 type
Definition: qcssparser_p.h:514
static quint64 findKnownValue(const QString &name, const QCssKnownValue *start, int numValues)
Definition: qcssparser.cpp:357
QString lexem() const
Definition: qcssparser_p.h:817
bool test(TokenType t)

◆ parsePseudoPage()

bool Parser::parsePseudoPage ( QString selector)

Definition at line 2267 of file qcssparser.cpp.

2268 {
2269  if (!next(IDENT)) return false;
2270  *selector = lexem();
2271  return true;
2272 }
TokenType next()
Definition: qcssparser_p.h:812
QString lexem() const
Definition: qcssparser_p.h:817

◆ parseRuleset()

bool Parser::parseRuleset ( StyleRule styleRule)

Definition at line 2311 of file qcssparser.cpp.

2312 {
2313  Selector sel;
2314  if (!parseSelector(&sel)) return false;
2315  styleRule->selectors.append(sel);
2316 
2317  while (test(COMMA)) {
2318  skipSpace();
2319  Selector sel;
2320  if (!parseNextSelector(&sel)) return false;
2321  styleRule->selectors.append(sel);
2322  }
2323 
2324  skipSpace();
2325  if (!next(LBRACE)) return false;
2326  const int declarationStart = index;
2327 
2328  do {
2329  skipSpace();
2330  Declaration decl;
2331  const int rewind = index;
2332  if (!parseNextDeclaration(&decl)) {
2333  index = rewind;
2334  const bool foundSemicolon = until(SEMICOLON);
2335  const int semicolonIndex = index;
2336 
2337  index = declarationStart;
2338  const bool foundRBrace = until(RBRACE);
2339 
2340  if (foundSemicolon && semicolonIndex < index) {
2341  decl = Declaration();
2342  index = semicolonIndex - 1;
2343  } else {
2344  skipSpace();
2345  return foundRBrace;
2346  }
2347  }
2348  if (!decl.isEmpty())
2349  styleRule->declarations.append(decl);
2350  } while (test(SEMICOLON));
2351 
2352  if (!next(RBRACE)) return false;
2353  skipSpace();
2354  return true;
2355 }
bool parseNextSelector(Selector *sel)
Definition: qcssparser_p.h:784
bool parseSelector(Selector *sel)
void skipSpace()
Definition: qcssparser_p.h:809
TokenType next()
Definition: qcssparser_p.h:812
QVector< Selector > selectors
Definition: qcssparser_p.h:605
bool isEmpty() const
Definition: qcssparser_p.h:432
#define rewind(a)
QVector< Declaration > declarations
Definition: qcssparser_p.h:606
bool until(TokenType target, TokenType target2=NONE)
bool parseNextDeclaration(Declaration *declaration)
bool test(TokenType t)

◆ parseSelector()

bool Parser::parseSelector ( Selector sel)

Definition at line 2357 of file qcssparser.cpp.

2358 {
2359  BasicSelector basicSel;
2360  if (!parseSimpleSelector(&basicSel)) return false;
2361  while (testCombinator()) {
2362  if (!parseCombinator(&basicSel.relationToNext)) return false;
2363 
2364  if (!testSimpleSelector()) break;
2365  sel->basicSelectors.append(basicSel);
2366 
2367  basicSel = BasicSelector();
2368  if (!parseSimpleSelector(&basicSel)) return false;
2369  }
2370  sel->basicSelectors.append(basicSel);
2371  return true;
2372 }
QVector< BasicSelector > basicSelectors
Definition: qcssparser_p.h:557
bool parseSimpleSelector(BasicSelector *basicSel)
bool testSimpleSelector()
bool testCombinator()
Definition: qcssparser_p.h:797
bool parseCombinator(BasicSelector::Relation *relation)

◆ parseSimpleSelector()

bool Parser::parseSimpleSelector ( BasicSelector basicSel)

Definition at line 2374 of file qcssparser.cpp.

2375 {
2376  int minCount = 0;
2377  if (lookupElementName()) {
2378  if (!parseElementName(&basicSel->elementName)) return false;
2379  } else {
2380  prev();
2381  minCount = 1;
2382  }
2383  bool onceMore;
2384  int count = 0;
2385  do {
2386  onceMore = false;
2387  if (test(HASH)) {
2388  QString theid = lexem();
2389  // chop off leading #
2390  theid.remove(0, 1);
2391  basicSel->ids.append(theid);
2392  onceMore = true;
2393  } else if (testClass()) {
2394  onceMore = true;
2396  a.name = QLatin1String("class");
2398  if (!parseClass(&a.value)) return false;
2399  basicSel->attributeSelectors.append(a);
2400  } else if (testAttrib()) {
2401  onceMore = true;
2403  if (!parseAttrib(&a)) return false;
2404  basicSel->attributeSelectors.append(a);
2405  } else if (testPseudo()) {
2406  onceMore = true;
2407  Pseudo ps;
2408  if (!parsePseudo(&ps)) return false;
2409  basicSel->pseudos.append(ps);
2410  }
2411  if (onceMore) ++count;
2412  } while (onceMore);
2413  return count >= minCount;
2414 }
bool parseElementName(QString *name)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
long ASN1_INTEGER_get ASN1_INTEGER * a
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool parseAttrib(AttributeSelector *attr)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QVector< Pseudo > pseudos
Definition: qcssparser_p.h:549
bool testClass()
Definition: qcssparser_p.h:788
bool parsePseudo(Pseudo *pseudo)
bool lookupElementName() const
Definition: qcssparser_p.h:807
bool parseClass(QString *name)
bool testAttrib()
Definition: qcssparser_p.h:789
ValueMatchType valueMatchCriterium
Definition: qcssparser_p.h:532
bool testPseudo()
Definition: qcssparser_p.h:790
QString lexem() const
Definition: qcssparser_p.h:817
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
bool test(TokenType t)
QVector< AttributeSelector > attributeSelectors
Definition: qcssparser_p.h:550

◆ parseTerm()

bool Parser::parseTerm ( Value value)

Definition at line 2549 of file qcssparser.cpp.

2550 {
2551  QString str = lexem();
2552  bool haveUnary = false;
2553  if (lookup() == PLUS || lookup() == MINUS) {
2554  haveUnary = true;
2555  if (!hasNext()) return false;
2556  next();
2557  str += lexem();
2558  }
2559 
2560  value->variant = str;
2561  value->type = QCss::Value::String;
2562  switch (lookup()) {
2563  case NUMBER:
2564  value->type = Value::Number;
2566  break;
2567  case PERCENTAGE:
2568  value->type = Value::Percentage;
2569  str.chop(1); // strip off %
2570  value->variant = str;
2571  break;
2572  case LENGTH:
2573  value->type = Value::Length;
2574  break;
2575 
2576  case STRING:
2577  if (haveUnary) return false;
2578  value->type = Value::String;
2579  str.chop(1);
2580  str.remove(0, 1);
2581  value->variant = str;
2582  break;
2583  case IDENT: {
2584  if (haveUnary) return false;
2585  value->type = Value::Identifier;
2586  const int theid = findKnownValue(str, values, NumKnownValues);
2587  if (theid != 0) {
2588  value->type = Value::KnownIdentifier;
2589  value->variant = theid;
2590  }
2591  break;
2592  }
2593  default: {
2594  if (haveUnary) return false;
2595  prev();
2596  if (testHexColor()) {
2597  QColor col;
2598  if (!parseHexColor(&col)) return false;
2599  value->type = Value::Color;
2600  value->variant = col;
2601  } else if (testFunction()) {
2602  QString name, args;
2603  if (!parseFunction(&name, &args)) return false;
2604  if (name == QLatin1String("url")) {
2605  value->type = Value::Uri;
2606  removeOptionalQuotes(&args);
2607  if (QFileInfo(args).isRelative() && !sourcePath.isEmpty()) {
2608  args.prepend(sourcePath);
2609  }
2610  value->variant = args;
2611  } else {
2612  value->type = Value::Function;
2613  value->variant = QStringList() << name << args;
2614  }
2615  } else {
2616  return recordError();
2617  }
2618  return true;
2619  }
2620  }
2621  skipSpace();
2622  return true;
2623 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
bool hasNext() const
Definition: qcssparser_p.h:811
QString & prepend(QChar c)
Definition: qstring.h:261
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool recordError()
Definition: qcssparser_p.h:827
The QString class provides a Unicode character string.
Definition: qstring.h:83
void skipSpace()
Definition: qcssparser_p.h:809
QVariant variant
Definition: qcssparser_p.h:372
static void removeOptionalQuotes(QString *str)
TokenType next()
Definition: qcssparser_p.h:812
bool parseFunction(QString *name, QString *args)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool testHexColor()
Definition: qcssparser_p.h:803
static quint64 findKnownValue(const QString &name, const QCssKnownValue *start, int numValues)
Definition: qcssparser.cpp:357
static const QCssKnownValue values[NumKnownValues - 1]
Definition: qcssparser.cpp:172
bool convert(Type t)
Casts the variant to the requested type, t.
Definition: qvariant.cpp:2959
bool testFunction()
Definition: qcssparser_p.h:804
QString sourcePath
Definition: qcssparser_p.h:833
bool parseHexColor(QColor *col)
TokenType lookup() const
Definition: qcssparser_p.h:821
QString lexem() const
Definition: qcssparser_p.h:817
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60

◆ prev()

void QCss::Parser::prev ( )
inline

Definition at line 815 of file qcssparser_p.h.

815 { index--; }

◆ recordError()

bool QCss::Parser::recordError ( )
inline

Definition at line 827 of file qcssparser_p.h.

827 { errorIndex = index; return false; }

◆ skipSpace()

void QCss::Parser::skipSpace ( )
inline

Definition at line 809 of file qcssparser_p.h.

Referenced by parseBrushValue().

809 { while (test(S)) {}; }
bool test(TokenType t)

◆ symbol()

const Symbol& QCss::Parser::symbol ( ) const
inline

Definition at line 816 of file qcssparser_p.h.

816 { return symbols.at(index - 1); }
QVector< Symbol > symbols
Definition: qcssparser_p.h:829

◆ test()

bool Parser::test ( QCss::TokenType  t)

Definition at line 2688 of file qcssparser.cpp.

2689 {
2690  if (index >= symbols.count())
2691  return false;
2692  if (symbols.at(index).token == t) {
2693  ++index;
2694  return true;
2695  }
2696  return false;
2697 }
QVector< Symbol > symbols
Definition: qcssparser_p.h:829

◆ testAndParseUri()

bool Parser::testAndParseUri ( QString uri)

Definition at line 2653 of file qcssparser.cpp.

2654 {
2655  const int rewind = index;
2656  if (!testFunction()) return false;
2657 
2658  QString name, args;
2659  if (!parseFunction(&name, &args)) {
2660  index = rewind;
2661  return false;
2662  }
2663  if (name.toLower() != QLatin1String("url")) {
2664  index = rewind;
2665  return false;
2666  }
2667  *uri = args;
2668  removeOptionalQuotes(uri);
2669  return true;
2670 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void removeOptionalQuotes(QString *str)
bool parseFunction(QString *name, QString *args)
const char * name
#define rewind(a)
bool testFunction()
Definition: qcssparser_p.h:804
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389

◆ testAttrib()

bool QCss::Parser::testAttrib ( )
inline

Definition at line 789 of file qcssparser_p.h.

789 { return test(LBRACKET); }
bool test(TokenType t)

◆ testClass()

bool QCss::Parser::testClass ( )
inline

Definition at line 788 of file qcssparser_p.h.

788 { return test(DOT); }
bool test(TokenType t)

◆ testCombinator()

bool QCss::Parser::testCombinator ( )
inline

Definition at line 797 of file qcssparser_p.h.

797 { return test(PLUS) || test(GREATER) || test(S); }
bool test(TokenType t)

◆ testElementName()

bool QCss::Parser::testElementName ( )
inline

Definition at line 787 of file qcssparser_p.h.

787 { return test(IDENT) || test(STAR); }
bool test(TokenType t)

◆ testExpr()

bool QCss::Parser::testExpr ( )
inline

Definition at line 800 of file qcssparser_p.h.

800 { return testTerm(); }

◆ testFunction()

bool QCss::Parser::testFunction ( )
inline

Definition at line 804 of file qcssparser_p.h.

804 { return test(FUNCTION); }
bool test(TokenType t)

◆ testHexColor()

bool QCss::Parser::testHexColor ( )
inline

Definition at line 803 of file qcssparser_p.h.

803 { return test(HASH); }
bool test(TokenType t)

◆ testImport()

bool QCss::Parser::testImport ( )
inline

Definition at line 794 of file qcssparser_p.h.

794 { return testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1String("import")); }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool testTokenAndEndsWith(TokenType t, const QLatin1String &str)

◆ testMedia()

bool QCss::Parser::testMedia ( )
inline

Definition at line 795 of file qcssparser_p.h.

795 { return testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1String("media")); }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool testTokenAndEndsWith(TokenType t, const QLatin1String &str)

◆ testMedium()

bool QCss::Parser::testMedium ( )
inline

Definition at line 791 of file qcssparser_p.h.

791 { return test(IDENT); }
bool test(TokenType t)

◆ testPage()

bool QCss::Parser::testPage ( )
inline

Definition at line 796 of file qcssparser_p.h.

QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool testTokenAndEndsWith(TokenType t, const QLatin1String &str)

◆ testPrio()

bool Parser::testPrio ( )

Definition at line 2492 of file qcssparser.cpp.

2493 {
2494  const int rewind = index;
2495  if (!test(EXCLAMATION_SYM)) return false;
2496  skipSpace();
2497  if (!test(IDENT)) {
2498  index = rewind;
2499  return false;
2500  }
2501  if (lexem().compare(QLatin1String("important"), Qt::CaseInsensitive) != 0) {
2502  index = rewind;
2503  return false;
2504  }
2505  return true;
2506 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void skipSpace()
Definition: qcssparser_p.h:809
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
Compares a to b.
Definition: qvariant.cpp:383
#define rewind(a)
QString lexem() const
Definition: qcssparser_p.h:817
bool test(TokenType t)

◆ testProperty()

bool QCss::Parser::testProperty ( )
inline

Definition at line 798 of file qcssparser_p.h.

798 { return test(IDENT); }
bool test(TokenType t)

◆ testPseudo()

bool QCss::Parser::testPseudo ( )
inline

Definition at line 790 of file qcssparser_p.h.

790 { return test(COLON); }
bool test(TokenType t)

◆ testPseudoPage()

bool QCss::Parser::testPseudoPage ( )
inline

Definition at line 793 of file qcssparser_p.h.

793 { return test(COLON); }
bool test(TokenType t)

◆ testRuleset()

bool QCss::Parser::testRuleset ( )
inline

Definition at line 782 of file qcssparser_p.h.

782 { return testSelector(); }
bool testSelector()
Definition: qcssparser_p.h:783

◆ testSelector()

bool QCss::Parser::testSelector ( )
inline

Definition at line 783 of file qcssparser_p.h.

783 { return testSimpleSelector(); }
bool testSimpleSelector()

◆ testSimpleSelector()

bool Parser::testSimpleSelector ( )

Definition at line 2672 of file qcssparser.cpp.

2673 {
2674  return testElementName()
2675  || (test(HASH))
2676  || testClass()
2677  || testAttrib()
2678  || testPseudo();
2679 }
bool testElementName()
Definition: qcssparser_p.h:787
bool testClass()
Definition: qcssparser_p.h:788
bool testAttrib()
Definition: qcssparser_p.h:789
bool testPseudo()
Definition: qcssparser_p.h:790
bool test(TokenType t)

◆ testTerm()

bool Parser::testTerm ( )

Definition at line 2537 of file qcssparser.cpp.

2538 {
2539  return test(PLUS) || test(MINUS)
2540  || test(NUMBER)
2541  || test(PERCENTAGE)
2542  || test(LENGTH)
2543  || test(STRING)
2544  || test(IDENT)
2545  || testHexColor()
2546  || testFunction();
2547 }
bool testHexColor()
Definition: qcssparser_p.h:803
bool testFunction()
Definition: qcssparser_p.h:804
bool test(TokenType t)

◆ testTokenAndEndsWith()

bool Parser::testTokenAndEndsWith ( QCss::TokenType  t,
const QLatin1String str 
)

Definition at line 2757 of file qcssparser.cpp.

2758 {
2759  if (!test(t)) return false;
2760  if (!lexem().endsWith(str, Qt::CaseInsensitive)) {
2761  prev();
2762  return false;
2763  }
2764  return true;
2765 }
QString lexem() const
Definition: qcssparser_p.h:817
bool test(TokenType t)

◆ unquotedLexem()

QString Parser::unquotedLexem ( ) const

Definition at line 2699 of file qcssparser.cpp.

2700 {
2701  QString s = lexem();
2702  if (lookup() == STRING) {
2703  s.chop(1);
2704  s.remove(0, 1);
2705  }
2706  return s;
2707 }
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
The QString class provides a Unicode character string.
Definition: qstring.h:83
TokenType lookup() const
Definition: qcssparser_p.h:821
QString lexem() const
Definition: qcssparser_p.h:817
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867

◆ until()

bool Parser::until ( QCss::TokenType  target,
QCss::TokenType  target2 = NONE 
)

Definition at line 2717 of file qcssparser.cpp.

2718 {
2719  int braceCount = 0;
2720  int brackCount = 0;
2721  int parenCount = 0;
2722  if (index) {
2723  switch(symbols.at(index-1).token) {
2724  case LBRACE: ++braceCount; break;
2725  case LBRACKET: ++brackCount; break;
2726  case FUNCTION:
2727  case LPAREN: ++parenCount; break;
2728  default: ;
2729  }
2730  }
2731  while (index < symbols.size()) {
2732  QCss::TokenType t = symbols.at(index++).token;
2733  switch (t) {
2734  case LBRACE: ++braceCount; break;
2735  case RBRACE: --braceCount; break;
2736  case LBRACKET: ++brackCount; break;
2737  case RBRACKET: --brackCount; break;
2738  case FUNCTION:
2739  case LPAREN: ++parenCount; break;
2740  case RPAREN: --parenCount; break;
2741  default: break;
2742  }
2743  if ((t == target || (target2 != NONE && t == target2))
2744  && braceCount <= 0
2745  && brackCount <= 0
2746  && parenCount <= 0)
2747  return true;
2748 
2749  if (braceCount < 0 || brackCount < 0 || parenCount < 0) {
2750  --index;
2751  break;
2752  }
2753  }
2754  return false;
2755 }
QVector< Symbol > symbols
Definition: qcssparser_p.h:829

Properties

◆ errorIndex

int QCss::Parser::errorIndex

Definition at line 831 of file qcssparser_p.h.

◆ hasEscapeSequences

bool QCss::Parser::hasEscapeSequences

Definition at line 832 of file qcssparser_p.h.

◆ index

int QCss::Parser::index

Definition at line 830 of file qcssparser_p.h.

◆ sourcePath

QString QCss::Parser::sourcePath

Definition at line 833 of file qcssparser_p.h.

◆ symbols

QVector<Symbol> QCss::Parser::symbols

Definition at line 829 of file qcssparser_p.h.


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