mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Make the dom_scanner_token store it's string in a dom_string struct
This commit is contained in:
parent
97c702c674
commit
6e163b186c
@ -507,8 +507,8 @@ render_dom_element_end_source(struct dom_stack *stack, struct dom_node *node, vo
|
||||
struct dom_stack_state *state = get_dom_stack_top(stack);
|
||||
struct sgml_parser_state *pstate = get_dom_stack_state_data(stack->contexts[0], state);
|
||||
struct dom_scanner_token *token = &pstate->end_token;
|
||||
unsigned char *string = token->string;
|
||||
int length = token->length;
|
||||
unsigned char *string = token->string.string;
|
||||
int length = token->string.length;
|
||||
|
||||
assert(node && renderer && renderer->document);
|
||||
|
||||
|
@ -130,7 +130,7 @@ scan_css_token(struct dom_scanner *scanner, struct dom_scanner_token *token)
|
||||
int real_length = -1;
|
||||
|
||||
assert(first_char);
|
||||
token->string = string++;
|
||||
token->string.string = string++;
|
||||
|
||||
if (is_css_char_token(first_char)) {
|
||||
type = first_char;
|
||||
@ -174,7 +174,7 @@ scan_css_token(struct dom_scanner *scanner, struct dom_scanner_token *token)
|
||||
/* Make sure that we have an ending ')' */
|
||||
skip_css(scanner, function_end, ')');
|
||||
if (*function_end == ')') {
|
||||
type = map_dom_scanner_string(scanner, token->string,
|
||||
type = map_dom_scanner_string(scanner, token->string.string,
|
||||
string, CSS_TOKEN_FUNCTION);
|
||||
|
||||
/* If it is not a known function just skip the
|
||||
@ -202,7 +202,7 @@ scan_css_token(struct dom_scanner *scanner, struct dom_scanner_token *token)
|
||||
if (isquote(*from)) from++;
|
||||
if (isquote(*to)) to--;
|
||||
|
||||
token->string = from;
|
||||
token->string.string = from;
|
||||
real_length = to - from + 1;
|
||||
assert(real_length >= 0);
|
||||
string = function_end;
|
||||
@ -233,7 +233,7 @@ scan_css_token(struct dom_scanner *scanner, struct dom_scanner_token *token)
|
||||
/* Check that the hexdigit sequence is either 3 or 6
|
||||
* chars and it isn't just start of some non-hex ident
|
||||
* string. */
|
||||
hexdigits = string - token->string - 1;
|
||||
hexdigits = string - token->string.string - 1;
|
||||
if ((hexdigits == 3 || hexdigits == 6)
|
||||
&& !is_css_ident(*string)) {
|
||||
type = CSS_TOKEN_HEX_COLOR;
|
||||
@ -299,8 +299,8 @@ scan_css_token(struct dom_scanner *scanner, struct dom_scanner_token *token)
|
||||
|
||||
if (string_end) {
|
||||
/* We don't want the delimiters in the token */
|
||||
token->string++;
|
||||
real_length = string_end - token->string;
|
||||
token->string.string++;
|
||||
real_length = string_end - token->string.string;
|
||||
string = string_end + 1;
|
||||
type = CSS_TOKEN_STRING;
|
||||
}
|
||||
@ -345,7 +345,7 @@ scan_css_token(struct dom_scanner *scanner, struct dom_scanner_token *token)
|
||||
}
|
||||
|
||||
token->type = type;
|
||||
token->length = real_length > 0 ? real_length : string - token->string;
|
||||
token->string.length = real_length > 0 ? real_length : string - token->string.string;
|
||||
token->precedence = get_css_precedence(type);
|
||||
scanner->position = string;
|
||||
}
|
||||
|
@ -21,8 +21,7 @@ struct dom_scanner_token {
|
||||
int precedence;
|
||||
|
||||
/* The start of the token string and the token length */
|
||||
unsigned char *string;
|
||||
int length;
|
||||
struct dom_string string;
|
||||
};
|
||||
|
||||
/* The naming of these two macros is a bit odd .. we compare often with
|
||||
@ -31,7 +30,7 @@ struct dom_scanner_token {
|
||||
|
||||
/* Compare the string of @token with @string */
|
||||
#define dom_scanner_token_strlcasecmp(token, str, len) \
|
||||
((token) && !strlcasecmp((token)->string, (token)->length, str, len))
|
||||
((token) && !strlcasecmp((token)->string.string, (token)->string.length, str, len))
|
||||
|
||||
/* Also compares the token string but using a "static" string */
|
||||
#define dom_scanner_token_contains(token, str) \
|
||||
|
@ -70,13 +70,10 @@ get_dom_select_pseudo(struct dom_scanner_token *token)
|
||||
#undef INIT_DOM_SELECT_PSEUDO_STRING
|
||||
|
||||
};
|
||||
struct dom_string string;
|
||||
int i;
|
||||
|
||||
set_dom_string(&string, token->string, token->length);
|
||||
|
||||
for (i = 0; i < sizeof_array(pseudo_info); i++)
|
||||
if (!dom_string_casecmp(&pseudo_info[i].string, &string))
|
||||
if (!dom_string_casecmp(&pseudo_info[i].string, &token->string))
|
||||
return pseudo_info[i].pseudo;
|
||||
|
||||
return DOM_SELECT_PSEUDO_UNKNOWN;
|
||||
@ -99,7 +96,7 @@ parse_dom_select_attribute(struct dom_select_node *sel, struct dom_scanner *scan
|
||||
if (!token || token->type != CSS_TOKEN_IDENT)
|
||||
return DOM_ERR_SYNTAX;
|
||||
|
||||
set_dom_string(&sel->node.string, token->string, token->length);
|
||||
copy_dom_string(&sel->node.string, &token->string);
|
||||
|
||||
/* Get the optional '=' combo or ending ']'. */
|
||||
|
||||
@ -143,7 +140,7 @@ parse_dom_select_attribute(struct dom_select_node *sel, struct dom_scanner *scan
|
||||
switch (token->type) {
|
||||
case CSS_TOKEN_IDENT:
|
||||
case CSS_TOKEN_STRING:
|
||||
set_dom_string(&sel->node.data.attribute.value, token->string, token->length);
|
||||
copy_dom_string(&sel->node.data.attribute.value, &token->string);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -176,7 +173,7 @@ get_scanner_token_number(struct dom_scanner_token *token)
|
||||
{
|
||||
size_t number = 0;
|
||||
|
||||
while (token->length > 0 && isdigit(token->string[0])) {
|
||||
while (token->string.length > 0 && isdigit(token->string.string[0])) {
|
||||
size_t old_number = number;
|
||||
|
||||
number *= 10;
|
||||
@ -185,8 +182,8 @@ get_scanner_token_number(struct dom_scanner_token *token)
|
||||
if (old_number > number)
|
||||
return -1;
|
||||
|
||||
number += token->string[0] - '0';
|
||||
token->string++, token->length--;
|
||||
number += token->string.string[0] - '0';
|
||||
token->string.string++, token->string.length--;
|
||||
}
|
||||
|
||||
return number;
|
||||
@ -416,8 +413,8 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack,
|
||||
switch (token->type) {
|
||||
case CSS_TOKEN_IDENT:
|
||||
sel.node.type = DOM_NODE_ELEMENT;
|
||||
set_dom_string(&sel.node.string, token->string, token->length);
|
||||
if (token->length == 1 && token->string[0] == '*')
|
||||
copy_dom_string(&sel.node.string, &token->string);
|
||||
if (token->string.length == 1 && token->string.string[0] == '*')
|
||||
sel.match.element |= DOM_SELECT_ELEMENT_UNIVERSAL;
|
||||
break;
|
||||
|
||||
@ -427,7 +424,7 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack,
|
||||
sel.node.type = DOM_NODE_ATTRIBUTE;
|
||||
sel.match.attribute |= DOM_SELECT_ATTRIBUTE_ID;
|
||||
/* Skip the leading '#'. */
|
||||
token->string++, token->length--;
|
||||
token->string.string++, token->string.length--;
|
||||
break;
|
||||
|
||||
case '[':
|
||||
@ -445,7 +442,7 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack,
|
||||
sel.node.type = DOM_NODE_ATTRIBUTE;
|
||||
sel.match.attribute |= DOM_SELECT_ATTRIBUTE_SPACE_LIST;
|
||||
set_dom_string(&sel.node.string, "class", -1);
|
||||
set_dom_string(&sel.node.data.attribute.value, token->string, token->length);
|
||||
copy_dom_string(&sel.node.data.attribute.value, &token->string);
|
||||
break;
|
||||
|
||||
case ':':
|
||||
|
@ -56,7 +56,7 @@ add_sgml_element(struct dom_stack *stack, struct dom_scanner_token *token)
|
||||
struct dom_node *node;
|
||||
struct sgml_node_info *node_info;
|
||||
|
||||
node = add_dom_element(parent, token->string, token->length);
|
||||
node = add_dom_element(parent, token->string.string, token->string.length);
|
||||
if (!node) return NULL;
|
||||
|
||||
node_info = get_sgml_node_info(parser->info->elements, node);
|
||||
@ -81,12 +81,12 @@ add_sgml_attribute(struct dom_stack *stack,
|
||||
{
|
||||
struct sgml_parser *parser = get_sgml_parser(stack);
|
||||
struct dom_node *parent = get_dom_stack_top(stack)->node;
|
||||
unsigned char *value = valtoken ? valtoken->string : NULL;
|
||||
size_t valuelen = valtoken ? valtoken->length : 0;
|
||||
unsigned char *value = valtoken ? valtoken->string.string : NULL;
|
||||
size_t valuelen = valtoken ? valtoken->string.length : 0;
|
||||
struct sgml_node_info *info;
|
||||
struct dom_node *node;
|
||||
|
||||
node = add_dom_attribute(parent, token->string, token->length,
|
||||
node = add_dom_attribute(parent, token->string.string, token->string.length,
|
||||
value, valuelen);
|
||||
|
||||
info = get_sgml_node_info(parser->info->attributes, node);
|
||||
@ -110,15 +110,15 @@ add_sgml_proc_instruction(struct dom_stack *stack, struct dom_scanner_token *tok
|
||||
struct dom_node *parent = get_dom_stack_top(stack)->node;
|
||||
struct dom_node *node;
|
||||
/* Split the token in two if we can find a first space separator. */
|
||||
unsigned char *separator = memchr(token->string, ' ', token->length);
|
||||
unsigned char *separator = memchr(token->string.string, ' ', token->string.length);
|
||||
|
||||
/* Anything before the separator becomes the target name ... */
|
||||
unsigned char *name = token->string;
|
||||
size_t namelen = separator ? separator - token->string : token->length;
|
||||
unsigned char *name = token->string.string;
|
||||
size_t namelen = separator ? separator - token->string.string : token->string.length;
|
||||
|
||||
/* ... and everything after the instruction value. */
|
||||
unsigned char *value = separator ? separator + 1 : NULL;
|
||||
size_t valuelen = value ? token->length - namelen - 1 : 0;
|
||||
size_t valuelen = value ? token->string.length - namelen - 1 : 0;
|
||||
|
||||
node = add_dom_proc_instruction(parent, name, namelen, value, valuelen);
|
||||
if (!node) return NULL;
|
||||
@ -146,7 +146,7 @@ static inline void
|
||||
add_sgml_node(struct dom_stack *stack, enum dom_node_type type, struct dom_scanner_token *token)
|
||||
{
|
||||
struct dom_node *parent = get_dom_stack_top(stack)->node;
|
||||
struct dom_node *node = add_dom_node(parent, type, token->string, token->length);
|
||||
struct dom_node *node = add_dom_node(parent, type, token->string.string, token->string.length);
|
||||
|
||||
if (!node) return;
|
||||
|
||||
@ -251,13 +251,13 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
|
||||
break;
|
||||
|
||||
case SGML_TOKEN_ELEMENT_END:
|
||||
if (!token->length) {
|
||||
if (!token->string.length) {
|
||||
pop_dom_node(stack);
|
||||
} else {
|
||||
struct dom_string string;
|
||||
struct dom_stack_state *state;
|
||||
|
||||
set_dom_string(&string, token->string, token->length);
|
||||
set_dom_string(&string, token->string.string, token->string.length);
|
||||
state = search_dom_stack(stack, DOM_NODE_ELEMENT,
|
||||
&string);
|
||||
if (state) {
|
||||
|
@ -101,14 +101,14 @@ scan_sgml_text_token(struct dom_scanner *scanner, struct dom_scanner_token *toke
|
||||
/* In scan_sgml_tokens() we check that first_char != '<' */
|
||||
assert(first_char != '<' && scanner->state == SGML_STATE_TEXT);
|
||||
|
||||
token->string = string++;
|
||||
token->string.string = string++;
|
||||
|
||||
if (first_char == '&') {
|
||||
if (is_sgml_entity(*string)) {
|
||||
scan_sgml(scanner, string, SGML_CHAR_ENTITY);
|
||||
type = SGML_TOKEN_ENTITY;
|
||||
token->string++;
|
||||
real_length = string - token->string;
|
||||
token->string.string++;
|
||||
real_length = string - token->string.string;
|
||||
}
|
||||
|
||||
foreach_sgml_cdata (scanner, string) {
|
||||
@ -133,7 +133,7 @@ scan_sgml_text_token(struct dom_scanner *scanner, struct dom_scanner_token *toke
|
||||
}
|
||||
|
||||
token->type = type;
|
||||
token->length = real_length >= 0 ? real_length : string - token->string;
|
||||
token->string.length = real_length >= 0 ? real_length : string - token->string.string;
|
||||
token->precedence = get_sgml_precedence(type);
|
||||
scanner->position = string;
|
||||
}
|
||||
@ -223,7 +223,7 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
|
||||
enum sgml_token_type type = SGML_TOKEN_GARBAGE;
|
||||
int real_length = -1;
|
||||
|
||||
token->string = string++;
|
||||
token->string.string = string++;
|
||||
|
||||
if (first_char == '<') {
|
||||
scan_sgml(scanner, string, SGML_CHAR_WHITESPACE);
|
||||
@ -237,10 +237,10 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
|
||||
scanner->state = SGML_STATE_TEXT;
|
||||
|
||||
} else if (is_sgml_ident(*string)) {
|
||||
token->string = string;
|
||||
token->string.string = string;
|
||||
scan_sgml(scanner, string, SGML_CHAR_IDENT);
|
||||
|
||||
real_length = string - token->string;
|
||||
real_length = string - token->string.string;
|
||||
|
||||
scan_sgml(scanner, string, SGML_CHAR_WHITESPACE);
|
||||
if (*string == '>') {
|
||||
@ -257,13 +257,13 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
|
||||
|
||||
string++;
|
||||
scan_sgml(scanner, string, SGML_CHAR_WHITESPACE);
|
||||
token->string = ident = string;
|
||||
token->string.string = ident = string;
|
||||
|
||||
if (string + 1 < scanner->end
|
||||
&& string[0] == '-' && string[1] == '-') {
|
||||
string += 2;
|
||||
type = SGML_TOKEN_NOTATION_COMMENT;
|
||||
token->string = string;
|
||||
token->string.string = string;
|
||||
real_length = skip_comment(scanner, &string);
|
||||
assert(real_length >= 0);
|
||||
|
||||
@ -272,7 +272,7 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
|
||||
|
||||
string += 7;
|
||||
type = SGML_TOKEN_CDATA_SECTION;
|
||||
token->string = string;
|
||||
token->string.string = string;
|
||||
real_length = skip_cdata_section(scanner, &string);
|
||||
assert(real_length >= 0);
|
||||
|
||||
@ -288,7 +288,7 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
|
||||
|
||||
string++;
|
||||
scan_sgml(scanner, string, SGML_CHAR_WHITESPACE);
|
||||
token->string = pos = string;
|
||||
token->string.string = pos = string;
|
||||
scan_sgml(scanner, string, SGML_CHAR_IDENT);
|
||||
|
||||
type = map_dom_scanner_string(scanner, pos, string, base);
|
||||
@ -299,7 +299,7 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
|
||||
|
||||
/* Set length until '?' char and move position
|
||||
* beyond '>'. */
|
||||
real_length = pos - token->string - 2;
|
||||
real_length = pos - token->string.string - 2;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -320,9 +320,9 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
|
||||
scan_sgml(scanner, string, SGML_CHAR_WHITESPACE);
|
||||
|
||||
if (is_sgml_ident(*string)) {
|
||||
token->string = string;
|
||||
token->string.string = string;
|
||||
scan_sgml(scanner, string, SGML_CHAR_IDENT);
|
||||
real_length = string - token->string;
|
||||
real_length = string - token->string.string;
|
||||
|
||||
type = SGML_TOKEN_ELEMENT_END;
|
||||
skip_sgml(scanner, &string, '>', 1);
|
||||
@ -371,12 +371,12 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
|
||||
|
||||
if (string_end) {
|
||||
/* We don't want the delimiters in the token */
|
||||
token->string++;
|
||||
real_length = string_end - token->string;
|
||||
token->string.string++;
|
||||
real_length = string_end - token->string.string;
|
||||
string = string_end + 1;
|
||||
type = SGML_TOKEN_STRING;
|
||||
} else if (is_sgml_attribute(*string)) {
|
||||
token->string++;
|
||||
token->string.string++;
|
||||
scan_sgml_attribute(scanner, string);
|
||||
type = SGML_TOKEN_ATTRIBUTE;
|
||||
}
|
||||
@ -394,7 +394,7 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t
|
||||
}
|
||||
|
||||
token->type = type;
|
||||
token->length = real_length >= 0 ? real_length : string - token->string;
|
||||
token->string.length = real_length >= 0 ? real_length : string - token->string.string;
|
||||
token->precedence = get_sgml_precedence(type);
|
||||
scanner->position = string;
|
||||
}
|
||||
|
@ -35,6 +35,9 @@ dom_string_ncasecmp(struct dom_string *string1, struct dom_string *string2, size
|
||||
return strncasecmp(string1->string, string2->string, length);
|
||||
}
|
||||
|
||||
#define copy_dom_string(string1, string2) \
|
||||
set_dom_string(string1, (string2)->string, (string2)->length)
|
||||
|
||||
static inline struct dom_string *
|
||||
init_dom_string(struct dom_string *string, unsigned char *str, size_t len)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user