diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2008-10-23 00:28:20 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2008-10-23 00:28:20 +0000 |
commit | c8e73871f9006987983fd1010d97b6168c13f6a3 (patch) | |
tree | 2fb79379af6643828fb93bd6c855a6e0a5e6dc7b /src/parse/css21props.c | |
parent | 5d9507591d83b48be8c76421b602500c196e3785 (diff) | |
download | libcss-c8e73871f9006987983fd1010d97b6168c13f6a3.tar.gz libcss-c8e73871f9006987983fd1010d97b6168c13f6a3.tar.bz2 |
Something approximating a parser for clear.
Provide API to create/destroy css_styles and append them to css_rules.
svn path=/trunk/libcss/; revision=5625
Diffstat (limited to 'src/parse/css21props.c')
-rw-r--r-- | src/parse/css21props.c | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/src/parse/css21props.c b/src/parse/css21props.c index 24c9ba1..c47ef99 100644 --- a/src/parse/css21props.c +++ b/src/parse/css21props.c @@ -690,10 +690,64 @@ css_error parse_clear(css_css21 *c, const parserutils_vector *vector, int *ctx, css_style **result) { - UNUSED(c); - UNUSED(vector); - UNUSED(ctx); - UNUSED(result); + const css_token *token, *ident; + uint8_t flags = 0; + uint16_t value = 0; + uint32_t opv; + + /* IDENT (left, right, both, none, inherit) */ + ident = parserutils_vector_iterate(vector, ctx); + if (ident == NULL || ident->type != CSS_TOKEN_IDENT) + return CSS_INVALID; + + /** \todo break this !important stuff into a utility function */ + consumeWhitespace(vector, ctx); + + token = parserutils_vector_iterate(vector, ctx); + if (token != NULL && tokenIsChar(token, '!')) { + consumeWhitespace(vector, ctx); + + token = parserutils_vector_iterate(vector, ctx); + if (token == NULL || token->type != CSS_TOKEN_IDENT) + return CSS_INVALID; + + /** \todo compare pointer to interned version. */ + if (token->lower.len == 9 && + strncmp((char *) token->lower.ptr, + "important", 9) == 0) + flags |= FLAG_IMPORTANT; + } else if (token != NULL) + return CSS_INVALID; + + + /** \todo ugh. compare pointers to interned versions, already */ + if (ident->lower.len == 7 && + strncmp((char *) ident->lower.ptr, "inherit", 7) == 0) { + flags |= FLAG_INHERIT; + } else if (ident->lower.len == 5 && + strncmp((char *) ident->lower.ptr, "right", 5) == 0) { + value = CLEAR_RIGHT; + } else if (ident->lower.len == 4 && + strncmp((char *) ident->lower.ptr, "left", 4) == 0) { + value = CLEAR_LEFT; + } else if (ident->lower.len == 4 && + strncmp((char *) ident->lower.ptr, "both", 4) == 0) { + value = CLEAR_BOTH; + } else if (ident->lower.len == 4 && + strncmp((char *) ident->lower.ptr, "none", 4) == 0) { + value = CLEAR_NONE; + } else + return CSS_INVALID; + + opv = buildOPV(OP_CLEAR, flags, value); + + /* Allocate result */ + *result = css_stylesheet_style_create(c->sheet, sizeof(opv)); + if (*result == NULL) + return CSS_NOMEM; + + /* Copy the bytecode to it */ + memcpy((*result)->bytecode, &opv, sizeof(opv)); return CSS_OK; } |