diff --git a/include/mycss/selectors/myosi_resource.h b/include/mycss/selectors/myosi_resource.h index 21baa67..8dd81ac 100644 --- a/include/mycss/selectors/myosi_resource.h +++ b/include/mycss/selectors/myosi_resource.h @@ -23,11 +23,11 @@ #pragma once static const char mycss_selectors_resource_matcher_names_map[][3] = { - "=", "~=", "|=", "^=", "$=", "*=" + "=", "~=", "|=", "^=", "$=", "*=", "'", "\"" }; static const char mycss_selectors_resource_combinator_names_map[][3] = { - "", " ", ">", "+", "~", "||" + "", " ", ">", "+", "~", "||", "'", "\"" }; #endif /* MyHTML_MyCSS_SELECTORS_MYOSI_RESOURCE_H */ diff --git a/source/modest/finder/finder.c b/source/modest/finder/finder.c index ed7b576..9556f03 100644 --- a/source/modest/finder/finder.c +++ b/source/modest/finder/finder.c @@ -163,8 +163,8 @@ mystatus_t modest_finder_by_selectors_list(modest_finder_t* finder, myhtml_tree_ } // FRANK - printf("\nmodest_finder_by_selectors_list()\n"); - printf("\tselector_list->entries_list_length = %d\n", (int)selector_list->entries_list_length); + // printf("\nmodest_finder_by_selectors_list()\n"); + // printf("\tselector_list->entries_list_length = %d\n", (int)selector_list->entries_list_length); for(size_t i = 0; i < selector_list->entries_list_length; i++) { mycss_selectors_specificity_t spec = selector_list->entries_list[i].specificity; @@ -187,9 +187,9 @@ myhtml_tree_node_t * modest_finder_node_combinator_begin(modest_finder_t* finder myhtml_tree_node_t *node = base_node; // FRANK - printf("\nmodest_finder_node_combinator_begin()\n"); - printf("\t%s\n", (node)?"has node":"no node"); - printf("\tselector->type = %d\n", (int)selector->type); + // printf("\nmodest_finder_node_combinator_begin()\n"); + // printf("\t%s\n", (node)?"has node":"no node"); + // printf("\tselector->type = %d\n", (int)selector->type); while(node) { if(node->tag_id != MyHTML_TAG__TEXT && node->tag_id != MyHTML_TAG__COMMENT && @@ -249,8 +249,8 @@ myhtml_tree_node_t * modest_finder_node_combinator_undef(modest_finder_t* finder return NULL; // FRANK - printf("\nmodest_finder_node_combinator_undef()\n"); - printf("\tselector->type = %d\n", (int)selector->type); + // printf("\nmodest_finder_node_combinator_undef()\n"); + // printf("\tselector->type = %d\n", (int)selector->type); mycss_selectors_specificity_t match_spec = *spec; diff --git a/source/modest/finder/pseudo_class.c b/source/modest/finder/pseudo_class.c index 9e0622a..bb6051c 100644 --- a/source/modest/finder/pseudo_class.c +++ b/source/modest/finder/pseudo_class.c @@ -77,6 +77,67 @@ bool modest_finder_selector_sub_type_pseudo_class_function_has(modest_finder_t* return false; } +// concat str1 and str2 +char *concat_string(const char *str1, const char *str2) +{ + char *finalString = NULL; + size_t n = 0; + + if(str1) n += strlen(str1); + if(str2) n += strlen(str2); + + if((str1 || str2) && (finalString = malloc(n + 1)) != NULL) + { + *finalString = '\0'; + + if(str1) strcpy(finalString, str1); + if(str2) strcat(finalString, str2); + } + + return finalString; +} + +bool modest_finder_selector_sub_type_pseudo_class_function_contains(modest_finder_t* finder, myhtml_tree_node_t* base_node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec) +{ + // FRANK + // printf("\nmodest_finder_selector_sub_type_pseudo_class_function_contains()\n"); + if(base_node){ + const char* text = NULL; + myhtml_tree_node_t *text_node = myhtml_node_child(base_node); + if(text_node) { + text = myhtml_node_text(text_node, NULL); + if(text){ + // printf("\ttext = %s\n", text); + char *data = NULL; + + mycss_selectors_list_t *list = selector->value; + for(size_t i = 0; i < list->entries_list_length; i++) { + bool i_found = false; + mycss_selectors_entry_t *sel_entry = list->entries_list[i].entry; + + if(sel_entry->key->data){ + data = concat_string(data, sel_entry->key->data); + } + + mycss_selectors_entry_t *next = sel_entry->next; + while(next && !i_found){ + if(next->key->data){ + data = concat_string(data, " "); + data = concat_string(data, next->key->data); + } + next = next->next; + } + } + // printf("\tdata = %s\n", data); + if(strstr(text, data) != NULL) { + return true; + } + } + } + } + return false; +} +/* bool modest_finder_selector_sub_type_pseudo_class_function_contains(modest_finder_t* finder, myhtml_tree_node_t* base_node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec) { // FRANK @@ -136,6 +197,7 @@ bool modest_finder_selector_sub_type_pseudo_class_function_contains(modest_finde return false; } +*/ bool modest_finder_selector_sub_type_pseudo_class_function_lang(modest_finder_t* finder, myhtml_tree_node_t* base_node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec) { diff --git a/source/modest/finder/type.c b/source/modest/finder/type.c index 732c56d..e0ec0f4 100644 --- a/source/modest/finder/type.c +++ b/source/modest/finder/type.c @@ -113,8 +113,8 @@ bool modest_finder_selector_type_attribute(modest_finder_t* finder, myhtml_tree_ bool modest_finder_selector_type_pseudo_class_function(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec) { // FRANK - printf("\nmodest_finder_selector_type_pseudo_class_function()\n"); - printf("\tselector->sub_type = %d\n", (int)selector->sub_type); + // printf("\nmodest_finder_selector_type_pseudo_class_function()\n"); + // printf("\tselector->sub_type = %d\n", (int)selector->sub_type); if(selector->sub_type < MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_LAST_ENTRY) return modest_finder_static_selector_sub_type_pseudo_class_function_map[selector->sub_type](finder, node, selector, spec); diff --git a/source/mycss/selectors/function.c b/source/mycss/selectors/function.c index 4495f1b..3868522 100644 --- a/source/mycss/selectors/function.c +++ b/source/mycss/selectors/function.c @@ -118,7 +118,7 @@ void mycss_selectors_function_begin_contains(mycss_entry_t* entry, mycss_selecto // FRANK // TODO: implement - printf("\nmycss_selectors_function_begin_contains()\n"); + // printf("\nmycss_selectors_function_begin_contains()\n"); // printf("\tselector->sub_type = %d\n", (int)selector->sub_type); mycss_selectors_t *selectors = entry->selectors; diff --git a/source/mycss/selectors/function_parser.c b/source/mycss/selectors/function_parser.c index ccb29d5..3d0f140 100644 --- a/source/mycss/selectors/function_parser.c +++ b/source/mycss/selectors/function_parser.c @@ -234,32 +234,32 @@ bool mycss_selectors_function_parser_has(mycss_entry_t* entry, mycss_token_t* to // printf("\nmycss_selectors_function_parser_contains_find_bad_selector()\n"); // } -bool mycss_selectors_function_parser_contains(mycss_entry_t* entry, mycss_token_t* token, bool last_response) -{ - // TODO: implement - // FRANK - printf("\nmycss_selectors_function_parser_contains()\n"); - // printf("\ttoken->type = %d\n\tentry->parser_ending_token = %d\n\tlast_response = %d\n", (int)token->type, entry->parser_ending_token, (int)last_response); +// bool mycss_selectors_function_parser_contains(mycss_entry_t* entry, mycss_token_t* token, bool last_response) +// { +// // TODO: implement +// // FRANK +// printf("\nmycss_selectors_function_parser_contains()\n"); +// // printf("\ttoken->type = %d\n\tentry->parser_ending_token = %d\n\tlast_response = %d\n", (int)token->type, entry->parser_ending_token, (int)last_response); - mycss_selectors_t *selectors = entry->selectors; - mycss_selectors_entry_t *selector = selectors->entry_last; - printf("\t%s\n", (selector->value) ? "selector->value exists" : "selector->value does not exist"); +// mycss_selectors_t *selectors = entry->selectors; +// mycss_selectors_entry_t *selector = selectors->entry_last; +// printf("\t%s\n", (selector->value) ? "selector->value exists" : "selector->value does not exist"); - if(token){ +// if(token){ - // printf("%.*s", (int)size, buffer); - printf("\ttoken from %d -> %d, type = %d\n", (int)token->begin, (int)token->length, (int)token->type); - printf("\tdata = \"%.*s\"\n", (int)token->length, (char*)token->data); +// // printf("%.*s", (int)size, buffer); +// printf("\ttoken from %d -> %d, type = %d\n", (int)token->begin, (int)token->length, (int)token->type); +// printf("\tdata = \"%.*s\"\n", (int)token->length, (char*)token->data); - if(token->type == entry->parser_ending_token) { - printf("\ttype is entry->parser_ending_token\n"); - mycss_entry_parser_list_pop(entry); - return false; - } - } +// if(token->type == entry->parser_ending_token) { +// printf("\ttype is entry->parser_ending_token\n"); +// mycss_entry_parser_list_pop(entry); +// return false; +// } +// } - return true; -} +// return true; +// } /////////////////////////////////////////////////////////// ////// NTH OF SELECTORS diff --git a/source/mycss/selectors/init.c b/source/mycss/selectors/init.c index 42f7075..7a890c3 100644 --- a/source/mycss/selectors/init.c +++ b/source/mycss/selectors/init.c @@ -144,7 +144,7 @@ mycss_selectors_list_t * mycss_selectors_parse_by_function(mycss_selectors_t* se // FRANK // printf("\nmycss_selectors_parse_by_function()\n"); - // printf("\tstatus = %d %s\n", (int)status, ((int)status == MyHTML_STATUS_OK)?"MyHTML_STATUS_OK":"not OK"); + // printf("\t%s\n", ((int)status == MyHTML_STATUS_OK)?"MyHTML_STATUS_OK":"not OK"); if(out_status) *out_status = status; diff --git a/source/mycss/selectors/myosi_resource.h b/source/mycss/selectors/myosi_resource.h index 21baa67..8dd81ac 100644 --- a/source/mycss/selectors/myosi_resource.h +++ b/source/mycss/selectors/myosi_resource.h @@ -23,11 +23,11 @@ #pragma once static const char mycss_selectors_resource_matcher_names_map[][3] = { - "=", "~=", "|=", "^=", "$=", "*=" + "=", "~=", "|=", "^=", "$=", "*=", "'", "\"" }; static const char mycss_selectors_resource_combinator_names_map[][3] = { - "", " ", ">", "+", "~", "||" + "", " ", ">", "+", "~", "||", "'", "\"" }; #endif /* MyHTML_MyCSS_SELECTORS_MYOSI_RESOURCE_H */ diff --git a/source/mycss/selectors/serialization.c b/source/mycss/selectors/serialization.c index b97aab3..99d675b 100644 --- a/source/mycss/selectors/serialization.c +++ b/source/mycss/selectors/serialization.c @@ -21,6 +21,70 @@ #include "mycss/selectors/serialization.h" #include "mycss/selectors/myosi_resource.h" +// void mycss_selectors_serialization_chain_contains(mycss_selectors_t* selectors, mycss_selectors_entry_t* selector, +// mycore_callback_serialize_f callback, void* context) +// { +// while(selector) { +// if(selector->combinator == MyCSS_SELECTORS_COMBINATOR_DESCENDANT) +// callback(" ", 1, context); +// else if(selector->combinator == MyCSS_SELECTORS_COMBINATOR_UNDEF) { +// /* "" */ +// } +// else { +// callback(" ", 1, context); + +// const char *comb_name = mycss_selectors_resource_combinator_names_map[ selector->combinator ]; +// callback(comb_name, strlen(comb_name), context); + +// callback(" ", 1, context); +// } + +// mycss_selectors_serialization_selector(selectors, selector, callback, context); + +// selector = selector->next; +// } +// } + +// bool mycss_selectors_serialization_contains(mycss_selectors_t* selectors, mycss_selectors_list_t *selectors_list, +// mycore_callback_serialize_f callback, void* context) +// { +// // TODO: implement +// // FRANK +// // printf("\nmycss_selectors_serialization_contains()\n"); +// while(selectors_list) { + +// // FRANK +// // printf("\nmycss_selectors_serialization_list()\n"); +// // printf("\tselectors_list->entries_list_length = %d\n", (int)selectors_list->entries_list_length); + +// for(size_t i = 0; i < selectors_list->entries_list_length; i++) +// { +// mycss_selectors_entries_list_t *entries = &selectors_list->entries_list[i]; +// mycss_selectors_serialization_chain_contains(selectors, entries->entry, callback, context); + +// if((i + 1) != selectors_list->entries_list_length) +// callback(", ", 2, context); +// } + +// // if(selectors_list->declaration_entry) { +// // callback(" {", 2, context); +// // mycss_declaration_serialization_entries(selectors->ref_entry, selectors_list->declaration_entry, callback, context); +// // callback("}", 1, context); +// // } + +// // if(selectors_list->flags == MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) { +// // callback("^BAD_SELECTOR_LIST", 18, context); +// // } + +// if(selectors_list->next) +// callback("\n", 1, context); + +// selectors_list = selectors_list->next; +// } + +// return true; +// } + void mycss_selectors_serialization_chain(mycss_selectors_t* selectors, mycss_selectors_entry_t* selector, mycore_callback_serialize_f callback, void* context) { @@ -45,17 +109,6 @@ void mycss_selectors_serialization_chain(mycss_selectors_t* selectors, mycss_sel } } -bool mycss_selectors_serialization_contains(mycss_selectors_t* selectors, void *value, - mycore_callback_serialize_f callback, void* context) -{ - // TODO: implement - // FRANK - printf("\nmycss_selectors_serialization_contains()\n"); - - - return true; -} - bool mycss_selectors_serialization_list(mycss_selectors_t* selectors, mycss_selectors_list_t* selectors_list, mycore_callback_serialize_f callback, void* context) { diff --git a/source/mycss/selectors/value.c b/source/mycss/selectors/value.c index 4b4886c..19f0f13 100644 --- a/source/mycss/selectors/value.c +++ b/source/mycss/selectors/value.c @@ -257,17 +257,19 @@ void * mycss_selectors_value_pseudo_class_function_contains_destroy(mycss_entry_ { // FRANK // TODO: implement - printf("\nmycss_selectors_value_pseudo_class_function_contains_destroy()\n"); + // printf("\nmycss_selectors_value_pseudo_class_function_contains_destroy()\n"); - if(value == NULL) - return NULL; + return mycss_selectors_list_destroy(entry->selectors, value, self_destroy); - if(self_destroy) { - mchar_async_free(entry->mchar, entry->mchar_value_node_id, value); - return NULL; - } + // if(value == NULL) + // return NULL; - return value; + // if(self_destroy) { + // mchar_async_free(entry->mchar, entry->mchar_value_node_id, value); + // return NULL; + // } + + // return value; } void * mycss_selectors_value_pseudo_class_function_lang_destroy(mycss_entry_t* entry, void* value, bool self_destroy) diff --git a/test/mycss/pseudo_class_contains b/test/mycss/pseudo_class_contains new file mode 100755 index 0000000..a563a77 Binary files /dev/null and b/test/mycss/pseudo_class_contains differ diff --git a/test/myhtml/pseudo_class_contains.c b/test/myhtml/pseudo_class_contains.c index 3db32c5..ad8bdd0 100644 --- a/test/myhtml/pseudo_class_contains.c +++ b/test/myhtml/pseudo_class_contains.c @@ -89,7 +89,6 @@ mycss_selectors_list_t * prepare_selector(mycss_entry_t *css_entry, const char* // printf("\nprepare_selector()\n"); // printf("\t%s\n", (list != NULL)?"has list":"no list"); - // printf("\tlist->flags = %d\n", (int)list->flags); /* check parsing errors */ if(list == NULL || (list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD)) { @@ -125,9 +124,12 @@ void print_found_result(myhtml_tree_t* html_tree, myhtml_collection_t *collectio int main(int argc, const char * argv[]) { - const char *html = "
Another

Hello World

Something Else

"; + const char *html = "
Another

Hello World

World

"; // const char *selector = ":has(p)"; - const char *selector = "p:contains(Hello World)"; + // const char *selector = ":contains(Hello World)"; + const char *selector = ":contains(World)"; + // const char *selector = "p:contains('Hello World')"; // Bad Selector + // const char *selector = "p:contains(\"Hello World\")"; // Bad Selector /* init MyHTML and parse HTML */ myhtml_tree_t *html_tree = parse_html(html, strlen(html));