File Coverage

third_party/modest/source/modest/finder/type.c
Criterion Covered Total %
statement 23 60 38.3
branch 13 40 32.5
condition n/a
subroutine n/a
pod n/a
total 36 100 36.0


line stmt bran cond sub pod time code
1             /*
2             Copyright (C) 2016-2017 Alexander Borisov
3            
4             This library is free software; you can redistribute it and/or
5             modify it under the terms of the GNU Lesser General Public
6             License as published by the Free Software Foundation; either
7             version 2.1 of the License, or (at your option) any later version.
8            
9             This library is distributed in the hope that it will be useful,
10             but WITHOUT ANY WARRANTY; without even the implied warranty of
11             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12             Lesser General Public License for more details.
13            
14             You should have received a copy of the GNU Lesser General Public
15             License along with this library; if not, write to the Free Software
16             Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17            
18             Author: lex.borisov@gmail.com (Alexander Borisov)
19             */
20              
21             #include "modest/finder/type.h"
22             #include "modest/finder/resource.h"
23              
24 0           bool modest_finder_selector_type_undef(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
25             {
26 0           return false;
27             }
28              
29 452           bool modest_finder_selector_type_element(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
30             {
31             /* namespace */
32 452 50         if(selector->ns_entry) {
33 0 0         if(selector->ns_entry->ns_id != MyHTML_NAMESPACE_ANY && selector->ns_entry->ns_id != node->ns)
    0          
34 0           return false;
35             }
36            
37             /* tag match */
38 452           mycore_string_t *str = selector->key;
39 452 100         if(str->length == 1 && *str->data == '*')
    50          
40 0           return true;
41            
42 452 50         if(node->tree) {
43 452           myhtml_tag_id_t tag_id = myhtml_tag_id_by_name(node->tree, str->data, str->length);
44            
45 452 100         if(tag_id == node->tag_id)
46 129           return true;
47             }
48            
49 323           return false;
50             }
51              
52 287           bool modest_finder_selector_type_id(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
53             {
54 287 100         if(node->token == NULL)
55 114           return false;
56            
57 173 50         if(node->tree) {
58 173           return modest_finder_match_attribute_eq(node->token->attr_first,
59             "id", 2,
60 346           selector->key->data, selector->key->length,
61 173           (node->tree->compat_mode != MyHTML_TREE_COMPAT_MODE_QUIRKS));
62             }
63            
64 0           return false;
65             }
66              
67 364           bool modest_finder_selector_type_class(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
68             {
69 364 100         if(node->token == NULL)
70 39           return false;
71            
72 325 50         if(node->tree) {
73 325           return modest_finder_match_attribute_ws(node->token->attr_first,
74             "class", 5,
75 650           selector->key->data, selector->key->length,
76 325           (node->tree->compat_mode != MyHTML_TREE_COMPAT_MODE_QUIRKS));
77             }
78            
79 0           return false;
80             }
81              
82 0           bool modest_finder_selector_type_attribute(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
83             {
84             /* namespace */
85 0 0         if(selector->ns_entry) {
86 0 0         if(selector->ns_entry->ns_id != MyHTML_NAMESPACE_ANY && selector->ns_entry->ns_id != node->ns)
    0          
87 0           return false;
88             }
89            
90 0 0         if(node->token == NULL)
91 0           return false;
92            
93 0           mycss_selectors_object_attribute_t *sel_attr = mycss_selector_value_attribute(selector->value);
94            
95 0 0         if(sel_attr) {
96 0 0         if(sel_attr->value == NULL)
97 0           return false;
98            
99 0 0         if(sel_attr->match < MyCSS_SELECTORS_MATCH_LAST_ENTRY)
100 0           return modest_finder_static_selector_match_map[sel_attr->match](node->token->attr_first,
101 0           selector->key->data, selector->key->length,
102 0           sel_attr->value->data, sel_attr->value->length,
103 0           (sel_attr->mod & MyCSS_SELECTORS_MOD_I));
104             }
105             else {
106 0           return modest_finder_match_attribute_only_key(node->token->attr_first,
107 0           selector->key->data, selector->key->length);
108             }
109            
110 0           return false;
111             }
112              
113 0           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)
114             {
115 0 0         if(selector->sub_type < MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_LAST_ENTRY)
116 0           return modest_finder_static_selector_sub_type_pseudo_class_function_map[selector->sub_type](finder, node, selector, spec);
117            
118 0           return false;
119             }
120              
121 0           bool modest_finder_selector_type_pseudo_class(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
122             {
123 0 0         if(selector->sub_type < MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_LAST_ENTRY)
124 0           return modest_finder_static_selector_sub_type_pseudo_class_map[selector->sub_type](finder, node, selector, spec);
125            
126 0           return false;
127             }
128              
129 0           bool modest_finder_selector_type_pseudo_element_function(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
130             {
131 0           return false;
132             }
133              
134 0           bool modest_finder_selector_type_pseudo_element(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
135             {
136 0           return false;
137             }
138              
139