From 385ee89b582259503a2ce997aa195f4b19956271 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Wed, 12 Sep 2007 16:23:46 +0200 Subject: [PATCH] DOM: Move get_scanner_token_number from dom/select to dom/scanner --- src/dom/scanner.c | 21 +++++++++++++++++++++ src/dom/scanner.h | 4 ++++ src/dom/select.c | 22 ---------------------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/dom/scanner.c b/src/dom/scanner.c index c3cd1baa..51c258d9 100644 --- a/src/dom/scanner.c +++ b/src/dom/scanner.c @@ -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 */ diff --git a/src/dom/scanner.h b/src/dom/scanner.h index 1f6a6f17..e45ff0e0 100644 --- a/src/dom/scanner.h +++ b/src/dom/scanner.h @@ -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; diff --git a/src/dom/select.c b/src/dom/select.c index 521672ac..b87d2b3d 100644 --- a/src/dom/select.c +++ b/src/dom/select.c @@ -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)