summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cssparser.cc46
-rw-r--r--src/cssparser.hh1
2 files changed, 30 insertions, 17 deletions
diff --git a/src/cssparser.cc b/src/cssparser.cc
index 1b575aec..5782925a 100644
--- a/src/cssparser.cc
+++ b/src/cssparser.cc
@@ -410,6 +410,28 @@ void CssParser::ungetChar()
bufptr--;
}
+/*
+ * Skip string str if it is found in the input buffer.
+ * If not wind back. The first char is passed as parameter c
+ * to avoid unnecessary getChar() / ungetChar() calls.
+ */
+inline bool CssParser::skipString(int c, const char *str)
+{
+ int n = 0;
+
+ while (str[n]) {
+ if (str[n] != c) {
+ while (n--)
+ ungetChar();
+ return false;
+ }
+ c = getChar();
+ n++;
+ }
+
+ return true;
+}
+
void CssParser::nextToken()
{
int c, c1, d, j;
@@ -419,26 +441,16 @@ void CssParser::nextToken()
ttype = CSS_TK_CHAR; /* init */
spaceSeparated = false;
- c = getChar();
-
while (true) {
- if (isspace(c)) { // ignore whitespace
+ c = getChar();
+ if (isspace(c)) { // ignore whitespace
spaceSeparated = true;
- c = getChar();
- } else if (c == '/') { // ignore comments
- d = getChar();
- if (d == '*') {
- c = getChar();
- d = getChar();
- while (d != EOF && (c != '*' || d != '/')) {
- c = d;
- d = getChar();
- }
+ } else if (skipString(c, "/*")) { // ignore comments
+ do {
c = getChar();
- } else {
- ungetChar();
- break;
- }
+ } while (! skipString(c, "*/"));
+ } else if (skipString(c, "<!--")) { // ignore XML comment markers
+ } else if (skipString(c, "-->")) {
} else {
break;
}
diff --git a/src/cssparser.hh b/src/cssparser.hh
index d6e54ec7..1e471c68 100644
--- a/src/cssparser.hh
+++ b/src/cssparser.hh
@@ -28,6 +28,7 @@ class CssParser {
int getChar();
void ungetChar();
void nextToken();
+ bool skipString(int c, const char *string);
bool tokenMatchesProperty(CssPropertyName prop, CssValueType * type);
bool parseValue(CssPropertyName prop, CssValueType type,
CssPropertyValue * val);