aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-07-03 00:18:06 +0200
committerdec05eba <dec05eba@protonmail.com>2021-07-03 00:18:06 +0200
commit41206f68eb257e788a2d038e25f01d9deb7d37af (patch)
tree00aae0721a00854adbfa0630e56051c81f1559f2
parentd8132eeb7337b410a46fcf64ae0f6dacbe52cf33 (diff)
Strip whitespace for attribute values as well
-rw-r--r--include/quickmedia/HtmlSearch.h2
-rw-r--r--src/HtmlSearch.c34
2 files changed, 20 insertions, 16 deletions
diff --git a/include/quickmedia/HtmlSearch.h b/include/quickmedia/HtmlSearch.h
index 63f2175..1a7faca 100644
--- a/include/quickmedia/HtmlSearch.h
+++ b/include/quickmedia/HtmlSearch.h
@@ -53,12 +53,14 @@ typedef struct {
/*
Returns an empty string view if attribute doesn't exist or if it doesn't have any value.
The result is only valid within the callback function scope.
+ The result is stripped of whitespace on the left and right side.
*/
QuickMediaStringView quickmedia_html_node_get_attribute_value(QuickMediaMatchNode *self, const char *attribute_name);
/*
Returns an empty string if the node doesn't have any text or if there was an error creating the text.
The result is only valid within the callback function scope.
+ The result is stripped of whitespace on the left and right side.
*/
QuickMediaStringView quickmedia_html_node_get_text(QuickMediaMatchNode *self);
diff --git a/src/HtmlSearch.c b/src/HtmlSearch.c
index 89ee326..03d7e3a 100644
--- a/src/HtmlSearch.c
+++ b/src/HtmlSearch.c
@@ -329,22 +329,6 @@ static int html_parse_callback(HtmlParser *html_parser, HtmlParseType parse_type
return 0;
}
-QuickMediaStringView quickmedia_html_node_get_attribute_value(QuickMediaMatchNode *self, const char *attribute_name) {
- QuickMediaStringView attr_name;
- attr_name.data = attribute_name;
- attr_name.size = strlen(attribute_name);
-
- QuickMediaHtmlAttribute *attr = get_attribute_by_name(self->node, attr_name);
- if(attr) {
- return attr->value;
- } else {
- QuickMediaStringView attr_value;
- attr_value.data = NULL;
- attr_value.size = 0;
- return attr_value;
- }
-}
-
static int is_whitespace(int c) {
switch(c) {
case ' ':
@@ -384,6 +368,24 @@ static void strip(const char *str, size_t size, const char **output_str, size_t
rstrip(*output_str, *output_size, output_size, strip_filter_func);
}
+QuickMediaStringView quickmedia_html_node_get_attribute_value(QuickMediaMatchNode *self, const char *attribute_name) {
+ QuickMediaStringView attr_name;
+ attr_name.data = attribute_name;
+ attr_name.size = strlen(attribute_name);
+
+ QuickMediaHtmlAttribute *attr = get_attribute_by_name(self->node, attr_name);
+ if(attr) {
+ QuickMediaStringView attr_value = attr->value;
+ strip(attr_value.data, attr_value.size, &attr_value.data, &attr_value.size, is_whitespace);
+ return attr_value;
+ } else {
+ QuickMediaStringView attr_value;
+ attr_value.data = NULL;
+ attr_value.size = 0;
+ return attr_value;
+ }
+}
+
static int merge_inner_text(QuickMediaHtmlNode *node, QuickMediaString *str) {
if(node->is_tag) {
int newline = 0;