File Coverage

third_party/modest/source/mycss/selectors/function.c
Criterion Covered Total %
statement 18 135 13.3
branch 4 12 33.3
condition n/a
subroutine n/a
pod n/a
total 22 147 14.9


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 "mycss/selectors/function.h"
22             #include "mycss/selectors/function_resource.h"
23             #include "mycore/utils/resources.h"
24              
25             /////////////////////////////////////////////////////////
26             //// Functions for a find Begin Function
27             ////
28             /////////////////////////////////////////////////////////
29 1           const mycss_selectots_function_begin_entry_t * mycss_function_begin_entry_by_name(const char* name, size_t length)
30             {
31 3           size_t idx = ((mycore_string_chars_lowercase_map[ (const unsigned char)name[0] ] *
32 2           mycore_string_chars_lowercase_map[ (const unsigned char)name[(length - 1)] ] *
33             length)
34 1           % MyCSS_SELECTORS_FUNCTION_NAME_STATIC_SIZE) + 1;
35            
36 1 50         while (mycss_selectors_function_begin_map_index[idx].name)
37             {
38 1 50         if(mycss_selectors_function_begin_map_index[idx].length == length) {
39 1 50         if(mycore_strncasecmp(mycss_selectors_function_begin_map_index[idx].name, name, length) == 0)
40 1           return &mycss_selectors_function_begin_map_index[idx];
41            
42 0 0         if(mycss_selectors_function_begin_map_index[idx].next)
43 0           idx = mycss_selectors_function_begin_map_index[idx].next;
44             else
45 0           return NULL;
46             }
47 0 0         else if(mycss_selectors_function_begin_map_index[idx].length > length) {
48 0           return NULL;
49             }
50             else {
51 0           idx = mycss_selectors_function_begin_map_index[idx].next;
52             }
53             }
54            
55 0           return NULL;
56             }
57              
58 1           mycss_selectors_function_begin_f mycss_function_begin_by_name(const char *name, size_t length)
59             {
60 1           const mycss_selectots_function_begin_entry_t *entry = mycss_function_begin_entry_by_name(name, length);
61            
62 1 50         if(entry) {
63 1           return entry->func;
64             }
65            
66 0           return NULL;
67             }
68              
69             /////////////////////////////////////////////////////////
70             //// Unknown, for not exists function
71             ////
72             /////////////////////////////////////////////////////////
73 0           void mycss_selectors_begin_unknown(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
74             {
75 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_UNKNOWN;
76            
77 0           entry->parser = mycss_selectors_unknown_parser;
78 0           }
79              
80             ///////////////////////////////////////////////////////////
81             ////// Begin functions
82             //////
83             ///////////////////////////////////////////////////////////
84 1           void mycss_selectors_function_begin_nth_child(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
85             {
86 1           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_CHILD;
87            
88 1           entry->anb->entry = (mycss_an_plus_b_entry_t**)(&selector->value);
89            
90 1           entry->parser = mycss_an_plus_b_state_anb_begin;
91 1           entry->parser_switch = mycss_selectors_function_parser_nth_with_selectors;
92 1           }
93              
94 0           void mycss_selectors_function_begin_has(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
95             {
96 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_HAS;
97            
98 0           mycss_selectors_t *selectors = entry->selectors;
99 0           mycss_selectors_list_t **new_list = (mycss_selectors_list_t**)(&selectors->entry_last->value);
100 0           mycss_selectors_list_t *current_list = selectors->list_last;
101            
102 0           selectors->list = new_list;
103 0           selectors->list_last = NULL;
104 0           selectors->ending_token = entry->parser_ending_token;
105            
106 0           mycss_selectors_state_relative_selector_list(entry, NULL, true);
107            
108 0           (*new_list)->parent = current_list;
109            
110 0           mycss_entry_parser_list_push(entry, mycss_selectors_function_parser_has, entry->parser_switch, entry->parser_ending_token, false);
111 0           }
112              
113 0           void mycss_selectors_function_begin_contains(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
114             {
115 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS;
116              
117 0           mycss_selectors_t *selectors = entry->selectors;
118 0           mycss_selectors_list_t **new_list = (mycss_selectors_list_t**)(&selectors->entry_last->value);
119 0           mycss_selectors_list_t *current_list = selectors->list_last;
120            
121 0           selectors->list = new_list;
122 0           selectors->list_last = NULL;
123 0           selectors->ending_token = entry->parser_ending_token;
124            
125 0           mycss_selectors_state_relative_selector_list(entry, NULL, true);
126            
127 0           (*new_list)->parent = current_list;
128            
129 0           mycss_entry_parser_list_push(entry, mycss_selectors_function_parser_contains, entry->parser_switch, entry->parser_ending_token, false);
130 0           }
131              
132 0           void mycss_selectors_function_begin_nth_last_child(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
133             {
134 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_CHILD;
135              
136 0           entry->anb->entry = (mycss_an_plus_b_entry_t**)(&selector->value);
137            
138 0           entry->parser = mycss_an_plus_b_state_anb_begin;
139 0           entry->parser_switch = mycss_selectors_function_parser_nth_with_selectors;
140 0           }
141              
142 0           void mycss_selectors_function_begin_drop(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
143             {
144 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_DROP;
145            
146 0           selector->value = NULL;
147 0           entry->parser = mycss_selectors_function_parser_drop;
148 0           }
149              
150 0           void mycss_selectors_function_begin_nth_last_of_type(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
151             {
152 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_OF_TYPE;
153            
154 0           entry->anb->entry = (mycss_an_plus_b_entry_t**)(&selector->value);
155            
156 0           entry->parser = mycss_an_plus_b_state_anb_begin;
157 0           entry->parser_switch = mycss_selectors_function_parser_nth_without_selectors;
158 0           }
159              
160 0           void mycss_selectors_function_begin_not(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
161             {
162 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NOT;
163            
164 0           mycss_selectors_t *selectors = entry->selectors;
165 0           mycss_selectors_list_t **new_list = (mycss_selectors_list_t**)(&selectors->entry_last->value);
166 0           mycss_selectors_list_t *current_list = selectors->list_last;
167            
168 0           selectors->list = new_list;
169 0           selectors->list_last = NULL;
170 0           selectors->ending_token = entry->parser_ending_token;
171            
172 0           mycss_selectors_state_compound_selector_list(entry, NULL, true);
173            
174 0           (*new_list)->parent = current_list;
175            
176 0           mycss_entry_parser_list_push(entry, mycss_selectors_function_parser_not_or_matches_or_current_parser,
177             entry->parser_switch, entry->parser_ending_token, false);
178 0           }
179              
180 0           void mycss_selectors_function_begin_current(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
181             {
182 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CURRENT;
183              
184 0           mycss_selectors_t *selectors = entry->selectors;
185 0           mycss_selectors_list_t **new_list = (mycss_selectors_list_t**)(&selectors->entry_last->value);
186 0           mycss_selectors_list_t *current_list = selectors->list_last;
187            
188 0           selectors->list = new_list;
189 0           selectors->list_last = NULL;
190 0           selectors->ending_token = entry->parser_ending_token;
191            
192 0           mycss_selectors_state_compound_selector_list(entry, NULL, true);
193            
194 0           (*new_list)->parent = current_list;
195            
196 0           mycss_entry_parser_list_push(entry, mycss_selectors_function_parser_not_or_matches_or_current_parser,
197             entry->parser_switch, entry->parser_ending_token, false);
198 0           }
199              
200 0           void mycss_selectors_function_begin_nth_of_type(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
201             {
202 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE;
203              
204 0           entry->anb->entry = (mycss_an_plus_b_entry_t**)(&selector->value);
205            
206 0           entry->parser = mycss_an_plus_b_state_anb_begin;
207 0           entry->parser_switch = mycss_selectors_function_parser_nth_without_selectors;
208 0           }
209              
210 0           void mycss_selectors_function_begin_nth_last_column(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
211             {
212 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_COLUMN;
213              
214 0           entry->anb->entry = (mycss_an_plus_b_entry_t**)(&selector->value);
215            
216 0           entry->parser = mycss_an_plus_b_state_anb_begin;
217 0           entry->parser_switch = mycss_selectors_function_parser_nth_without_selectors;
218 0           }
219              
220 0           void mycss_selectors_function_begin_dir(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
221             {
222 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_DIR;
223 0           selector->value = NULL;
224            
225 0           entry->parser = mycss_selectors_function_parser_dir;
226 0           }
227              
228 0           void mycss_selectors_function_begin_matches(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
229             {
230 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_MATCHES;
231              
232 0           mycss_selectors_t *selectors = entry->selectors;
233 0           mycss_selectors_list_t **new_list = (mycss_selectors_list_t**)(&selectors->entry_last->value);
234 0           mycss_selectors_list_t *current_list = selectors->list_last;
235            
236 0           selectors->list = new_list;
237 0           selectors->list_last = NULL;
238 0           selectors->ending_token = entry->parser_ending_token;
239            
240 0           mycss_selectors_state_compound_selector_list(entry, NULL, true);
241            
242 0           (*new_list)->parent = current_list;
243            
244 0           mycss_entry_parser_list_push(entry, mycss_selectors_function_parser_not_or_matches_or_current_parser, entry->parser_switch, entry->parser_ending_token, false);
245 0           }
246              
247 0           void mycss_selectors_function_begin_nth_column(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
248             {
249 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_COLUMN;
250              
251 0           entry->anb->entry = (mycss_an_plus_b_entry_t**)(&selector->value);
252            
253 0           entry->parser = mycss_an_plus_b_state_anb_begin;
254 0           entry->parser_switch = mycss_selectors_function_parser_nth_without_selectors;
255 0           }
256              
257 0           void mycss_selectors_function_begin_lang(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
258             {
259 0           selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_LANG;
260 0           selector->value = NULL;
261            
262 0           entry->parser = mycss_selectors_function_parser_lang;
263 0           }
264              
265