changeset 1006:40fbc9a0ca34

replace a_Css_parse(), a_Css_parse_declaration() with static methods
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Sun, 15 Mar 2009 21:15:08 +0100
parents b50debc823bb
children 0604a13c629a
files src/css.cc src/cssparser.cc src/cssparser.hh src/styleengine.cc
diffstat 4 files changed, 58 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.cc	Sun Mar 15 20:48:44 2009 +0100
+++ b/src/css.cc	Sun Mar 15 21:15:08 2009 +0100
@@ -481,7 +481,7 @@
      "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 @@
    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);
--- a/src/cssparser.cc	Sun Mar 15 20:48:44 2009 +0100
+++ b/src/cssparser.cc	Sun Mar 15 21:15:08 2009 +0100
@@ -36,9 +36,6 @@
 
 #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 @@
  *    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 @@
 
    // 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 @@
    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 @@
       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 @@
       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 @@
             }
          }
 
-         if (i < MAX_STR_LEN - 1) {
+         if (i < CSS_MAX_STR_LEN - 1) {
             tval[i] = c;
             i++;
          }                      /* else silently truncated */
@@ -593,7 +556,7 @@
       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 @@
       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);
--- a/src/cssparser.hh	Sun Mar 15 20:48:44 2009 +0100
+++ b/src/cssparser.hh	Sun Mar 15 21:15:08 2009 +0100
@@ -9,13 +9,48 @@
    const char *const *enum_symbols;
 } CssPropertyInfo;
 
-void        a_Css_parse                       (CssContext *context,
-                                               const char *buf,
-                                               int buflen,
-                                               CssOrigin origin);
-
-CssPropertyList *a_Css_parse_declaration(const char *buf, int buflen);
-
 extern const CssPropertyInfo Css_property_info[CSS_PROPERTY_LAST];
 
+typedef enum {
+   CSS_TK_DECINT, CSS_TK_FLOAT, CSS_TK_COLOR, CSS_TK_SYMBOL, CSS_TK_STRING,
+   CSS_TK_CHAR, CSS_TK_END
+} CssTokenType;
+
+/* 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
--- a/src/styleengine.cc	Sun Mar 15 20:48:44 2009 +0100
+++ b/src/styleengine.cc	Sun Mar 15 21:15:08 2009 +0100
@@ -523,7 +523,8 @@
    // 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 @@
 }
 
 void StyleEngine::parse (const char *buf, int buflen, CssOrigin origin) {
-   a_Css_parse (cssContext, buf, buflen, origin);
+   CssParser::parse (cssContext, buf, buflen, origin);
 }