From f68785a65aed9ce40d9aec5fbf7f9cec3af1b384 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 15 Mar 2009 21:15:08 +0100 Subject: replace a_Css_parse(), a_Css_parse_declaration() with static methods --- src/css.cc | 4 ++-- src/cssparser.cc | 61 ++++++++++-------------------------------------------- src/cssparser.hh | 47 +++++++++++++++++++++++++++++++++++------ src/styleengine.cc | 5 +++-- 4 files changed, 57 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/css.cc b/src/css.cc index 94bb5716..627f221d 100644 --- a/src/css.cc +++ b/src/css.cc @@ -481,7 +481,7 @@ void CssContext::buildUserAgentStyle () { "th {font-weight: bolder; text-align: center}" "code, tt, pre, samp, kbd {font-family: monospace}"; - a_Css_parse (this, cssBuf, strlen (cssBuf), CSS_ORIGIN_USER_AGENT); + CssParser::parse (this, cssBuf, strlen (cssBuf), CSS_ORIGIN_USER_AGENT); } void CssContext::buildUserStyle () { @@ -489,7 +489,7 @@ void CssContext::buildUserStyle () { char *filename = dStrconcat(dGethomedir(), "/.dillo/style.css", NULL); if ((style = a_Misc_file2dstr(filename))) { - a_Css_parse (this, style->str, style->len, CSS_ORIGIN_USER); + CssParser::parse (this, style->str, style->len, CSS_ORIGIN_USER); dStr_free (style, 1); } dFree (filename); diff --git a/src/cssparser.cc b/src/cssparser.cc index f2bde324..349e4ce6 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -36,9 +36,6 @@ using namespace dw::core::style; #define DEBUG_LEVEL 10 -/* Applies to symbol lengths and string literals. */ -#define MAX_STR_LEN 256 - /* The last three ones are never parsed. */ #define CSS_NUM_INTERNAL_PROPERTIES 3 #define CSS_NUM_PARSED_PROPERTIES \ @@ -354,40 +351,6 @@ static const CssShorthandInfo Css_shorthand_info[] = { * Parsing * ---------------------------------------------------------------------- */ -typedef enum { - CSS_TK_DECINT, CSS_TK_FLOAT, CSS_TK_COLOR, CSS_TK_SYMBOL, CSS_TK_STRING, - CSS_TK_CHAR, CSS_TK_END -} CssTokenType; - -class CssParser { - public: - CssContext *context; - CssOrigin origin; - - const char *buf; - int buflen, bufptr; - - CssTokenType ttype; - char tval[MAX_STR_LEN]; - bool within_block; - bool space_separated; /* used when parsing CSS selectors */ - - CssParser(CssContext *context, CssOrigin origin, - const char *buf, int buflen); - int getc(); - void ungetc(); - void nextToken(); - bool tokenMatchesProperty(CssPropertyName prop, CssValueType * type); - bool parseValue(CssPropertyName prop, CssValueType type, - CssPropertyValue * val); - bool parseWeight(); - void parseDeclaration(CssPropertyList * props, - CssPropertyList * importantProps); - bool parseSimpleSelector(CssSimpleSelector *selector); - CssSelector *parseSelector(); - void parseRuleset(); -}; - CssParser::CssParser(CssContext *context, CssOrigin origin, const char *buf, int buflen) { @@ -463,7 +426,7 @@ void CssParser::nextToken() // handle negative numbers if (c == '-') { - if (i < MAX_STR_LEN - 1) + if (i < CSS_MAX_STR_LEN - 1) tval[i++] = c; c = getc(); } @@ -471,7 +434,7 @@ void CssParser::nextToken() if (isdigit(c)) { ttype = CSS_TK_DECINT; do { - if (i < MAX_STR_LEN - 1) { + if (i < CSS_MAX_STR_LEN - 1) { tval[i++] = c; } /* else silently truncated */ @@ -487,10 +450,10 @@ void CssParser::nextToken() c = getc(); if (isdigit(c)) { ttype = CSS_TK_FLOAT; - if (i < MAX_STR_LEN - 1) + if (i < CSS_MAX_STR_LEN - 1) tval[i++] = '.'; do { - if (i < MAX_STR_LEN - 1) + if (i < CSS_MAX_STR_LEN - 1) tval[i++] = c; /* else silently truncated */ c = getc(); @@ -529,7 +492,7 @@ void CssParser::nextToken() i = 1; c = getc(); while (isalnum(c) || c == '_' || c == '-') { - if (i < MAX_STR_LEN - 1) { + if (i < CSS_MAX_STR_LEN - 1) { tval[i] = c; i++; } /* else silently truncated */ @@ -571,7 +534,7 @@ void CssParser::nextToken() } } - if (i < MAX_STR_LEN - 1) { + if (i < CSS_MAX_STR_LEN - 1) { tval[i] = c; i++; } /* else silently truncated */ @@ -593,7 +556,7 @@ void CssParser::nextToken() i = 1; c = getc(); while (isxdigit(c)) { - if (i < MAX_STR_LEN - 1) { + if (i < CSS_MAX_STR_LEN - 1) { tval[i] = c; i++; } /* else silently truncated */ @@ -1227,19 +1190,17 @@ void CssParser::parseRuleset() nextToken(); } -void a_Css_parse(CssContext * context, - const char *buf, - int buflen, CssOrigin origin) +void CssParser::parse(CssContext * context, + const char *buf, + int buflen, CssOrigin origin) { CssParser parser (context, origin, buf, buflen); - parser.within_block = false; - while (parser.ttype != CSS_TK_END) parser.parseRuleset(); } -CssPropertyList *a_Css_parse_declaration(const char *buf, int buflen) +CssPropertyList *CssParser::parseDeclarationBlock(const char *buf, int buflen) { CssPropertyList *props = new CssPropertyList (true); CssParser parser (NULL, CSS_ORIGIN_AUTHOR, buf, buflen); diff --git a/src/cssparser.hh b/src/cssparser.hh index bfeca95d..4802510d 100644 --- a/src/cssparser.hh +++ b/src/cssparser.hh @@ -9,13 +9,48 @@ typedef struct { const char *const *enum_symbols; } CssPropertyInfo; -void a_Css_parse (CssContext *context, - const char *buf, - int buflen, - CssOrigin origin); +extern const CssPropertyInfo Css_property_info[CSS_PROPERTY_LAST]; -CssPropertyList *a_Css_parse_declaration(const char *buf, int buflen); +typedef enum { + CSS_TK_DECINT, CSS_TK_FLOAT, CSS_TK_COLOR, CSS_TK_SYMBOL, CSS_TK_STRING, + CSS_TK_CHAR, CSS_TK_END +} CssTokenType; -extern const CssPropertyInfo Css_property_info[CSS_PROPERTY_LAST]; +/* Applies to symbol lengths and string literals. */ +#define CSS_MAX_STR_LEN 256 + +class CssParser { + private: + CssContext *context; + CssOrigin origin; + + const char *buf; + int buflen, bufptr; + + CssTokenType ttype; + char tval[CSS_MAX_STR_LEN]; + bool within_block; + bool space_separated; /* used when parsing CSS selectors */ + + CssParser(CssContext *context, CssOrigin origin, + const char *buf, int buflen); + int getc(); + void ungetc(); + void nextToken(); + bool tokenMatchesProperty(CssPropertyName prop, CssValueType * type); + bool parseValue(CssPropertyName prop, CssValueType type, + CssPropertyValue * val); + bool parseWeight(); + void parseDeclaration(CssPropertyList * props, + CssPropertyList * importantProps); + bool parseSimpleSelector(CssSimpleSelector *selector); + CssSelector *parseSelector(); + void parseRuleset(); + + public: + static CssPropertyList *parseDeclarationBlock(const char *buf, int buflen); + static void parse(CssContext *context, const char *buf, int buflen, + CssOrigin origin); +}; #endif diff --git a/src/styleengine.cc b/src/styleengine.cc index bc13e36a..51e304e9 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -523,7 +523,8 @@ Style * StyleEngine::style0 (CssPropertyList *nonCssProperties) { // parse style information from style="" attribute, if it exists if (styleAttribute && prefs.parse_embedded_css) styleAttributeProps = - a_Css_parse_declaration (styleAttribute, strlen (styleAttribute)); + CssParser::parseDeclarationBlock (styleAttribute, + strlen (styleAttribute)); // merge style information cssContext->apply (&props, this, styleAttributeProps, nonCssProperties); @@ -553,5 +554,5 @@ Style * StyleEngine::wordStyle0 (CssPropertyList *nonCssProperties) { } void StyleEngine::parse (const char *buf, int buflen, CssOrigin origin) { - a_Css_parse (cssContext, buf, buflen, origin); + CssParser::parse (cssContext, buf, buflen, origin); } -- cgit v1.2.3