From 2b1a4ac7ad5743400fa875a91ee6869fcd94a9ed Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 2 Jul 2021 17:42:37 +0200 Subject: Return non-0 value from callback to cancel parsing (and return the value in html_parser_parse) --- include/HtmlParser.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/HtmlParser.h b/include/HtmlParser.h index e6f0c3b..a7cdb4f 100644 --- a/include/HtmlParser.h +++ b/include/HtmlParser.h @@ -27,7 +27,8 @@ typedef enum{ HTML_PARSE_JAVASCRIPT_CODE } HtmlParseType; -typedef void (*HtmlParseCallback)(HtmlParser *html_parser, HtmlParseType parse_type, void *userdata); +/* Return 0 to continue */ +typedef int (*HtmlParseCallback)(HtmlParser *html_parser, HtmlParseType parse_type, void *userdata); #define UNCLOSED_TAGS_SIZE 2048 @@ -53,8 +54,11 @@ struct HtmlParser { HtmlStringView unclosed_tags[UNCLOSED_TAGS_SIZE]; }; -/* Note: HTML_PARSE_TAG_START is guaranteed to be called for a tag before HTML_PARSE_TAG_END */ -void html_parser_parse(const char *html_source, size_t len, HtmlParseCallback parse_callback, void *userdata); +/* + Returns the value returned from |parse_callback|. 0 meaning success. + Note: HTML_PARSE_TAG_START is guaranteed to be called for a tag before HTML_PARSE_TAG_END +*/ +int html_parser_parse(const char *html_source, size_t len, HtmlParseCallback parse_callback, void *userdata); #ifdef __cplusplus } -- cgit v1.2.3