-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New CSS selector ":contains(text)" #42
New CSS selector ":contains(text)" #42
Conversation
…tils/MyCSS/functions.pl'
…tains(); Test pseudo_class_contains succeeds
source/modest/finder/finder.c
Outdated
@@ -189,9 +190,9 @@ myhtml_tree_node_t * modest_finder_node_combinator_begin(modest_finder_t* finder | |||
if(callback_found) | |||
callback_found(finder, node, selector_list, selector, spec, ctx); | |||
} | |||
else { | |||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra spaces after else {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
source/modest/finder/finder.c
Outdated
// FRANK | ||
// printf("\nmodest_finder_node_combinator_undef()\n"); | ||
// printf("\tselector->type = %d\n", (int)selector->type); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to remove comments above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
source/modest/finder/pseudo_class.c
Outdated
@@ -77,6 +77,62 @@ 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to core
module, append to mycore/utils.c and rename to mycore_str_cat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
source/modest/finder/pseudo_class.c
Outdated
|
||
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) | ||
{ | ||
if(base_node){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(base_node == NULL) {
return false;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
source/modest/finder/pseudo_class.c
Outdated
if(str1) n += strlen(str1); | ||
if(str2) n += strlen(str2); | ||
|
||
if((str1 || str2) && (result = malloc(n + 1)) != NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many checks of the same str1
and str2
You can make it easier
source/modest/finder/pseudo_class.c
Outdated
if(str1) n += strlen(str1); | ||
if(str2) n += strlen(str2); | ||
|
||
if((str1 || str2) && (result = malloc(n + 1)) != NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
malloc
=> mycore_malloc
and:
result = mycore_malloc(n + 1);
if(result == NULL) {
return NULL;
}
source/modest/finder/pseudo_class.c
Outdated
mycss_selectors_entry_t *next = sel_entry->next; | ||
while(next && !i_found){ | ||
if(next->key->data){ | ||
data = concat_string(data, " "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memory leak!
if we allocation memory in concat_string
and call concat_string
with returned data we get leak.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course :)
source/modest/finder/pseudo_class.c
Outdated
next = next->next; | ||
} | ||
} | ||
if(strstr(text, data) != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the release (mycore_free(data)
) of resources for data
?
source/mycss/selectors/function.c
Outdated
@@ -34,7 +34,7 @@ const mycss_selectots_function_begin_entry_t * mycss_function_begin_entry_by_nam | |||
% MyCSS_SELECTORS_FUNCTION_NAME_STATIC_SIZE) + 1; | |||
|
|||
while (mycss_selectors_function_begin_map_index[idx].name) | |||
{ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary spaces after {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
source/mycss/selectors/function.c
Outdated
|
||
(*new_list)->parent = current_list; | ||
|
||
mycss_entry_parser_list_push(entry, mycss_selectors_function_parser_has, entry->parser_switch, entry->parser_ending_token, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why didn't you implement their parsing function?
Do not use mycss_selectors_function_parser_has
in this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
…pseudo_class_function_contains' to use mycore_malloc, mycore_realloc and snprintf
source/modest/finder/pseudo_class.c
Outdated
mycore_free(data); | ||
return true; | ||
} | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary else
if(strstr(text, data) != NULL) {
mycore_free(data);
return true;
}
mycore_free(data);
return false;
mycss_selectors_list_t *list = (mycss_selectors_list_t*)selector->value; | ||
for(size_t i = 0; i < list->entries_list_length; i++) { | ||
char *data = NULL; | ||
data = mycore_malloc(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(data == NULL) {
return false;
}
source/modest/finder/pseudo_class.c
Outdated
const char *str = sel_entry->key->data; | ||
int length = strlen(str) + 1; | ||
data = mycore_realloc(data, length); | ||
snprintf(&data[0], length, "%s", str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leak detected if mycore_realloc
return NULL
. Need check.
if(sel_entry->key->data){
const char *str = sel_entry->key->data;
int length = strlen(str) + 1;
char *new_data = mycore_realloc(data, length);
if(new_data == NULL) {
mycore_free(data);
return false;
}
snprintf(&data[0], length, "%s", str);
}
source/modest/finder/pseudo_class.c
Outdated
const char *str = next->key->data; | ||
int length = strlen(whitespace) + strlen(str) + 1; | ||
data = mycore_realloc(data, prev + length); | ||
snprintf(&data[prev], length, "%s%s", whitespace, str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this we have memory leak. see prev comment
source/modest/finder/pseudo_class.c
Outdated
const char *str = sel_entry->key->data; | ||
int length = strlen(str) + 1; | ||
data = mycore_realloc(data, length); | ||
if(data == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leak detected, see comment
mycss_selectors_entry_t *sel_entry = list->entries_list[i].entry; | ||
if(sel_entry->key->data){ | ||
const char *str = sel_entry->key->data; | ||
int length = strlen(str) + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add new line after this
source/modest/finder/pseudo_class.c
Outdated
mycore_free(data); | ||
return false; | ||
} | ||
snprintf(&new_data[0], length, "%s", str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and change to snprintf(new_data, length, "%s", str);
int prev = strlen(data); | ||
const char *whitespace = (prev > 0) ? " " : ""; | ||
const char *str = next->key->data; | ||
int length = strlen(whitespace) + strlen(str) + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line after
source/modest/finder/pseudo_class.c
Outdated
mycore_free(data); | ||
return false; | ||
} | ||
snprintf(&new_data[prev], length, "%s%s", whitespace, str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line before
AWESOME! |
Thanks man! That was fun :) |
You're welcome! 😄 |
Hey Alex,
I followed your instructions in #36 and added new pseudo class "contains".
$func_map = {...}
perl utils/MyCSS/functions.pl
mycss_selectors_function_begin_contains()
in file function.c:added selector sub_type
MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS
test/myhtml/pseudo_class_contains.c
modest_finder_selector_sub_type_pseudo_class_function_contains()
in file pseudo_class.c.As of now, the selector argument cannot contain single or double quotation marks. That's because I basically duplicated the implementation from pseudo class "has", so behavior and serialization is the same.
Example:
According to the spec (from 2001) however, quotation marks should also be supported.
So my implementation only solves the "argument as keyword" case.
Tell me what you think.
Best,
Frank