summaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/language.c23
-rw-r--r--src/parse/parse.c241
-rw-r--r--src/parse/parse.h8
-rw-r--r--src/parse/properties.c327
4 files changed, 276 insertions, 323 deletions
diff --git a/src/parse/language.c b/src/parse/language.c
index 11fe972..cff66df 100644
--- a/src/parse/language.c
+++ b/src/parse/language.c
@@ -41,7 +41,7 @@ struct css_language {
/** \todo These should be statically allocated */
/** Interned strings */
- const parserutils_hash_entry *strings[LAST_KNOWN];
+ lwc_string *strings[LAST_KNOWN];
css_allocator_fn alloc; /**< Memory (de)allocation function */
void *pw; /**< Client's private data */
@@ -127,6 +127,7 @@ css_error css_language_create(css_stylesheet *sheet, css_parser *parser,
css_language *c;
css_parser_optparams params;
parserutils_error perror;
+ lwc_error lerror;
css_error error;
if (sheet == NULL || parser == NULL || alloc == NULL ||
@@ -147,10 +148,11 @@ css_error css_language_create(css_stylesheet *sheet, css_parser *parser,
/* Intern all known strings */
for (int i = 0; i < LAST_KNOWN; i++) {
- c->strings[i] = css_parser_dict_add(parser,
- (const uint8_t *) stringmap[i].data,
- stringmap[i].len);
- if (c->strings[i] == NULL) {
+ lerror = lwc_context_intern(sheet->dictionary,
+ stringmap[i].data,
+ stringmap[i].len,
+ &(c->strings[i]));
+ if (lerror != lwc_error_ok) {
parserutils_stack_destroy(c->context);
alloc(c, 0, pw);
return CSS_NOMEM;
@@ -184,11 +186,18 @@ css_error css_language_create(css_stylesheet *sheet, css_parser *parser,
*/
css_error css_language_destroy(css_language *language)
{
+ int i;
+
if (language == NULL)
return CSS_BADPARM;
parserutils_stack_destroy(language->context);
-
+
+ for (i = 0; i < LAST_KNOWN; ++i) {
+ lwc_context_string_unref(language->sheet->dictionary,
+ language->strings[i]);
+ }
+
language->alloc(language, 0, language->pw);
return CSS_OK;
@@ -1107,7 +1116,7 @@ void consumeWhitespace(const parserutils_vector *vector, int *ctx)
bool tokenIsChar(const css_token *token, uint8_t c)
{
return token != NULL && token->type == CSS_TOKEN_CHAR &&
- token->ilower->len == 1 && token->ilower->data[0] == c;
+ lwc_string_length(token->ilower) == 1 && lwc_string_data(token->ilower)[0] == c;
}
diff --git a/src/parse/parse.c b/src/parse/parse.c
index c1b8143..50bd362 100644
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -9,8 +9,9 @@
#include <ctype.h>
#include <stdbool.h>
+#include <libwapcaplet/libwapcaplet.h>
+
#include <parserutils/input/inputstream.h>
-#include <parserutils/utils/hash.h>
#include <parserutils/utils/stack.h>
#include <parserutils/utils/vector.h>
@@ -91,7 +92,7 @@ struct css_parser
#define STACK_CHUNK 32
parserutils_stack *states; /**< Stack of states */
- parserutils_hash *dictionary; /**< Dictionary for interned strings */
+ lwc_context *dictionary; /**< Dictionary for interned strings */
parserutils_vector *tokens; /**< Vector of pending tokens */
@@ -187,7 +188,7 @@ static css_error (*parseFuncs[])(css_parser *parser) = {
* CSS_NOMEM on memory exhaustion
*/
css_error css_parser_create(const char *charset, css_charset_source cs_source,
- parserutils_hash *dictionary, css_allocator_fn alloc, void *pw,
+ lwc_context *dictionary, css_allocator_fn alloc, void *pw,
css_parser **parser)
{
css_parser *p;
@@ -412,31 +413,6 @@ const char *css_parser_read_charset(css_parser *parser,
return parserutils_inputstream_read_charset(parser->stream, source);
}
-/**
- * Add an entry to the parser dictionary
- *
- * \param parser The parser instance
- * \param data Pointer to data
- * \param len Length, in bytes, of data
- * \return Pointer to data in dictionary, or NULL on memory exhaustion
- */
-const parserutils_hash_entry *css_parser_dict_add(css_parser *parser,
- const uint8_t *data, size_t len)
-{
- const parserutils_hash_entry *interned;
- parserutils_error perror;
-
- if (parser == NULL || data == NULL || len == 0)
- return NULL;
-
- perror = parserutils_hash_insert(parser->dictionary, data, len,
- &interned);
- if (perror != PARSERUTILS_OK)
- return NULL;
-
- return interned;
-}
-
/******************************************************************************
* Helper functions *
******************************************************************************/
@@ -558,6 +534,7 @@ css_error expect(css_parser *parser, css_token_type type)
css_error getToken(css_parser *parser, const css_token **token)
{
parserutils_error perror;
+ lwc_error lerror;
css_error error;
/* Use pushback, if it exists */
@@ -609,27 +586,25 @@ css_error getToken(css_parser *parser, const css_token **token)
if (lower == true) {
/* Insert lowercase version */
- perror = parserutils_hash_insert(
- parser->dictionary,
- temp, t->data.len,
- &t->ilower);
- if (perror != PARSERUTILS_OK) {
- return css_error_from_parserutils_error(
- perror);
- }
+ lerror = lwc_context_intern(parser->dictionary,
+ (char *)temp,
+ t->data.len,
+ &t->ilower);
+ if (lerror != lwc_error_ok)
+ return css_error_from_lwc_error(lerror);
}
}
/* Insert token text into the dictionary */
- perror = parserutils_hash_insert(parser->dictionary,
- t->data.data, t->data.len,
- &t->idata);
-
+ lerror = lwc_context_intern(parser->dictionary,
+ (char *)t->data.data,
+ t->data.len, &t->idata);
+
if (t->ilower == NULL)
t->ilower = t->idata;
- if (perror != PARSERUTILS_OK)
- return css_error_from_parserutils_error(perror);
+ if (lerror != lwc_error_ok)
+ return css_error_from_lwc_error(lerror);
} else {
t->idata = t->ilower = NULL;
}
@@ -855,8 +830,8 @@ css_error parseRuleset(css_parser *parser)
/* The grammar's ambiguous here -- selectors may start with a
* brace. We're going to assume that that won't happen,
* however. */
- if (token->type == CSS_TOKEN_CHAR && token->ilower->len == 1 &&
- token->ilower->data[0] == '{') {
+ if (token->type == CSS_TOKEN_CHAR && lwc_string_length(token->ilower) == 1 &&
+ lwc_string_data(token->ilower)[0] == '{') {
#if !defined(NDEBUG) && defined(DEBUG_EVENTS)
printf("Begin ruleset\n");
#endif
@@ -906,8 +881,8 @@ css_error parseRuleset(css_parser *parser)
if (error != CSS_OK)
return error;
- if (token->type != CSS_TOKEN_CHAR || token->ilower->len != 1 ||
- token->ilower->data[0] != '{') {
+ if (token->type != CSS_TOKEN_CHAR || lwc_string_length(token->ilower) != 1 ||
+ lwc_string_data(token->ilower)[0] != '{') {
/* This should never happen, as FOLLOW(selector)
* contains only '{' */
assert(0 && "Expected {");
@@ -954,9 +929,9 @@ css_error parseRulesetEnd(css_parser *parser)
* attempt to parse a declaration. This will catch any invalid
* input at this point and read to the start of the next
* declaration. FIRST(decl-list) = (';', '}') */
- if (token->type != CSS_TOKEN_CHAR || token->ilower->len != 1 ||
- (token->ilower->data[0] != '}' &&
- token->ilower->data[0] != ';')) {
+ if (token->type != CSS_TOKEN_CHAR || lwc_string_length(token->ilower) != 1 ||
+ (lwc_string_data(token->ilower)[0] != '}' &&
+ lwc_string_data(token->ilower)[0] != ';')) {
parser_state to = { sDeclaration, Initial };
parser_state subsequent = { sRulesetEnd, DeclList };
@@ -980,8 +955,8 @@ css_error parseRulesetEnd(css_parser *parser)
if (token->type == CSS_TOKEN_EOF)
break;
- if (token->type != CSS_TOKEN_CHAR || token->ilower->len != 1 ||
- token->ilower->data[0] != '}') {
+ if (token->type != CSS_TOKEN_CHAR || lwc_string_length(token->ilower) != 1 ||
+ lwc_string_data(token->ilower)[0] != '}') {
/* This should never happen, as FOLLOW(decl-list)
* contains only '}' */
assert(0 && "Expected }");
@@ -1055,9 +1030,9 @@ css_error parseAtRule(css_parser *parser)
/* Grammar ambiguity: any0 can be followed by '{',';',')',']'.
* at-rule can only be followed by '{' and ';'. */
- if (token->type == CSS_TOKEN_CHAR && token->ilower->len == 1) {
- if (token->ilower->data[0] == ')' ||
- token->ilower->data[0] == ']') {
+ if (token->type == CSS_TOKEN_CHAR && lwc_string_length(token->ilower) == 1) {
+ if (lwc_string_data(token->ilower)[0] == ')' ||
+ lwc_string_data(token->ilower)[0] == ']') {
parser_state to = { sAny0, Initial };
parser_state subsequent = { sAtRule, AfterAny };
@@ -1108,12 +1083,12 @@ css_error parseAtRuleEnd(css_parser *parser)
if (error != CSS_OK)
return error;
- if (token->type != CSS_TOKEN_CHAR || token->ilower->len != 1) {
+ if (token->type != CSS_TOKEN_CHAR || lwc_string_length(token->ilower) != 1) {
/* Should never happen FOLLOW(at-rule) == '{', ';'*/
assert(0 && "Expected { or ;");
}
- if (token->ilower->data[0] == '{') {
+ if (lwc_string_data(token->ilower)[0] == '{') {
parser_state to = { sBlock, Initial };
parser_state subsequent = { sAtRuleEnd, AfterBlock };
@@ -1122,7 +1097,7 @@ css_error parseAtRuleEnd(css_parser *parser)
return error;
return transition(parser, to, subsequent);
- } else if (token->ilower->data[0] != ';') {
+ } else if (lwc_string_data(token->ilower)[0] != ';') {
/* Again, should never happen */
assert(0 && "Expected ;");
}
@@ -1174,8 +1149,8 @@ css_error parseBlock(css_parser *parser)
parserutils_vector_clear(parser->tokens);
- if (token->type != CSS_TOKEN_CHAR || token->ilower->len != 1 ||
- token->ilower->data[0] != '{') {
+ if (token->type != CSS_TOKEN_CHAR || lwc_string_length(token->ilower) != 1 ||
+ lwc_string_data(token->ilower)[0] != '{') {
/* This should never happen, as FIRST(block) == '{' */
assert(0 && "Expected {");
}
@@ -1204,8 +1179,8 @@ css_error parseBlock(css_parser *parser)
if (token->type == CSS_TOKEN_EOF)
break;
- if (token->type != CSS_TOKEN_CHAR || token->ilower->len != 1 ||
- token->ilower->data[0] != '}') {
+ if (token->type != CSS_TOKEN_CHAR || lwc_string_length(token->ilower) != 1 ||
+ lwc_string_data(token->ilower)[0] != '}') {
/* This should never happen, as
* FOLLOW(block-content) == '}' */
assert(0 && "Expected }");
@@ -1257,8 +1232,8 @@ css_error parseBlockContent(css_parser *parser)
if (token->type == CSS_TOKEN_ATKEYWORD) {
state->substate = WS;
} else if (token->type == CSS_TOKEN_CHAR) {
- if (token->ilower->len == 1 &&
- token->ilower->data[0] == '{') {
+ if (lwc_string_length(token->ilower) == 1 &&
+ lwc_string_data(token->ilower)[0] == '{') {
/* Grammar ambiguity. Assume block */
parser_state to = { sBlock, Initial };
parser_state subsequent =
@@ -1281,12 +1256,12 @@ css_error parseBlockContent(css_parser *parser)
return transition(parser, to,
subsequent);
- } else if (token->ilower->len == 1 &&
- token->ilower->data[0] == ';') {
+ } else if (lwc_string_length(token->ilower) == 1 &&
+ lwc_string_data(token->ilower)[0] == ';') {
/* Grammar ambiguity. Assume semi */
state->substate = WS;
- } else if (token->ilower->len == 1 &&
- token->ilower->data[0] == '}') {
+ } else if (lwc_string_length(token->ilower) == 1 &&
+ lwc_string_data(token->ilower)[0] == '}') {
/* Grammar ambiguity. Assume end */
error = pushBack(parser, token);
if (error != CSS_OK)
@@ -1402,8 +1377,8 @@ css_error parseDeclaration(css_parser *parser)
if (error != CSS_OK)
return error;
- if (token->type != CSS_TOKEN_CHAR || token->ilower->len != 1 ||
- token->ilower->data[0] != ':') {
+ if (token->type != CSS_TOKEN_CHAR || lwc_string_length(token->ilower) != 1 ||
+ lwc_string_data(token->ilower)[0] != ':') {
/* parse error -- expected : */
parser_state to = { sMalformedDecl, Initial };
@@ -1469,14 +1444,14 @@ css_error parseDeclList(css_parser *parser)
if (token->type == CSS_TOKEN_EOF)
return done(parser);
- if (token->type != CSS_TOKEN_CHAR || token->ilower->len != 1 ||
- (token->ilower->data[0] != '}' &&
- token->ilower->data[0] != ';')) {
+ if (token->type != CSS_TOKEN_CHAR || lwc_string_length(token->ilower) != 1 ||
+ (lwc_string_data(token->ilower)[0] != '}' &&
+ lwc_string_data(token->ilower)[0] != ';')) {
/* Should never happen */
assert(0 && "Expected ; or }");
}
- if (token->ilower->data[0] == '}') {
+ if (lwc_string_data(token->ilower)[0] == '}') {
error = pushBack(parser, token);
if (error != CSS_OK)
return error;
@@ -1519,9 +1494,9 @@ css_error parseDeclListEnd(css_parser *parser)
return error;
if (token->type != CSS_TOKEN_CHAR ||
- token->ilower->len != 1 ||
- (token->ilower->data[0] != ';' &&
- token->ilower->data[0] != '}')) {
+ lwc_string_length(token->ilower) != 1 ||
+ (lwc_string_data(token->ilower)[0] != ';' &&
+ lwc_string_data(token->ilower)[0] != '}')) {
parser_state to = { sDeclaration, Initial };
parser_state subsequent =
{ sDeclListEnd, AfterDeclaration };
@@ -1608,9 +1583,9 @@ css_error parseValue1(css_parser *parser)
/* Grammar ambiguity -- assume ';' or '}' mark end */
if (token->type == CSS_TOKEN_CHAR &&
- token->ilower->len == 1 &&
- (token->ilower->data[0] == ';' ||
- token->ilower->data[0] == '}')) {
+ lwc_string_length(token->ilower) == 1 &&
+ (lwc_string_data(token->ilower)[0] == ';' ||
+ lwc_string_data(token->ilower)[0] == '}')) {
/* Parse error */
parser->parseError = true;
@@ -1661,9 +1636,9 @@ css_error parseValue0(css_parser *parser)
/* Grammar ambiguity -- assume ';' or '}' mark end */
if (token->type == CSS_TOKEN_CHAR &&
- token->ilower->len == 1 &&
- (token->ilower->data[0] == ';' ||
- token->ilower->data[0] == '}')) {
+ lwc_string_length(token->ilower) == 1 &&
+ (lwc_string_data(token->ilower)[0] == ';' ||
+ lwc_string_data(token->ilower)[0] == '}')) {
return done(parser);
}
@@ -1703,8 +1678,8 @@ css_error parseValue(css_parser *parser)
if (token->type == CSS_TOKEN_ATKEYWORD) {
state->substate = WS;
} else if (token->type == CSS_TOKEN_CHAR &&
- token->ilower->len == 1 &&
- token->ilower->data[0] == '{') {
+ lwc_string_length(token->ilower) == 1 &&
+ lwc_string_data(token->ilower)[0] == '{') {
/* Grammar ambiguity. Assume block. */
parser_state to = { sBlock, Initial };
@@ -1767,11 +1742,11 @@ css_error parseAny0(css_parser *parser)
/* Grammar ambiguity:
* assume '{', ';', ')', ']' mark end */
if (token->type == CSS_TOKEN_CHAR &&
- token->ilower->len == 1 &&
- (token->ilower->data[0] == '{' ||
- token->ilower->data[0] == ';' ||
- token->ilower->data[0] == ')' ||
- token->ilower->data[0] == ']')) {
+ lwc_string_length(token->ilower) == 1 &&
+ (lwc_string_data(token->ilower)[0] == '{' ||
+ lwc_string_data(token->ilower)[0] == ';' ||
+ lwc_string_data(token->ilower)[0] == ')' ||
+ lwc_string_data(token->ilower)[0] == ']')) {
return done(parser);
}
@@ -1831,15 +1806,15 @@ css_error parseAny1(css_parser *parser)
/* Grammar ambiguity: any0 can be followed by
* '{', ';', ')', ']'. any1 can only be followed by '{'. */
- if (token->type == CSS_TOKEN_CHAR && token->ilower->len == 1) {
- if (token->ilower->data[0] == ';' ||
- token->ilower->data[0] == ')' ||
- token->ilower->data[0] == ']') {
+ if (token->type == CSS_TOKEN_CHAR && lwc_string_length(token->ilower) == 1) {
+ if (lwc_string_data(token->ilower)[0] == ';' ||
+ lwc_string_data(token->ilower)[0] == ')' ||
+ lwc_string_data(token->ilower)[0] == ']') {
parser_state to = { sAny, Initial };
parser_state subsequent = { sAny1, AfterAny };
return transition(parser, to, subsequent);
- } else if (token->ilower->data[0] != '{') {
+ } else if (lwc_string_data(token->ilower)[0] != '{') {
/* parse error */
parser->parseError = true;
}
@@ -1909,11 +1884,11 @@ css_error parseAny(css_parser *parser)
parser->match_char = ')';
state->substate = WS;
} else if (token->type == CSS_TOKEN_CHAR &&
- token->ilower->len == 1 &&
- (token->ilower->data[0] == '(' ||
- token->ilower->data[0] == '[')) {
+ lwc_string_length(token->ilower) == 1 &&
+ (lwc_string_data(token->ilower)[0] == '(' ||
+ lwc_string_data(token->ilower)[0] == '[')) {
parser->match_char =
- token->ilower->data[0] == '(' ? ')' : ']';
+ lwc_string_data(token->ilower)[0] == '(' ? ')' : ']';
state->substate = WS;
}
@@ -1945,8 +1920,8 @@ css_error parseAny(css_parser *parser)
return error;
/* Match correct close bracket (grammar ambiguity) */
- if (token->type == CSS_TOKEN_CHAR && token->ilower->len == 1 &&
- token->ilower->data[0] == parser->match_char) {
+ if (token->type == CSS_TOKEN_CHAR && lwc_string_length(token->ilower) == 1 &&
+ lwc_string_data(token->ilower)[0] == parser->match_char) {
state->substate = WS2;
goto ws2;
}
@@ -1989,14 +1964,14 @@ css_error parseMalformedDeclaration(css_parser *parser)
break;
if (token->type != CSS_TOKEN_CHAR ||
- token->ilower->len != 1 ||
- (token->ilower->data[0] != '{' &&
- token->ilower->data[0] != '}' &&
- token->ilower->data[0] != '[' &&
- token->ilower->data[0] != ']' &&
- token->ilower->data[0] != '(' &&
- token->ilower->data[0] != ')' &&
- token->ilower->data[0] != ';'))
+ lwc_string_length(token->ilower) != 1 ||
+ (lwc_string_data(token->ilower)[0] != '{' &&
+ lwc_string_data(token->ilower)[0] != '}' &&
+ lwc_string_data(token->ilower)[0] != '[' &&
+ lwc_string_data(token->ilower)[0] != ']' &&
+ lwc_string_data(token->ilower)[0] != '(' &&
+ lwc_string_data(token->ilower)[0] != ')' &&
+ lwc_string_data(token->ilower)[0] != ';'))
continue;
char want;
@@ -2006,17 +1981,17 @@ css_error parseMalformedDeclaration(css_parser *parser)
/* If the stack is empty, then we're done if we've got
* either a ';' or '}' */
if (match == NULL) {
- if (token->ilower->data[0] == ';' ||
- token->ilower->data[0] == '}')
+ if (lwc_string_data(token->ilower)[0] == ';' ||
+ lwc_string_data(token->ilower)[0] == '}')
break;
}
/* Regardless, if we've got a semicolon, ignore it */
- if (token->ilower->data[0] == ';')
+ if (lwc_string_data(token->ilower)[0] == ';')
continue;
/* Get corresponding start tokens for end tokens */
- switch (token->ilower->data[0]) {
+ switch (lwc_string_data(token->ilower)[0]) {
case '}':
want = '{';
break;
@@ -2038,7 +2013,7 @@ css_error parseMalformedDeclaration(css_parser *parser)
parser->open_items, NULL);
} else if (want == 0) {
parserutils_stack_push(parser->open_items,
- &token->ilower->data[0]);
+ &lwc_string_data(token->ilower)[0]);
}
}
}
@@ -2083,13 +2058,13 @@ css_error parseMalformedSelector(css_parser *parser)
break;
if (token->type != CSS_TOKEN_CHAR ||
- token->ilower->len != 1 ||
- (token->ilower->data[0] != '{' &&
- token->ilower->data[0] != '}' &&
- token->ilower->data[0] != '[' &&
- token->ilower->data[0] != ']' &&
- token->ilower->data[0] != '(' &&
- token->ilower->data[0] != ')'))
+ lwc_string_length(token->ilower) != 1 ||
+ (lwc_string_data(token->ilower)[0] != '{' &&
+ lwc_string_data(token->ilower)[0] != '}' &&
+ lwc_string_data(token->ilower)[0] != '[' &&
+ lwc_string_data(token->ilower)[0] != ']' &&
+ lwc_string_data(token->ilower)[0] != '(' &&
+ lwc_string_data(token->ilower)[0] != ')'))
continue;
char want;
@@ -2097,7 +2072,7 @@ css_error parseMalformedSelector(css_parser *parser)
parser->open_items);
/* Get corresponding start tokens for end tokens */
- switch (token->ilower->data[0]) {
+ switch (lwc_string_data(token->ilower)[0]) {
case '}':
want = '{';
break;
@@ -2119,7 +2094,7 @@ css_error parseMalformedSelector(css_parser *parser)
parser->open_items, NULL);
} else if (want == 0) {
parserutils_stack_push(parser->open_items,
- &token->ilower->data[0]);
+ &lwc_string_data(token->ilower)[0]);
}
/* If we encountered a '}', there was data on the stack
@@ -2176,14 +2151,14 @@ css_error parseMalformedAtRule(css_parser *parser)
break;
if (token->type != CSS_TOKEN_CHAR ||
- token->ilower->len != 1 ||
- (token->ilower->data[0] != '{' &&
- token->ilower->data[0] != '}' &&
- token->ilower->data[0] != '[' &&
- token->ilower->data[0] != ']' &&
- token->ilower->data[0] != '(' &&
- token->ilower->data[0] != ')' &&
- token->ilower->data[0] != ';'))
+ lwc_string_length(token->ilower) != 1 ||
+ (lwc_string_data(token->ilower)[0] != '{' &&
+ lwc_string_data(token->ilower)[0] != '}' &&
+ lwc_string_data(token->ilower)[0] != '[' &&
+ lwc_string_data(token->ilower)[0] != ']' &&
+ lwc_string_data(token->ilower)[0] != '(' &&
+ lwc_string_data(token->ilower)[0] != ')' &&
+ lwc_string_data(token->ilower)[0] != ';'))
continue;
char want;
@@ -2192,7 +2167,7 @@ css_error parseMalformedAtRule(css_parser *parser)
/* If we have a semicolon, then we're either done or
* need to ignore it */
- if (token->ilower->data[0] == ';') {
+ if (lwc_string_data(token->ilower)[0] == ';') {
if (match == NULL)
break;
else
@@ -2200,7 +2175,7 @@ css_error parseMalformedAtRule(css_parser *parser)
}
/* Get corresponding start tokens for end tokens */
- switch (token->ilower->data[0]) {
+ switch (lwc_string_data(token->ilower)[0]) {
case '}':
want = '{';
break;
@@ -2222,7 +2197,7 @@ css_error parseMalformedAtRule(css_parser *parser)
parser->open_items, NULL);
} else if (want == 0) {
parserutils_stack_push(parser->open_items,
- &token->ilower->data[0]);
+ &lwc_string_data(token->ilower)[0]);
}
/* If we encountered a '}', there was data on the stack
diff --git a/src/parse/parse.h b/src/parse/parse.h
index 5dc1b18..bb6229f 100644
--- a/src/parse/parse.h
+++ b/src/parse/parse.h
@@ -8,7 +8,8 @@
#ifndef css_parse_parse_h_
#define css_parse_parse_h_
-#include <parserutils/utils/hash.h>
+#include <libwapcaplet/libwapcaplet.h>
+
#include <parserutils/utils/vector.h>
#include <libcss/errors.h>
@@ -57,7 +58,7 @@ typedef union css_parser_optparams {
} css_parser_optparams;
css_error css_parser_create(const char *charset, css_charset_source cs_source,
- parserutils_hash *dict, css_allocator_fn alloc, void *pw,
+ lwc_context *dict, css_allocator_fn alloc, void *pw,
css_parser **parser);
css_error css_parser_destroy(css_parser *parser);
@@ -71,8 +72,5 @@ css_error css_parser_completed(css_parser *parser);
const char *css_parser_read_charset(css_parser *parser,
css_charset_source *source);
-const parserutils_hash_entry *css_parser_dict_add(css_parser *parser,
- const uint8_t *ptr, size_t len);
-
#endif
diff --git a/src/parse/properties.c b/src/parse/properties.c
index b0905a8..bd1a6a4 100644
--- a/src/parse/properties.c
+++ b/src/parse/properties.c
@@ -751,7 +751,7 @@ css_error parse_background_image(css_language *c,
required_size = sizeof(opv);
if ((flags & FLAG_INHERIT) == false && value == BACKGROUND_IMAGE_URI)
- required_size += sizeof(parserutils_hash_entry *);
+ required_size += sizeof(lwc_string *);
/* Allocate result */
error = css_stylesheet_style_create(c->sheet, required_size, result);
@@ -763,7 +763,7 @@ css_error parse_background_image(css_language *c,
if ((flags & FLAG_INHERIT) == false && value == BACKGROUND_IMAGE_URI) {
memcpy((uint8_t *) (*result)->bytecode + sizeof(opv),
&token->idata,
- sizeof(parserutils_hash_entry *));
+ sizeof(lwc_string *));
}
return CSS_OK;
@@ -1652,7 +1652,7 @@ css_error parse_counter_increment(css_language *c,
value = COUNTER_INCREMENT_NAMED;
while (token != NULL) {
- const parserutils_hash_entry *name = token->idata;
+ lwc_string *name = token->idata;
css_fixed increment = INTTOFIX(1);
consumeWhitespace(vector, &temp_ctx);
@@ -1664,14 +1664,12 @@ css_error parse_counter_increment(css_language *c,
return CSS_INVALID;
if (token != NULL && token->type == CSS_TOKEN_NUMBER) {
- const css_string temp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
size_t consumed = 0;
- increment = number_from_css_string(&temp,
+ increment = number_from_lwc_string(token->ilower,
true, &consumed);
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
parserutils_vector_iterate(vector, &temp_ctx);
@@ -1730,7 +1728,7 @@ css_error parse_counter_increment(css_language *c,
opv = COUNTER_INCREMENT_NAMED;
while (token != NULL) {
- const parserutils_hash_entry *name = token->idata;
+ lwc_string *name = token->idata;
css_fixed increment = INTTOFIX(1);
consumeWhitespace(vector, ctx);
@@ -1742,14 +1740,12 @@ css_error parse_counter_increment(css_language *c,
return CSS_INVALID;
if (token != NULL && token->type == CSS_TOKEN_NUMBER) {
- const css_string temp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
size_t consumed = 0;
- increment = number_from_css_string(&temp,
+ increment = number_from_lwc_string(token->ilower,
true, &consumed);
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
parserutils_vector_iterate(vector, ctx);
@@ -1821,7 +1817,7 @@ css_error parse_counter_reset(css_language *c,
value = COUNTER_RESET_NAMED;
while (token != NULL) {
- const parserutils_hash_entry *name = token->idata;
+ lwc_string *name = token->idata;
css_fixed increment = INTTOFIX(0);
consumeWhitespace(vector, &temp_ctx);
@@ -1833,14 +1829,12 @@ css_error parse_counter_reset(css_language *c,
return CSS_INVALID;
if (token != NULL && token->type == CSS_TOKEN_NUMBER) {
- const css_string temp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
size_t consumed = 0;
- increment = number_from_css_string(&temp,
+ increment = number_from_lwc_string(token->ilower,
true, &consumed);
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
parserutils_vector_iterate(vector, &temp_ctx);
@@ -1899,7 +1893,7 @@ css_error parse_counter_reset(css_language *c,
opv = COUNTER_RESET_NAMED;
while (token != NULL) {
- const parserutils_hash_entry *name = token->idata;
+ lwc_string *name = token->idata;
css_fixed increment = INTTOFIX(0);
consumeWhitespace(vector, ctx);
@@ -1911,14 +1905,12 @@ css_error parse_counter_reset(css_language *c,
return CSS_INVALID;
if (token != NULL && token->type == CSS_TOKEN_NUMBER) {
- const css_string temp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
size_t consumed = 0;
- increment = number_from_css_string(&temp,
+ increment = number_from_lwc_string(token->ilower,
true, &consumed);
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
parserutils_vector_iterate(vector, ctx);
@@ -1996,7 +1988,7 @@ css_error parse_cue_after(css_language *c,
required_size = sizeof(opv);
if ((flags & FLAG_INHERIT) == false && value == CUE_AFTER_URI)
- required_size += sizeof(parserutils_hash_entry *);
+ required_size += sizeof(lwc_string *);
/* Allocate result */
error = css_stylesheet_style_create(c->sheet, required_size, result);
@@ -2008,7 +2000,7 @@ css_error parse_cue_after(css_language *c,
if ((flags & FLAG_INHERIT) == false && value == CUE_AFTER_URI) {
memcpy((uint8_t *) (*result)->bytecode + sizeof(opv),
&token->idata,
- sizeof(parserutils_hash_entry *));
+ sizeof(lwc_string *));
}
return CSS_OK;
@@ -2050,7 +2042,7 @@ css_error parse_cue_before(css_language *c,
required_size = sizeof(opv);
if ((flags & FLAG_INHERIT) == false && value == CUE_BEFORE_URI)
- required_size += sizeof(parserutils_hash_entry *);
+ required_size += sizeof(lwc_string *);
/* Allocate result */
error = css_stylesheet_style_create(c->sheet, required_size, result);
@@ -2062,7 +2054,7 @@ css_error parse_cue_before(css_language *c,
if ((flags & FLAG_INHERIT) == false && value == CUE_BEFORE_URI) {
memcpy((uint8_t *) (*result)->bytecode + sizeof(opv),
&token->idata,
- sizeof(parserutils_hash_entry *));
+ sizeof(lwc_string *));
}
return CSS_OK;
@@ -2101,7 +2093,7 @@ css_error parse_cursor(css_language *c,
/* URI* */
while (token != NULL && token->type == CSS_TOKEN_URI) {
- const parserutils_hash_entry *uri = token->idata;
+ lwc_string *uri = token->idata;
if (first == false) {
required_size += sizeof(opv);
@@ -2244,7 +2236,7 @@ css_error parse_cursor(css_language *c,
/* URI* */
while (token != NULL && token->type == CSS_TOKEN_URI) {
- const parserutils_hash_entry *uri = token->idata;
+ lwc_string *uri = token->idata;
if (first == false) {
opv = CURSOR_URI;
@@ -2693,7 +2685,7 @@ css_error parse_font_family(css_language *c,
}
required_size +=
- sizeof(parserutils_hash_entry *);
+ sizeof(lwc_string *);
/* Skip past [ IDENT* S* ]* */
while (token != NULL) {
@@ -2729,7 +2721,7 @@ css_error parse_font_family(css_language *c,
}
required_size +=
- sizeof(parserutils_hash_entry *);
+ sizeof(lwc_string *);
} else {
return CSS_INVALID;
}
@@ -2798,8 +2790,8 @@ css_error parse_font_family(css_language *c,
while (token != NULL) {
if (token->type == CSS_TOKEN_IDENT) {
- const parserutils_hash_entry *name =
- token->idata;
+ lwc_string *name = token->idata;
+ lwc_string *newname;
if (token->ilower == c->strings[SERIF]) {
opv = FONT_FAMILY_SERIF;
@@ -2816,9 +2808,10 @@ css_error parse_font_family(css_language *c,
c->strings[MONOSPACE]) {
opv = FONT_FAMILY_MONOSPACE;
} else {
- uint16_t len = token->idata->len;
+ uint16_t len = lwc_string_length(token->idata);
const css_token *temp_token = token;
- parserutils_error perror;
+ lwc_error lerror;
+
temp_ctx = *ctx;
@@ -2838,7 +2831,7 @@ css_error parse_font_family(css_language *c,
if (temp_token->type ==
CSS_TOKEN_IDENT) {
- len += temp_token->idata->len;
+ len += lwc_string_length(temp_token->idata);
} else {
len += 1;
}
@@ -2850,8 +2843,8 @@ css_error parse_font_family(css_language *c,
uint8_t buf[len];
uint8_t *p = buf;
- memcpy(p, token->idata->data, token->idata->len);
- p += token->idata->len;
+ memcpy(p, lwc_string_data(token->idata), lwc_string_length(token->idata));
+ p += lwc_string_length(token->idata);
while (token != NULL) {
token = parserutils_vector_peek(
@@ -2867,9 +2860,9 @@ css_error parse_font_family(css_language *c,
if (token->type ==
CSS_TOKEN_IDENT) {
memcpy(p,
- token->idata->data,
- token->idata->len);
- p += token->idata->len;
+ lwc_string_data(token->idata),
+ lwc_string_length(token->idata));
+ p += lwc_string_length(token->idata);
} else {
*p++ = ' ';
}
@@ -2884,18 +2877,21 @@ css_error parse_font_family(css_language *c,
/* Insert into hash, if it's different
* from the name we already have */
- if (p - buf != name->len ||
- memcmp(buf, name->data,
- name->len) != 0) {
- perror = parserutils_hash_insert(
- c->sheet->dictionary,
- buf, len, &name);
- if (perror != PARSERUTILS_OK) {
- css_stylesheet_style_destroy(c->sheet, *result);
- *result = NULL;
- return css_error_from_parserutils_error(perror);
- }
- }
+
+ lerror = lwc_context_intern(c->sheet->dictionary,
+ (char *)buf, len, &newname);
+ if (lerror != lwc_error_ok) {
+ css_stylesheet_style_destroy(c->sheet, *result);
+ *result = NULL;
+ return css_error_from_lwc_error(lerror);
+ }
+
+ if (newname == name)
+ lwc_context_string_unref(c->sheet->dictionary,
+ newname);
+
+ name = newname;
+
}
if (first == false) {
@@ -3184,11 +3180,9 @@ css_error parse_font_weight(css_language *c,
flags |= FLAG_INHERIT;
} else if (token->type == CSS_TOKEN_NUMBER) {
size_t consumed = 0;
- css_string tmp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
- css_fixed num = number_from_css_string(&tmp, true, &consumed);
+ css_fixed num = number_from_lwc_string(token->ilower, true, &consumed);
/* Invalid if there are trailing characters */
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
switch (FIXTOINT(num)) {
case 100: value = FONT_WEIGHT_100; break;
@@ -3454,10 +3448,8 @@ css_error parse_line_height(css_language *c,
value = LINE_HEIGHT_NORMAL;
} else if (token->type == CSS_TOKEN_NUMBER) {
size_t consumed = 0;
- css_string tmp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
- length = number_from_css_string(&tmp, false, &consumed);
- if (consumed != token->ilower->len)
+ length = number_from_lwc_string(token->ilower, false, &consumed);
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
/* Negative values are illegal */
@@ -3549,7 +3541,7 @@ css_error parse_list_style_image(css_language *c,
required_size = sizeof(opv);
if ((flags & FLAG_INHERIT) == false && value == LIST_STYLE_IMAGE_URI)
- required_size += sizeof(parserutils_hash_entry *);
+ required_size += sizeof(lwc_string *);
/* Allocate result */
error = css_stylesheet_style_create(c->sheet, required_size, result);
@@ -3561,7 +3553,7 @@ css_error parse_list_style_image(css_language *c,
if ((flags & FLAG_INHERIT) == false && value == LIST_STYLE_IMAGE_URI) {
memcpy((uint8_t *) (*result)->bytecode + sizeof(opv),
&token->idata,
- sizeof(parserutils_hash_entry *));
+ sizeof(lwc_string *));
}
return CSS_OK;
@@ -3974,11 +3966,9 @@ css_error parse_orphans(css_language *c,
flags |= FLAG_INHERIT;
} else if (token->type == CSS_TOKEN_NUMBER) {
size_t consumed = 0;
- css_string tmp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
- num = number_from_css_string(&tmp, true, &consumed);
+ num = number_from_lwc_string(token->ilower, true, &consumed);
/* Invalid if there are trailing characters */
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
/* Negative values are nonsensical */
@@ -4466,11 +4456,9 @@ css_error parse_pitch_range(css_language *c,
flags |= FLAG_INHERIT;
} else if (token->type == CSS_TOKEN_NUMBER) {
size_t consumed = 0;
- css_string tmp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
- num = number_from_css_string(&tmp, false, &consumed);
+ num = number_from_lwc_string(token->ilower, false, &consumed);
/* Invalid if there are trailing characters */
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
/* Must be between 0 and 100 */
@@ -4597,7 +4585,7 @@ css_error parse_play_during(css_language *c,
uint16_t value = 0;
uint32_t opv;
uint32_t required_size;
- const parserutils_hash_entry *uri;
+ lwc_string *uri;
/* URI [ IDENT(mix) || IDENT(repeat) ]? | IDENT(auto,none,inherit) */
token = parserutils_vector_iterate(vector, ctx);
@@ -4653,7 +4641,7 @@ css_error parse_play_during(css_language *c,
required_size = sizeof(opv);
if ((flags & FLAG_INHERIT) == false &&
(value & PLAY_DURING_TYPE_MASK) == PLAY_DURING_URI)
- required_size += sizeof(parserutils_hash_entry *);
+ required_size += sizeof(lwc_string *);
/* Allocate result */
error = css_stylesheet_style_create(c->sheet, required_size, result);
@@ -4665,7 +4653,7 @@ css_error parse_play_during(css_language *c,
if ((flags & FLAG_INHERIT) == false &&
(value & PLAY_DURING_TYPE_MASK) == PLAY_DURING_URI) {
memcpy((uint8_t *) (*result)->bytecode + sizeof(opv),
- &uri, sizeof(parserutils_hash_entry *));
+ &uri, sizeof(lwc_string *));
}
return CSS_OK;
@@ -4749,8 +4737,8 @@ css_error parse_quotes(css_language *c,
/* [ STRING STRING ] + */
while (token != NULL && token->type == CSS_TOKEN_STRING) {
- const parserutils_hash_entry *open = token->idata;
- const parserutils_hash_entry *close;
+ lwc_string *open = token->idata;
+ lwc_string *close;
consumeWhitespace(vector, &temp_ctx);
@@ -4818,8 +4806,8 @@ css_error parse_quotes(css_language *c,
/* [ STRING STRING ]+ */
while (token != NULL && token->type == CSS_TOKEN_STRING) {
- const parserutils_hash_entry *open = token->idata;
- const parserutils_hash_entry *close;
+ lwc_string *open = token->idata;
+ lwc_string *close;
consumeWhitespace(vector, ctx);
@@ -4897,11 +4885,9 @@ css_error parse_richness(css_language *c,
flags |= FLAG_INHERIT;
} else if (token->type == CSS_TOKEN_NUMBER) {
size_t consumed = 0;
- css_string tmp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
- num = number_from_css_string(&tmp, false, &consumed);
+ num = number_from_lwc_string(token->ilower, false, &consumed);
/* Invalid if there are trailing characters */
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
/* Must be between 0 and 100 */
@@ -5214,11 +5200,9 @@ css_error parse_speech_rate(css_language *c,
value = SPEECH_RATE_SLOWER;
} else if (token->type == CSS_TOKEN_NUMBER) {
size_t consumed = 0;
- css_string tmp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
- num = number_from_css_string(&tmp, false, &consumed);
+ num = number_from_lwc_string(token->ilower, false, &consumed);
/* Invalid if there are trailing characters */
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
/* Make negative values invalid */
@@ -5276,11 +5260,9 @@ css_error parse_stress(css_language *c,
flags |= FLAG_INHERIT;
} else if (token->type == CSS_TOKEN_NUMBER) {
size_t consumed = 0;
- css_string tmp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
- num = number_from_css_string(&tmp, false, &consumed);
+ num = number_from_lwc_string(token->ilower, false, &consumed);
/* Invalid if there are trailing characters */
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
if (num < 0 || num > INTTOFIX(100))
@@ -5876,7 +5858,7 @@ css_error parse_voice_family(css_language *c,
}
required_size +=
- sizeof(parserutils_hash_entry *);
+ sizeof(lwc_string *);
/* Skip past [ IDENT* S* ]* */
while (token != NULL) {
@@ -5910,7 +5892,7 @@ css_error parse_voice_family(css_language *c,
}
required_size +=
- sizeof(parserutils_hash_entry *);
+ sizeof(lwc_string *);
} else {
return CSS_INVALID;
}
@@ -5979,8 +5961,8 @@ css_error parse_voice_family(css_language *c,
while (token != NULL) {
if (token->type == CSS_TOKEN_IDENT) {
- const parserutils_hash_entry *name =
- token->idata;
+ lwc_string *name = token->idata;
+ lwc_string *newname;
if (token->ilower == c->strings[MALE]) {
opv = VOICE_FAMILY_MALE;
@@ -5990,9 +5972,9 @@ css_error parse_voice_family(css_language *c,
} else if (token->ilower == c->strings[CHILD]) {
opv = VOICE_FAMILY_CHILD;
} else {
- uint16_t len = token->idata->len;
+ uint16_t len = lwc_string_length(token->idata);
const css_token *temp_token = token;
- parserutils_error perror;
+ lwc_error lerror;
temp_ctx = *ctx;
@@ -6011,7 +5993,7 @@ css_error parse_voice_family(css_language *c,
}
if (temp_token != NULL && temp_token->type == CSS_TOKEN_IDENT) {
- len += temp_token->idata->len;
+ len += lwc_string_length(temp_token->idata);
} else if (temp_token != NULL) {
len += 1;
}
@@ -6023,8 +6005,8 @@ css_error parse_voice_family(css_language *c,
uint8_t buf[len];
uint8_t *p = buf;
- memcpy(p, token->idata->data, token->idata->len);
- p += token->idata->len;
+ memcpy(p, lwc_string_data(token->idata), lwc_string_length(token->idata));
+ p += lwc_string_length(token->idata);
while (token != NULL) {
token = parserutils_vector_peek(
@@ -6041,9 +6023,9 @@ css_error parse_voice_family(css_language *c,
token->type ==
CSS_TOKEN_IDENT) {
memcpy(p,
- token->idata->data,
- token->idata->len);
- p += token->idata->len;
+ lwc_string_data(token->idata),
+ lwc_string_length(token->idata));
+ p += lwc_string_length(token->idata);
} else if (token != NULL) {
*p++ = ' ';
}
@@ -6058,19 +6040,20 @@ css_error parse_voice_family(css_language *c,
/* Insert into hash, if it's different
* from the name we already have */
- if (p - buf != name->len ||
- memcmp(buf, name->data,
- name->len) != 0) {
- perror = parserutils_hash_insert(
- c->sheet->dictionary,
- buf, len, &name);
- if (perror != PARSERUTILS_OK) {
- css_stylesheet_style_destroy(c->sheet, *result);
- *result = NULL;
- return css_error_from_parserutils_error(perror);
- }
- }
- }
+ lerror = lwc_context_intern(c->sheet->dictionary,
+ (char *)buf, len, &newname);
+ if (lerror != lwc_error_ok) {
+ css_stylesheet_style_destroy(c->sheet, *result);
+ *result = NULL;
+ return css_error_from_lwc_error(lerror);
+ }
+
+ if (newname == name)
+ lwc_context_string_unref(c->sheet->dictionary,
+ newname);
+
+ name = newname;
+ }
if (first == false) {
memcpy(ptr, &opv, sizeof(opv));
@@ -6197,10 +6180,8 @@ css_error parse_volume(css_language *c,
value = VOLUME_X_LOUD;
} else if (token->type == CSS_TOKEN_NUMBER) {
size_t consumed = 0;
- css_string tmp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
- length = number_from_css_string(&tmp, false, &consumed);
- if (consumed != token->ilower->len)
+ length = number_from_lwc_string(token->ilower, false, &consumed);
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
/* Must be between 0 and 100 */
@@ -6329,11 +6310,9 @@ css_error parse_widows(css_language *c,
flags |= FLAG_INHERIT;
} else if (token->type == CSS_TOKEN_NUMBER) {
size_t consumed = 0;
- css_string tmp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
- num = number_from_css_string(&tmp, true, &consumed);
+ num = number_from_lwc_string(token->ilower, true, &consumed);
/* Invalid if there are trailing characters */
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
/* Negative values are nonsensical */
@@ -6530,11 +6509,9 @@ css_error parse_z_index(css_language *c,
value = Z_INDEX_AUTO;
} else if (token->type == CSS_TOKEN_NUMBER) {
size_t consumed = 0;
- css_string tmp = { token->ilower->len,
- (uint8_t *) token->ilower->data };
- num = number_from_css_string(&tmp, true, &consumed);
+ num = number_from_lwc_string(token->ilower, true, &consumed);
/* Invalid if there are trailing characters */
- if (consumed != token->ilower->len)
+ if (consumed != lwc_string_length(token->ilower))
return CSS_INVALID;
value = Z_INDEX_SET;
@@ -6612,30 +6589,30 @@ css_error parse_colour_specifier(css_language *c,
if (token->type == CSS_TOKEN_IDENT) {
/** \todo Parse colour names */
} else if (token->type == CSS_TOKEN_HASH) {
- if (token->idata->len == 3 &&
- isHex(token->idata->data[0]) &&
- isHex(token->idata->data[1]) &&
- isHex(token->idata->data[2])) {
- r = charToHex(token->idata->data[0]);
- g = charToHex(token->idata->data[1]);
- b = charToHex(token->idata->data[2]);
+ if (lwc_string_length(token->idata) == 3 &&
+ isHex(lwc_string_data(token->idata)[0]) &&
+ isHex(lwc_string_data(token->idata)[1]) &&
+ isHex(lwc_string_data(token->idata)[2])) {
+ r = charToHex(lwc_string_data(token->idata)[0]);
+ g = charToHex(lwc_string_data(token->idata)[1]);
+ b = charToHex(lwc_string_data(token->idata)[2]);
r |= (r << 4);
g |= (g << 4);
b |= (b << 4);
- } else if (token->idata->len == 6 &&
- isHex(token->idata->data[0]) &&
- isHex(token->idata->data[1]) &&
- isHex(token->idata->data[2]) &&
- isHex(token->idata->data[3]) &&
- isHex(token->idata->data[4]) &&
- isHex(token->idata->data[5])) {
- r = (charToHex(token->idata->data[0]) << 4);
- r |= charToHex(token->idata->data[1]);
- g = (charToHex(token->idata->data[2]) << 4);
- g |= charToHex(token->idata->data[3]);
- b = (charToHex(token->idata->data[4]) << 4);
- b |= charToHex(token->idata->data[5]);
+ } else if (lwc_string_length(token->idata) == 6 &&
+ isHex(lwc_string_data(token->idata)[0]) &&
+ isHex(lwc_string_data(token->idata)[1]) &&
+ isHex(lwc_string_data(token->idata)[2]) &&
+ isHex(lwc_string_data(token->idata)[3]) &&
+ isHex(lwc_string_data(token->idata)[4]) &&
+ isHex(lwc_string_data(token->idata)[5])) {
+ r = (charToHex(lwc_string_data(token->idata)[0]) << 4);
+ r |= charToHex(lwc_string_data(token->idata)[1]);
+ g = (charToHex(lwc_string_data(token->idata)[2]) << 4);
+ g |= charToHex(lwc_string_data(token->idata)[3]);
+ b = (charToHex(lwc_string_data(token->idata)[4]) << 4);
+ b |= charToHex(lwc_string_data(token->idata)[5]);
} else
return CSS_INVALID;
} else if (token->type == CSS_TOKEN_FUNCTION) {
@@ -6643,7 +6620,6 @@ css_error parse_colour_specifier(css_language *c,
css_token_type valid = CSS_TOKEN_NUMBER;
for (int i = 0; i < 3; i++) {
- css_string tmp;
css_fixed num;
size_t consumed = 0;
uint8_t *component = i == 0 ? &r
@@ -6664,12 +6640,10 @@ css_error parse_colour_specifier(css_language *c,
else if (token->type != valid)
return CSS_INVALID;
- tmp.len = token->idata->len;
- tmp.data = (uint8_t *) token->idata->data;
- num = number_from_css_string(&tmp,
+ num = number_from_lwc_string(token->idata,
valid == CSS_TOKEN_NUMBER,
&consumed);
- if (consumed != token->idata->len)
+ if (consumed != lwc_string_length(token->idata))
return CSS_INVALID;
if (valid == CSS_TOKEN_NUMBER) {
@@ -6718,7 +6692,6 @@ css_error parse_unit_specifier(css_language *c,
const css_token *token;
css_fixed num;
size_t consumed = 0;
- css_string tmp;
UNUSED(c);
@@ -6730,64 +6703,62 @@ css_error parse_unit_specifier(css_language *c,
token->type != CSS_TOKEN_PERCENTAGE))
return CSS_INVALID;
- tmp.len = token->idata->len;
- tmp.data = (uint8_t *) token->idata->data;
- num = number_from_css_string(&tmp, false, &consumed);
+ num = number_from_lwc_string(token->idata, false, &consumed);
if (token->type == CSS_TOKEN_DIMENSION) {
- if (token->idata->len - consumed == 4) {
- if (strncasecmp((char *) token->idata->data + consumed,
+ if (lwc_string_length(token->idata) - consumed == 4) {
+ if (strncasecmp((char *) lwc_string_data(token->idata) + consumed,
"grad", 4) == 0)
*unit = UNIT_GRAD;
else
return CSS_INVALID;
- } else if (token->idata->len - consumed == 3) {
- if (strncasecmp((char *) token->idata->data + consumed,
+ } else if (lwc_string_length(token->idata) - consumed == 3) {
+ if (strncasecmp((char *) lwc_string_data(token->idata) + consumed,
"kHz", 3) == 0)
*unit = UNIT_KHZ;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "deg", 3) == 0)
*unit = UNIT_DEG;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "rad", 3) == 0)
*unit = UNIT_RAD;
else
return CSS_INVALID;
- } else if (token->idata->len - consumed == 2) {
- if (strncasecmp((char *) token->idata->data + consumed,
+ } else if (lwc_string_length(token->idata) - consumed == 2) {
+ if (strncasecmp((char *) lwc_string_data(token->idata) + consumed,
"Hz", 2) == 0)
*unit = UNIT_HZ;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "ms", 2) == 0)
*unit = UNIT_MS;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "px", 2) == 0)
*unit = UNIT_PX;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "ex", 2) == 0)
*unit = UNIT_EX;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "em", 2) == 0)
*unit = UNIT_EM;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "in", 2) == 0)
*unit = UNIT_IN;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "cm", 2) == 0)
*unit = UNIT_CM;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "mm", 2) == 0)
*unit = UNIT_MM;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "pt", 2) == 0)
*unit = UNIT_PT;
- else if (strncasecmp((char *) token->idata->data +
+ else if (strncasecmp((char *) lwc_string_data(token->idata) +
consumed, "pc", 2) == 0)
*unit = UNIT_PC;
else
return CSS_INVALID;
- } else if (token->idata->len - consumed == 1) {
- if (strncasecmp((char *) token->idata->data + consumed,
+ } else if (lwc_string_length(token->idata) - consumed == 1) {
+ if (strncasecmp((char *) lwc_string_data(token->idata) + consumed,
"s", 1) == 0)
*unit = UNIT_S;
else
@@ -6803,7 +6774,7 @@ css_error parse_unit_specifier(css_language *c,
return CSS_INVALID;
*unit = default_unit;
} else {
- if (consumed != token->idata->len)
+ if (consumed != lwc_string_length(token->idata))
return CSS_INVALID;
*unit = UNIT_PCT;
}
@@ -7323,7 +7294,7 @@ css_error parse_content_list(css_language *c,
return CSS_INVALID;
} else if (token->type == CSS_TOKEN_FUNCTION &&
token->ilower == c->strings[COUNTER]) {
- const parserutils_hash_entry *name;
+ lwc_string *name;
opv = CONTENT_COUNTER;
@@ -7394,8 +7365,8 @@ css_error parse_content_list(css_language *c,
offset += sizeof(name);
} else if (token->type == CSS_TOKEN_FUNCTION &&
token->ilower == c->strings[COUNTERS]) {
- const parserutils_hash_entry *name;
- const parserutils_hash_entry *sep;
+ lwc_string *name;
+ lwc_string *sep;
opv = CONTENT_COUNTERS;