« third_party/modest/source/modest/finder/finder.c
↑ Summary
third_party/modest/source/mycss/mycss.c »
| 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/an_plus_b.h" | ||||||||||||||
| 22 | #include "mycore/utils/resources.h" | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 74 | mycss_an_plus_b_t * mycss_an_plus_b_create(void) | |||||||||||||
| 25 | { | ||||||||||||||
| 26 | 74 | return (mycss_an_plus_b_t*)mycore_calloc(1, sizeof(mycss_an_plus_b_t)); | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 74 | mystatus_t mycss_an_plus_b_init(mycss_entry_t* entry, mycss_an_plus_b_t* anb) | |||||||||||||
| 30 | { | ||||||||||||||
| 31 | 74 | return MyCSS_STATUS_OK; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | mystatus_t mycss_an_plus_b_clean_all(mycss_an_plus_b_t* anb) | |||||||||||||
| 35 | { | ||||||||||||||
| 36 | 0 | return MyCSS_STATUS_OK; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | 74 | mycss_an_plus_b_t * mycss_an_plus_b_destroy(mycss_an_plus_b_t* anb, bool self_destroy) | |||||||||||||
| 40 | { | ||||||||||||||
| 41 | 74 | ▶ | if(anb == NULL) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 0 | return NULL; | |||||||||||||
| 43 | |||||||||||||||
| 44 | 74 | ▶ | if(self_destroy) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | 74 | mycore_free(anb); | |||||||||||||
| 46 | 74 | return NULL; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 0 | return anb; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 53 | //// An+B Entry | ||||||||||||||
| 54 | //// | ||||||||||||||
| 55 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 56 | 1 | mycss_an_plus_b_entry_t * mycss_an_plus_b_entry_create(mycss_entry_t* entry) | |||||||||||||
| 57 | { | ||||||||||||||
| 58 | 1 | return (mycss_an_plus_b_entry_t*)mchar_async_malloc(entry->mchar, | |||||||||||||
| 59 | entry->mchar_value_node_id, | ||||||||||||||
| 60 | sizeof(mycss_an_plus_b_entry_t)); | ||||||||||||||
| 61 | } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | 1 | void mycss_an_plus_b_entry_clean_all(mycss_an_plus_b_entry_t* anb_entry) | |||||||||||||
| 64 | { | ||||||||||||||
| 65 | 1 | memset(anb_entry, 0, sizeof(mycss_an_plus_b_entry_t)); | |||||||||||||
| 66 | 1 | } | |||||||||||||
| 67 | |||||||||||||||
| 68 | 0 | mycss_an_plus_b_entry_t * mycss_an_plus_b_entry_destroy(mycss_entry_t* entry, mycss_an_plus_b_entry_t* anb_entry, bool self_destroy) | |||||||||||||
| 69 | { | ||||||||||||||
| 70 | 0 | ▶ | if(anb_entry == NULL) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 71 | 0 | return NULL; | |||||||||||||
| 72 | |||||||||||||||
| 73 | 0 | ▶ | if(self_destroy) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 74 | 0 | mchar_async_free(entry->mchar, entry->mchar_value_node_id, (char*)anb_entry); | |||||||||||||
| 75 | 0 | return NULL; | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 0 | return anb_entry; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 82 | //// An+B Parser | ||||||||||||||
| 83 | //// | ||||||||||||||
| 84 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 85 | 0 | void mycss_an_plus_b_parser_expectations_error(mycss_entry_t* entry) | |||||||||||||
| 86 | { | ||||||||||||||
| 87 | 0 | mycss_an_plus_b_current_entry(entry)->is_broken = true; | |||||||||||||
| 88 | 0 | } | |||||||||||||
| 89 | |||||||||||||||
| 90 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 91 | //// An+B Serialization | ||||||||||||||
| 92 | //// | ||||||||||||||
| 93 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 94 | 1 | void mycss_an_plus_b_serialization(mycss_an_plus_b_entry_t* anb_entry, mycore_callback_serialize_f callback, void* context) | |||||||||||||
| 95 | { | ||||||||||||||
| 96 | char data[512]; | ||||||||||||||
| 97 | |||||||||||||||
| 98 | 1 | ▶ | if(anb_entry->a != 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 99 | 1 | int len = snprintf(data, 512, "%ld", anb_entry->a); | |||||||||||||
| 100 | |||||||||||||||
| 101 | 1 | ▶ | if(len > 0) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 102 | 1 | callback(data, (size_t)len, context); | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | 1 | callback("n", 1, context); | |||||||||||||
| 106 | |||||||||||||||
| 107 | 1 | ▶ | if(anb_entry->b != 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 108 | 1 | ▶ | if(anb_entry->b >= 0) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 109 | 1 | callback("+", 1, context); | |||||||||||||
| 110 | |||||||||||||||
| 111 | 1 | int len = snprintf(data, 512, "%ld", anb_entry->b); | |||||||||||||
| 112 | |||||||||||||||
| 113 | 1 | ▶ | if(len > 0) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 114 | 1 | callback(data, (size_t)len, context); | |||||||||||||
| 115 | } | ||||||||||||||
| 116 | 1 | } | |||||||||||||
| 117 | |||||||||||||||
| 118 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 119 | //// An+B State | ||||||||||||||
| 120 | //// | ||||||||||||||
| 121 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 122 | 1 | bool mycss_an_plus_b_state_anb_begin(mycss_entry_t* entry, mycss_token_t* token, bool last_response) | |||||||||||||
| 123 | { | ||||||||||||||
| 124 | 1 | mycss_an_plus_b_entry_t *anb_entry = mycss_an_plus_b_entry_create(entry); | |||||||||||||
| 125 | 1 | mycss_an_plus_b_entry_clean_all(anb_entry); | |||||||||||||
| 126 | |||||||||||||||
| 127 | 1 | *entry->anb->entry = anb_entry; | |||||||||||||
| 128 | |||||||||||||||
| 129 | 1 | return mycss_an_plus_b_state_anb(entry, token, true); | |||||||||||||
| 130 | } | ||||||||||||||
| 131 | |||||||||||||||
| 132 | 1 | bool mycss_an_plus_b_state_anb(mycss_entry_t* entry, mycss_token_t* token, bool last_response) | |||||||||||||
| 133 | { | ||||||||||||||
| 134 | 1 | mycss_an_plus_b_entry_t *anb_entry = mycss_an_plus_b_current_entry(entry); | |||||||||||||
| 135 | |||||||||||||||
| 136 | 1 | switch (token->type) { | |||||||||||||
| 137 | 0 | case MyCSS_TOKEN_TYPE_WHITESPACE: | |||||||||||||
| 138 | 0 | break; | |||||||||||||
| 139 | 0 | case MyCSS_TOKEN_TYPE_IDENT: { | |||||||||||||
| 140 | mycore_string_t str; | ||||||||||||||
| 141 | 0 | mycss_token_data_to_string(entry, token, &str, true, false); | |||||||||||||
| 142 | |||||||||||||||
| 143 | 0 | ▶ | if(mycore_strncasecmp(str.data, "-n-", 3) == 0) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 144 | { | ||||||||||||||
| 145 | 0 | anb_entry->a = -1; | |||||||||||||
| 146 | |||||||||||||||
| 147 | 0 | ▶ | if(str.length == 3) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 148 | 0 | anb_entry->b = -1; | |||||||||||||
| 149 | |||||||||||||||
| 150 | 0 | entry->parser = mycss_an_plus_b_state_anb_plus_n_hyphen; | |||||||||||||
| 151 | |||||||||||||||
| 152 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 153 | 0 | return true; | |||||||||||||
| 154 | } | ||||||||||||||
| 155 | /* -n-* */ | ||||||||||||||
| 156 | 0 | size_t len = str.length - 2; | |||||||||||||
| 157 | 0 | ▶ | if(mycss_convert_data_to_integer(&str.data[2], len, &anb_entry->b) != len) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 158 | /* parse error */ | ||||||||||||||
| 159 | 0 | anb_entry->is_broken = true; | |||||||||||||
| 160 | } | ||||||||||||||
| 161 | |||||||||||||||
| 162 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_hyphen_n_hyphen_asterisk_end"); | ||||||||||||||
| 163 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 164 | } | ||||||||||||||
| 165 | 0 | ▶ | else if(mycore_strncasecmp(str.data, "-n", 2) == 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 166 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_hyphen_n_end"); | ||||||||||||||
| 167 | |||||||||||||||
| 168 | 0 | anb_entry->a = -1; | |||||||||||||
| 169 | |||||||||||||||
| 170 | 0 | ▶ | if(str.length == 2) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 171 | 0 | entry->parser = mycss_an_plus_b_state_anb_plus_n; | |||||||||||||
| 172 | |||||||||||||||
| 173 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 174 | 0 | return true; | |||||||||||||
| 175 | } | ||||||||||||||
| 176 | |||||||||||||||
| 177 | 0 | size_t len = str.length - 2; | |||||||||||||
| 178 | 0 | ▶ | if(mycss_convert_data_to_integer(&str.data[2], len, &anb_entry->b) != len) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 179 | /* parse error */ | ||||||||||||||
| 180 | 0 | anb_entry->is_broken = true; | |||||||||||||
| 181 | } | ||||||||||||||
| 182 | |||||||||||||||
| 183 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 184 | } | ||||||||||||||
| 185 | 0 | ▶ | else if(mycore_strncasecmp(str.data, "n-", 2) == 0) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 186 | { | ||||||||||||||
| 187 | 0 | anb_entry->a = 1; | |||||||||||||
| 188 | |||||||||||||||
| 189 | 0 | ▶ | if(str.length == 2) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 190 | 0 | entry->parser = mycss_an_plus_b_state_anb_plus_n_hyphen; | |||||||||||||
| 191 | |||||||||||||||
| 192 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 193 | 0 | return true; | |||||||||||||
| 194 | } | ||||||||||||||
| 195 | |||||||||||||||
| 196 | 0 | size_t len = str.length - 1; | |||||||||||||
| 197 | 0 | ▶ | if(mycss_convert_data_to_integer(&str.data[1], len, &anb_entry->b) != len) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 198 | /* parse error */ | ||||||||||||||
| 199 | 0 | anb_entry->is_broken = true; | |||||||||||||
| 200 | } | ||||||||||||||
| 201 | |||||||||||||||
| 202 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_n"); | ||||||||||||||
| 203 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 204 | } | ||||||||||||||
| 205 | 0 | ▶ | else if(mycore_strncasecmp(str.data, "n", 1) == 0) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 206 | { | ||||||||||||||
| 207 | 0 | anb_entry->a = 1; | |||||||||||||
| 208 | |||||||||||||||
| 209 | 0 | ▶ | if(str.length == 1) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 210 | 0 | entry->parser = mycss_an_plus_b_state_anb_plus_n; | |||||||||||||
| 211 | |||||||||||||||
| 212 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 213 | 0 | return true; | |||||||||||||
| 214 | } | ||||||||||||||
| 215 | |||||||||||||||
| 216 | 0 | size_t len = str.length - 1; | |||||||||||||
| 217 | 0 | ▶ | if(mycss_convert_data_to_integer(&str.data[1], len, &anb_entry->b) != len) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 218 | /* parse error */ | ||||||||||||||
| 219 | 0 | anb_entry->is_broken = true; | |||||||||||||
| 220 | } | ||||||||||||||
| 221 | |||||||||||||||
| 222 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_n"); | ||||||||||||||
| 223 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 224 | } | ||||||||||||||
| 225 | 0 | ▶ | else if(mycore_strcasecmp(str.data, "even") == 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 226 | 0 | anb_entry->a = 2; | |||||||||||||
| 227 | 0 | anb_entry->b = 0; | |||||||||||||
| 228 | |||||||||||||||
| 229 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_e_v_e_n"); | ||||||||||||||
| 230 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 231 | } | ||||||||||||||
| 232 | 0 | ▶ | else if(mycore_strcasecmp(str.data, "odd") == 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 233 | 0 | anb_entry->a = 2; | |||||||||||||
| 234 | 0 | anb_entry->b = 1; | |||||||||||||
| 235 | |||||||||||||||
| 236 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_o_d_d"); | ||||||||||||||
| 237 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 238 | } | ||||||||||||||
| 239 | else { | ||||||||||||||
| 240 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 241 | |||||||||||||||
| 242 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 243 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 244 | 0 | return false; | |||||||||||||
| 245 | } | ||||||||||||||
| 246 | |||||||||||||||
| 247 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 248 | 0 | break; | |||||||||||||
| 249 | } | ||||||||||||||
| 250 | 0 | case MyCSS_TOKEN_TYPE_DELIM: { | |||||||||||||
| 251 | 0 | ▶ | if(*token->data == '+') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 252 | 0 | anb_entry->a = 1; | |||||||||||||
| 253 | |||||||||||||||
| 254 | 0 | entry->parser = mycss_an_plus_b_state_anb_plus; | |||||||||||||
| 255 | } | ||||||||||||||
| 256 | else { | ||||||||||||||
| 257 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 258 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 259 | 0 | return false; | |||||||||||||
| 260 | } | ||||||||||||||
| 261 | 0 | break; | |||||||||||||
| 262 | } | ||||||||||||||
| 263 | 0 | case MyCSS_TOKEN_TYPE_NUMBER: { | |||||||||||||
| 264 | mycore_string_t str; | ||||||||||||||
| 265 | 0 | mycss_token_data_to_string(entry, token, &str, true, false); | |||||||||||||
| 266 | |||||||||||||||
| 267 | 0 | mycss_convert_data_to_integer(str.data, str.length, &anb_entry->b); | |||||||||||||
| 268 | |||||||||||||||
| 269 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 270 | |||||||||||||||
| 271 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_number"); | ||||||||||||||
| 272 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 273 | 0 | break; | |||||||||||||
| 274 | } | ||||||||||||||
| 275 | 1 | case MyCSS_TOKEN_TYPE_DIMENSION: { | |||||||||||||
| 276 | mycore_string_t str; | ||||||||||||||
| 277 | 1 | mycss_token_data_to_string(entry, token, &str, true, false); | |||||||||||||
| 278 | |||||||||||||||
| 279 | 1 | size_t consumed_len = mycss_convert_data_to_integer(str.data, str.length, &anb_entry->a); | |||||||||||||
| 280 | |||||||||||||||
| 281 | 1 | ▶ | if(mycore_strncasecmp(&str.data[consumed_len], "n-", 2) == 0) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 282 | { | ||||||||||||||
| 283 | 0 | size_t rem = str.length - consumed_len; | |||||||||||||
| 284 | |||||||||||||||
| 285 | 0 | ▶ | if(rem == 2) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 286 | 0 | entry->parser = mycss_an_plus_b_state_anb_plus_n_hyphen; | |||||||||||||
| 287 | |||||||||||||||
| 288 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 289 | 1 | return true; | |||||||||||||
| 290 | } | ||||||||||||||
| 291 | |||||||||||||||
| 292 | 0 | rem -= 1; | |||||||||||||
| 293 | 0 | ▶ | if(mycss_convert_data_to_integer(&str.data[(consumed_len + 1)], rem, &anb_entry->b) != rem) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 294 | /* parse error */ | ||||||||||||||
| 295 | 0 | anb_entry->is_broken = true; | |||||||||||||
| 296 | } | ||||||||||||||
| 297 | |||||||||||||||
| 298 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_n_hyphen_asterisk_end"); | ||||||||||||||
| 299 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 300 | } | ||||||||||||||
| 301 | 1 | ▶ | else if(mycore_strncasecmp(&str.data[consumed_len], "n", 1) == 0) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 302 | { | ||||||||||||||
| 303 | 1 | size_t rem = (str.length - consumed_len) - 1; | |||||||||||||
| 304 | |||||||||||||||
| 305 | 1 | ▶ | if(rem == 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 306 | 1 | entry->parser = mycss_an_plus_b_state_anb_plus_n; | |||||||||||||
| 307 | |||||||||||||||
| 308 | 1 | mycore_string_destroy(&str, false); | |||||||||||||
| 309 | 1 | return true; | |||||||||||||
| 310 | } | ||||||||||||||
| 311 | |||||||||||||||
| 312 | 0 | ▶ | if(mycss_convert_data_to_integer(&str.data[(consumed_len + 1)], rem, &anb_entry->b) != rem) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 313 | /* parse error */ | ||||||||||||||
| 314 | 0 | anb_entry->is_broken = true; | |||||||||||||
| 315 | } | ||||||||||||||
| 316 | |||||||||||||||
| 317 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_n_end"); | ||||||||||||||
| 318 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 319 | } | ||||||||||||||
| 320 | else { | ||||||||||||||
| 321 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 322 | |||||||||||||||
| 323 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 324 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 325 | 0 | return false; | |||||||||||||
| 326 | } | ||||||||||||||
| 327 | |||||||||||||||
| 328 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 329 | 0 | break; | |||||||||||||
| 330 | } | ||||||||||||||
| 331 | 0 | default: { | |||||||||||||
| 332 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 333 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 334 | 0 | return false; | |||||||||||||
| 335 | } | ||||||||||||||
| 336 | } | ||||||||||||||
| 337 | |||||||||||||||
| 338 | 0 | return true; | |||||||||||||
| 339 | } | ||||||||||||||
| 340 | |||||||||||||||
| 341 | 0 | bool mycss_an_plus_b_state_anb_plus(mycss_entry_t* entry, mycss_token_t* token, bool last_response) | |||||||||||||
| 342 | { | ||||||||||||||
| 343 | 0 | mycss_an_plus_b_entry_t *anb_entry = mycss_an_plus_b_current_entry(entry); | |||||||||||||
| 344 | |||||||||||||||
| 345 | 0 | ▶ | switch (token->type) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 346 | 0 | case MyCSS_TOKEN_TYPE_IDENT: { | |||||||||||||
| 347 | mycore_string_t str; | ||||||||||||||
| 348 | 0 | mycss_token_data_to_string(entry, token, &str, true, false); | |||||||||||||
| 349 | |||||||||||||||
| 350 | 0 | ▶ | if(mycore_strncasecmp(str.data, "n-", 2) == 0) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 351 | { | ||||||||||||||
| 352 | 0 | ▶ | if(str.length == 2) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 353 | 0 | entry->parser = mycss_an_plus_b_state_anb_plus_n_hyphen; | |||||||||||||
| 354 | |||||||||||||||
| 355 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 356 | 0 | return true; | |||||||||||||
| 357 | } | ||||||||||||||
| 358 | |||||||||||||||
| 359 | 0 | size_t len = str.length - 1; | |||||||||||||
| 360 | 0 | ▶ | if(mycss_convert_data_to_integer(&str.data[1], len, &anb_entry->b) != len) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 361 | /* parse error */ | ||||||||||||||
| 362 | 0 | anb_entry->is_broken = true; | |||||||||||||
| 363 | } | ||||||||||||||
| 364 | |||||||||||||||
| 365 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_plus_n_hyphen_asterisk_end"); | ||||||||||||||
| 366 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 367 | } | ||||||||||||||
| 368 | 0 | ▶ | else if(mycore_strncasecmp(str.data, "n", 1) == 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 369 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_plus_n"); | ||||||||||||||
| 370 | 0 | entry->parser = mycss_an_plus_b_state_anb_plus_n; | |||||||||||||
| 371 | } | ||||||||||||||
| 372 | else { | ||||||||||||||
| 373 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 374 | |||||||||||||||
| 375 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 376 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 377 | 0 | return false; | |||||||||||||
| 378 | } | ||||||||||||||
| 379 | |||||||||||||||
| 380 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 381 | 0 | break; | |||||||||||||
| 382 | } | ||||||||||||||
| 383 | 0 | default: { | |||||||||||||
| 384 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 385 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 386 | 0 | return false; | |||||||||||||
| 387 | } | ||||||||||||||
| 388 | } | ||||||||||||||
| 389 | |||||||||||||||
| 390 | 0 | return true; | |||||||||||||
| 391 | } | ||||||||||||||
| 392 | |||||||||||||||
| 393 | 0 | bool mycss_an_plus_b_state_anb_plus_n_hyphen(mycss_entry_t* entry, mycss_token_t* token, bool last_response) | |||||||||||||
| 394 | { | ||||||||||||||
| 395 | 0 | ▶ | if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 396 | 0 | return true; | |||||||||||||
| 397 | |||||||||||||||
| 398 | 0 | mycss_an_plus_b_entry_t *anb_entry = mycss_an_plus_b_current_entry(entry); | |||||||||||||
| 399 | |||||||||||||||
| 400 | 0 | ▶ | if(token->type == MyCSS_TOKEN_TYPE_NUMBER) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 401 | /* begin from 0-9 */ | ||||||||||||||
| 402 | 0 | ▶ | if(mycore_string_chars_num_map[ (const unsigned char)(*token->data) ] != 0xff) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 403 | { | ||||||||||||||
| 404 | mycore_string_t str; | ||||||||||||||
| 405 | 0 | mycss_token_data_to_string(entry, token, &str, true, false); | |||||||||||||
| 406 | |||||||||||||||
| 407 | long res; | ||||||||||||||
| 408 | 0 | mycss_convert_data_to_integer(str.data, str.length, &res); | |||||||||||||
| 409 | |||||||||||||||
| 410 | 0 | anb_entry->b = -res; | |||||||||||||
| 411 | |||||||||||||||
| 412 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_plus_n_hyphen_zero_hyphen_nine_end"); | ||||||||||||||
| 413 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 414 | |||||||||||||||
| 415 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 416 | } | ||||||||||||||
| 417 | else { | ||||||||||||||
| 418 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 419 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 420 | 0 | return false; | |||||||||||||
| 421 | } | ||||||||||||||
| 422 | } | ||||||||||||||
| 423 | else { | ||||||||||||||
| 424 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 425 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 426 | 0 | return false; | |||||||||||||
| 427 | } | ||||||||||||||
| 428 | |||||||||||||||
| 429 | 0 | return true; | |||||||||||||
| 430 | } | ||||||||||||||
| 431 | |||||||||||||||
| 432 | 1 | bool mycss_an_plus_b_state_anb_plus_n(mycss_entry_t* entry, mycss_token_t* token, bool last_response) | |||||||||||||
| 433 | { | ||||||||||||||
| 434 | 1 | ▶ | if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 435 | 0 | return true; | |||||||||||||
| 436 | |||||||||||||||
| 437 | 1 | mycss_an_plus_b_entry_t *anb_entry = mycss_an_plus_b_current_entry(entry); | |||||||||||||
| 438 | |||||||||||||||
| 439 | 1 | switch (token->type) { | |||||||||||||
| 440 | 0 | case MyCSS_TOKEN_TYPE_DELIM: { | |||||||||||||
| 441 | 0 | ▶ | if(*token->data == '+') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 442 | 0 | entry->parser = mycss_an_plus_b_state_anb_plus_n_plus; | |||||||||||||
| 443 | } | ||||||||||||||
| 444 | 0 | ▶ | else if(*token->data == '-') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 445 | 0 | entry->parser = mycss_an_plus_b_state_anb_plus_n_hyphen; | |||||||||||||
| 446 | } | ||||||||||||||
| 447 | else { | ||||||||||||||
| 448 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 449 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 450 | 0 | return false; | |||||||||||||
| 451 | } | ||||||||||||||
| 452 | 0 | break; | |||||||||||||
| 453 | } | ||||||||||||||
| 454 | 1 | case MyCSS_TOKEN_TYPE_NUMBER: { | |||||||||||||
| 455 | 1 | ▶ | if(*token->data == '+' || *token->data == '-') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 456 | 1 | { | |||||||||||||
| 457 | mycore_string_t str; | ||||||||||||||
| 458 | 1 | mycss_token_data_to_string(entry, token, &str, true, false); | |||||||||||||
| 459 | |||||||||||||||
| 460 | 1 | mycss_convert_data_to_integer(str.data, str.length, &anb_entry->b); | |||||||||||||
| 461 | |||||||||||||||
| 462 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_plus_n_begin_plus_vertical_bar_hyphen"); | ||||||||||||||
| 463 | 1 | entry->parser = entry->parser_switch; | |||||||||||||
| 464 | |||||||||||||||
| 465 | 1 | mycore_string_destroy(&str, false); | |||||||||||||
| 466 | } | ||||||||||||||
| 467 | else { | ||||||||||||||
| 468 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 469 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 470 | 0 | return false; | |||||||||||||
| 471 | } | ||||||||||||||
| 472 | 1 | break; | |||||||||||||
| 473 | } | ||||||||||||||
| 474 | 0 | default: { | |||||||||||||
| 475 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 476 | 0 | return false; | |||||||||||||
| 477 | } | ||||||||||||||
| 478 | } | ||||||||||||||
| 479 | |||||||||||||||
| 480 | 1 | return true; | |||||||||||||
| 481 | } | ||||||||||||||
| 482 | |||||||||||||||
| 483 | 0 | bool mycss_an_plus_b_state_anb_plus_n_plus(mycss_entry_t* entry, mycss_token_t* token, bool last_response) | |||||||||||||
| 484 | { | ||||||||||||||
| 485 | 0 | ▶ | if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 486 | 0 | return true; | |||||||||||||
| 487 | |||||||||||||||
| 488 | 0 | mycss_an_plus_b_entry_t *anb_entry = mycss_an_plus_b_current_entry(entry); | |||||||||||||
| 489 | |||||||||||||||
| 490 | 0 | ▶ | if(token->type == MyCSS_TOKEN_TYPE_NUMBER) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 491 | /* begin from 0-9 */ | ||||||||||||||
| 492 | 0 | ▶ | if(mycore_string_chars_num_map[ (const unsigned char)(*token->data) ] != 0xff) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 493 | { | ||||||||||||||
| 494 | mycore_string_t str; | ||||||||||||||
| 495 | 0 | mycss_token_data_to_string(entry, token, &str, true, false); | |||||||||||||
| 496 | |||||||||||||||
| 497 | 0 | mycss_convert_data_to_integer(str.data, str.length, &anb_entry->b); | |||||||||||||
| 498 | |||||||||||||||
| 499 | MyCORE_DEBUG("mycss_an_plus_b_state_anb_plus_n_plus_zero_hyphen_nine_end"); | ||||||||||||||
| 500 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 501 | |||||||||||||||
| 502 | 0 | mycore_string_destroy(&str, false); | |||||||||||||
| 503 | } | ||||||||||||||
| 504 | else { | ||||||||||||||
| 505 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 506 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 507 | 0 | return false; | |||||||||||||
| 508 | } | ||||||||||||||
| 509 | } | ||||||||||||||
| 510 | else { | ||||||||||||||
| 511 | 0 | mycss_an_plus_b_parser_expectations_error(entry); | |||||||||||||
| 512 | 0 | entry->parser = entry->parser_switch; | |||||||||||||
| 513 | 0 | return false; | |||||||||||||
| 514 | } | ||||||||||||||
| 515 | |||||||||||||||
| 516 | 0 | return true; | |||||||||||||
| 517 | } | ||||||||||||||
| 518 | |||||||||||||||
| 519 | |||||||||||||||
| 520 | |||||||||||||||