diff options
Diffstat (limited to 'src/parse/properties')
-rw-r--r-- | src/parse/properties/generated_list.c | 176 | ||||
-rw-r--r-- | src/parse/properties/properties.c | 158 |
2 files changed, 170 insertions, 164 deletions
diff --git a/src/parse/properties/generated_list.c b/src/parse/properties/generated_list.c index bebb5c5..4adfdbc 100644 --- a/src/parse/properties/generated_list.c +++ b/src/parse/properties/generated_list.c @@ -585,6 +585,164 @@ css_error parse_list_style_type(css_language *c, return CSS_OK; } +css_error parse_quotes(css_language *c, + const parserutils_vector *vector, int *ctx, + css_style **result) +{ + css_error error; + const css_token *token; + uint8_t flags = 0; + uint16_t value = 0; + uint32_t opv; + uint32_t required_size = sizeof(opv); + int temp_ctx = *ctx; + uint8_t *ptr; + + /* [ STRING STRING ]+ | IDENT(none,inherit) */ + + /* Pass 1: validate input and calculate bytecode size */ + token = parserutils_vector_iterate(vector, &temp_ctx); + if (token == NULL || (token->type != CSS_TOKEN_IDENT && + token->type != CSS_TOKEN_STRING)) + return CSS_INVALID; + + if (token->type == CSS_TOKEN_IDENT) { + if (token->ilower == c->strings[INHERIT]) { + flags = FLAG_INHERIT; + } else if (token->ilower == c->strings[NONE]) { + value = QUOTES_NONE; + } else + return CSS_INVALID; + } else { + bool first = true; + + /* [ STRING STRING ] + */ + while (token != NULL && token->type == CSS_TOKEN_STRING) { + lwc_string *open = token->idata; + lwc_string *close; + + consumeWhitespace(vector, &temp_ctx); + + token = parserutils_vector_peek(vector, temp_ctx); + if (token == NULL || token->type != CSS_TOKEN_STRING) + return CSS_INVALID; + + close = token->idata; + + token = parserutils_vector_iterate(vector, &temp_ctx); + + consumeWhitespace(vector, &temp_ctx); + + if (first == false) { + required_size += sizeof(opv); + } else { + value = QUOTES_STRING; + } + required_size += sizeof(open) + sizeof(close); + + first = false; + + token = parserutils_vector_peek(vector, temp_ctx); + if (token == NULL || token->type != CSS_TOKEN_STRING) + break; + token = parserutils_vector_iterate(vector, &temp_ctx); + } + + consumeWhitespace(vector, &temp_ctx); + + token = parserutils_vector_peek(vector, temp_ctx); + if (token != NULL && tokenIsChar(token, '!') == false) + return CSS_INVALID; + + /* Terminator */ + required_size += sizeof(opv); + } + + error = parse_important(c, vector, &temp_ctx, &flags); + if (error != CSS_OK) + return error; + + opv = buildOPV(CSS_PROP_QUOTES, flags, value); + + /* Allocate result */ + error = css_stylesheet_style_create(c->sheet, required_size, result); + if (error != CSS_OK) + return error; + + /* Copy OPV to bytecode */ + ptr = (*result)->bytecode; + memcpy(ptr, &opv, sizeof(opv)); + ptr += sizeof(opv); + + /* Pass 2: construct bytecode */ + token = parserutils_vector_iterate(vector, ctx); + if (token == NULL || (token->type != CSS_TOKEN_IDENT && + token->type != CSS_TOKEN_STRING)) + return CSS_INVALID; + + if (token->type == CSS_TOKEN_IDENT) { + /* Nothing to do */ + } else { + bool first = true; + + /* [ STRING STRING ]+ */ + while (token != NULL && token->type == CSS_TOKEN_STRING) { + lwc_string *open = token->idata; + lwc_string *close; + + consumeWhitespace(vector, ctx); + + token = parserutils_vector_peek(vector, *ctx); + if (token == NULL || token->type != CSS_TOKEN_STRING) + return CSS_INVALID; + + close = token->idata; + + token = parserutils_vector_iterate(vector, ctx); + + consumeWhitespace(vector, ctx); + + if (first == false) { + opv = QUOTES_STRING; + memcpy(ptr, &opv, sizeof(opv)); + ptr += sizeof(opv); + } + + lwc_context_string_ref(c->sheet->dictionary, open); + memcpy(ptr, &open, sizeof(open)); + ptr += sizeof(open); + + lwc_context_string_ref(c->sheet->dictionary, close); + memcpy(ptr, &close, sizeof(close)); + ptr += sizeof(close); + + first = false; + + token = parserutils_vector_peek(vector, *ctx); + if (token == NULL || token->type != CSS_TOKEN_STRING) + break; + token = parserutils_vector_iterate(vector, ctx); + } + + consumeWhitespace(vector, ctx); + + token = parserutils_vector_peek(vector, *ctx); + if (token != NULL && tokenIsChar(token, '!') == false) + return CSS_INVALID; + + /* Terminator */ + opv = QUOTES_NONE; + memcpy(ptr, &opv, sizeof(opv)); + ptr += sizeof(opv); + } + + error = parse_important(c, vector, ctx, &flags); + if (error != CSS_OK) + return error; + + return CSS_OK; +} + css_error parse_list_style_type_value(css_language *c, const css_token *ident, uint16_t *value) { @@ -713,7 +871,8 @@ css_error parse_content_list(css_language *c, } if (buffer != NULL) { - lwc_context_string_ref(c->sheet->dictionary, token->idata); + lwc_context_string_ref(c->sheet->dictionary, + token->idata); memcpy(buffer + offset, &token->idata, sizeof(token->idata)); } @@ -732,7 +891,8 @@ css_error parse_content_list(css_language *c, } if (buffer != NULL) { - lwc_context_string_ref(c->sheet->dictionary, token->idata); + lwc_context_string_ref(c->sheet->dictionary, + token->idata); memcpy(buffer + offset, &token->idata, sizeof(token->idata)); } @@ -759,7 +919,8 @@ css_error parse_content_list(css_language *c, return CSS_INVALID; if (buffer != NULL) { - lwc_context_string_ref(c->sheet->dictionary, token->idata); + lwc_context_string_ref(c->sheet->dictionary, + token->idata); memcpy(buffer + offset, &token->idata, sizeof(token->idata)); } @@ -839,7 +1000,8 @@ css_error parse_content_list(css_language *c, } if (buffer != NULL) { - lwc_context_string_ref(c->sheet->dictionary, name); + lwc_context_string_ref(c->sheet->dictionary, + name); memcpy(buffer + offset, &name, sizeof(name)); } @@ -928,14 +1090,16 @@ css_error parse_content_list(css_language *c, } if (buffer != NULL) { - lwc_context_string_ref(c->sheet->dictionary, name); + lwc_context_string_ref(c->sheet->dictionary, + name); memcpy(buffer + offset, &name, sizeof(name)); } offset += sizeof(name); if (buffer != NULL) { - lwc_context_string_ref(c->sheet->dictionary, sep); + lwc_context_string_ref(c->sheet->dictionary, + sep); memcpy(buffer + offset, &sep, sizeof(sep)); } diff --git a/src/parse/properties/properties.c b/src/parse/properties/properties.c index 345377c..ccb2b64 100644 --- a/src/parse/properties/properties.c +++ b/src/parse/properties/properties.c @@ -1379,164 +1379,6 @@ css_error parse_overflow(css_language *c, return CSS_OK; } -css_error parse_quotes(css_language *c, - const parserutils_vector *vector, int *ctx, - css_style **result) -{ - css_error error; - const css_token *token; - uint8_t flags = 0; - uint16_t value = 0; - uint32_t opv; - uint32_t required_size = sizeof(opv); - int temp_ctx = *ctx; - uint8_t *ptr; - - /* [ STRING STRING ]+ | IDENT(none,inherit) */ - - /* Pass 1: validate input and calculate bytecode size */ - token = parserutils_vector_iterate(vector, &temp_ctx); - if (token == NULL || (token->type != CSS_TOKEN_IDENT && - token->type != CSS_TOKEN_STRING)) - return CSS_INVALID; - - if (token->type == CSS_TOKEN_IDENT) { - if (token->ilower == c->strings[INHERIT]) { - flags = FLAG_INHERIT; - } else if (token->ilower == c->strings[NONE]) { - value = QUOTES_NONE; - } else - return CSS_INVALID; - } else { - bool first = true; - - /* [ STRING STRING ] + */ - while (token != NULL && token->type == CSS_TOKEN_STRING) { - lwc_string *open = token->idata; - lwc_string *close; - - consumeWhitespace(vector, &temp_ctx); - - token = parserutils_vector_peek(vector, temp_ctx); - if (token == NULL || token->type != CSS_TOKEN_STRING) - return CSS_INVALID; - - close = token->idata; - - token = parserutils_vector_iterate(vector, &temp_ctx); - - consumeWhitespace(vector, &temp_ctx); - - if (first == false) { - required_size += sizeof(opv); - } else { - value = QUOTES_STRING; - } - required_size += sizeof(open) + sizeof(close); - - first = false; - - token = parserutils_vector_peek(vector, temp_ctx); - if (token == NULL || token->type != CSS_TOKEN_STRING) - break; - token = parserutils_vector_iterate(vector, &temp_ctx); - } - - consumeWhitespace(vector, &temp_ctx); - - token = parserutils_vector_peek(vector, temp_ctx); - if (token != NULL && tokenIsChar(token, '!') == false) - return CSS_INVALID; - - /* Terminator */ - required_size += sizeof(opv); - } - - error = parse_important(c, vector, &temp_ctx, &flags); - if (error != CSS_OK) - return error; - - opv = buildOPV(CSS_PROP_QUOTES, flags, value); - - /* Allocate result */ - error = css_stylesheet_style_create(c->sheet, required_size, result); - if (error != CSS_OK) - return error; - - /* Copy OPV to bytecode */ - ptr = (*result)->bytecode; - memcpy(ptr, &opv, sizeof(opv)); - ptr += sizeof(opv); - - /* Pass 2: construct bytecode */ - token = parserutils_vector_iterate(vector, ctx); - if (token == NULL || (token->type != CSS_TOKEN_IDENT && - token->type != CSS_TOKEN_STRING)) - return CSS_INVALID; - - if (token->type == CSS_TOKEN_IDENT) { - /* Nothing to do */ - } else { - bool first = true; - - /* [ STRING STRING ]+ */ - while (token != NULL && token->type == CSS_TOKEN_STRING) { - lwc_string *open = token->idata; - lwc_string *close; - - consumeWhitespace(vector, ctx); - - token = parserutils_vector_peek(vector, *ctx); - if (token == NULL || token->type != CSS_TOKEN_STRING) - return CSS_INVALID; - - close = token->idata; - - token = parserutils_vector_iterate(vector, ctx); - - consumeWhitespace(vector, ctx); - - if (first == false) { - opv = QUOTES_STRING; - memcpy(ptr, &opv, sizeof(opv)); - ptr += sizeof(opv); - } - - lwc_context_string_ref(c->sheet->dictionary, open); - memcpy(ptr, &open, sizeof(open)); - ptr += sizeof(open); - - lwc_context_string_ref(c->sheet->dictionary, close); - memcpy(ptr, &close, sizeof(close)); - ptr += sizeof(close); - - first = false; - - token = parserutils_vector_peek(vector, *ctx); - if (token == NULL || token->type != CSS_TOKEN_STRING) - break; - token = parserutils_vector_iterate(vector, ctx); - } - - consumeWhitespace(vector, ctx); - - token = parserutils_vector_peek(vector, *ctx); - if (token != NULL && tokenIsChar(token, '!') == false) - return CSS_INVALID; - - /* Terminator */ - opv = QUOTES_NONE; - memcpy(ptr, &opv, sizeof(opv)); - ptr += sizeof(opv); - } - - error = parse_important(c, vector, ctx, &flags); - if (error != CSS_OK) - return error; - - return CSS_OK; -} - css_error parse_table_layout(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) |