mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
DOM: Move get_scanner_token_number from dom/select to dom/scanner
This commit is contained in:
parent
e568011da7
commit
385ee89b58
@ -115,6 +115,27 @@ get_dom_scanner_token_debug(struct dom_scanner *scanner)
|
||||
}
|
||||
#endif
|
||||
|
||||
long
|
||||
get_scanner_token_number(struct dom_scanner_token *token)
|
||||
{
|
||||
long number = 0;
|
||||
|
||||
while (token->string.length > 0 && isdigit(token->string.string[0])) {
|
||||
long old_number = number;
|
||||
|
||||
number *= 10;
|
||||
|
||||
/* -E2BIG */
|
||||
if (old_number > number)
|
||||
return -1;
|
||||
|
||||
number += token->string.string[0] - '0';
|
||||
skip_dom_scanner_token_char(token);
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
|
||||
/* Initializers */
|
||||
|
||||
|
@ -37,6 +37,10 @@ struct dom_scanner_token {
|
||||
((token)->string.length == (sizeof(str) - 1) \
|
||||
&& !strncasecmp((token)->string.string, str, sizeof(str) - 1))
|
||||
|
||||
/** Get unsigned number from token string.
|
||||
* Returns -1 if overflow was detected. */
|
||||
long get_scanner_token_number(struct dom_scanner_token *token);
|
||||
|
||||
|
||||
struct dom_scan_table_info {
|
||||
enum { DOM_SCAN_RANGE, DOM_SCAN_STRING, DOM_SCAN_END } type;
|
||||
|
@ -167,28 +167,6 @@ parse_dom_select_attribute(struct dom_select_node *sel, struct dom_scanner *scan
|
||||
* 0n+0
|
||||
*/
|
||||
|
||||
/* FIXME: Move somewhere else? dom/scanner.h? */
|
||||
static size_t
|
||||
get_scanner_token_number(struct dom_scanner_token *token)
|
||||
{
|
||||
size_t number = 0;
|
||||
|
||||
while (token->string.length > 0 && isdigit(token->string.string[0])) {
|
||||
size_t old_number = number;
|
||||
|
||||
number *= 10;
|
||||
|
||||
/* -E2BIG */
|
||||
if (old_number > number)
|
||||
return -1;
|
||||
|
||||
number += token->string.string[0] - '0';
|
||||
skip_dom_scanner_token_char(token);
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
/* Parses the '(...)' part of ':nth-of-type(...)' and ':nth-child(...)'. */
|
||||
static enum dom_code
|
||||
parse_dom_select_nth_arg(struct dom_select_nth_match *nth, struct dom_scanner *scanner)
|
||||
|
Loading…
Reference in New Issue
Block a user