« third_party/modest/source/mycore/utils/mhash.c
↑ Summary
third_party/modest/source/mycss/declaration/default.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/check.h" | ||||||||||||||
| 22 | #include "mycss/tokenizer_resource.h" | ||||||||||||||
| 23 | |||||||||||||||
| 24 | #define MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED \ | ||||||||||||||
| 25 | if(css_offset >= buffer->size) { \ | ||||||||||||||
| 26 | buffer = buffer->next; \ | ||||||||||||||
| 27 | css_offset = 0; \ | ||||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 31 | //// For chunk | ||||||||||||||
| 32 | //// | ||||||||||||||
| 33 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 34 | 0 | bool mycss_check_two_code_points_valid_escape_chunk(mycss_entry_t* entry, size_t css_offset) | |||||||||||||
| 35 | { | ||||||||||||||
| 36 | 0 | mycore_incoming_buffer_t* buffer = entry->current_buffer; | |||||||||||||
| 37 | |||||||||||||||
| 38 | 0 | ▶ | MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | |||||||||||||||
| 40 | 0 | ▶ | if(buffer->data[css_offset] == '\\') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | 0 | ++css_offset; | |||||||||||||
| 42 | |||||||||||||||
| 43 | 0 | ▶ | MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | |||||||||||||||
| 45 | 0 | ▶ | if(buffer->data[css_offset] != '\n') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | 0 | return true; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 0 | return false; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 0 | bool mycss_check_three_code_points_would_start_identifier_chunk(mycss_entry_t* entry, size_t css_offset) | |||||||||||||
| 53 | { | ||||||||||||||
| 54 | 0 | mycore_incoming_buffer_t* buffer = entry->current_buffer; | |||||||||||||
| 55 | |||||||||||||||
| 56 | 0 | ▶ | MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 0 | const unsigned char *u_css = (const unsigned char*)buffer->data; | |||||||||||||
| 58 | |||||||||||||||
| 59 | 0 | ▶ | if(buffer->data[css_offset] == '-') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | { | ||||||||||||||
| 61 | 0 | ++css_offset; | |||||||||||||
| 62 | |||||||||||||||
| 63 | 0 | ▶ | MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | 0 | u_css = (const unsigned char*)buffer->data; | |||||||||||||
| 65 | |||||||||||||||
| 66 | 0 | ▶ | if(buffer->data[css_offset] == '-' || | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | 0 | mycss_begin_chars_state_map[ u_css[css_offset] ] == MyCSS_TOKENIZER_STATE_NAME_START_CODE_POINT || | |||||||||||||
| 68 | 0 | mycss_check_two_code_points_valid_escape_chunk(entry, css_offset)) | |||||||||||||
| 69 | { | ||||||||||||||
| 70 | 0 | return true; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | } | ||||||||||||||
| 73 | 0 | ▶ | else if(mycss_begin_chars_state_map[ u_css[css_offset] ] == MyCSS_TOKENIZER_STATE_NAME_START_CODE_POINT) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 74 | 0 | return true; | |||||||||||||
| 75 | } | ||||||||||||||
| 76 | 0 | ▶ | else if(buffer->data[css_offset] == '\\' && mycss_check_two_code_points_valid_escape_chunk(entry, css_offset)) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 77 | 0 | return true; | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | return false; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 0 | bool mycss_check_three_code_points_would_start_number_chunk(mycss_entry_t* entry, size_t css_offset) | |||||||||||||
| 84 | { | ||||||||||||||
| 85 | 0 | mycore_incoming_buffer_t* buffer = entry->current_buffer; | |||||||||||||
| 86 | |||||||||||||||
| 87 | 0 | ▶ | MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 88 | |||||||||||||||
| 89 | 0 | ▶ | if(buffer->data[css_offset] == '-' || buffer->data[css_offset] == '+') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 90 | { | ||||||||||||||
| 91 | 0 | ++css_offset; | |||||||||||||
| 92 | |||||||||||||||
| 93 | 0 | ▶ | MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 94 | |||||||||||||||
| 95 | 0 | ▶ | if(buffer->data[css_offset] >= '0' && buffer->data[css_offset] <= '9') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 96 | 0 | return true; | |||||||||||||
| 97 | |||||||||||||||
| 98 | 0 | ▶ | if(buffer->data[css_offset] == '.') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 99 | 0 | ++css_offset; | |||||||||||||
| 100 | |||||||||||||||
| 101 | 0 | ▶ | MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 102 | |||||||||||||||
| 103 | 0 | ▶ | if(buffer->data[css_offset] >= '0' && buffer->data[css_offset] <= '9') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 104 | 0 | return true; | |||||||||||||
| 105 | } | ||||||||||||||
| 106 | } | ||||||||||||||
| 107 | 0 | ▶ | else if(buffer->data[css_offset] == '.') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 108 | 0 | ++css_offset; | |||||||||||||
| 109 | |||||||||||||||
| 110 | 0 | ▶ | MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 111 | |||||||||||||||
| 112 | 0 | ▶ | if(buffer->data[css_offset] >= '0' && buffer->data[css_offset] <= '9') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 113 | 0 | return true; | |||||||||||||
| 114 | } | ||||||||||||||
| 115 | 0 | ▶ | else if(buffer->data[css_offset] >= '0' && buffer->data[css_offset] <= '9') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 116 | 0 | return true; | |||||||||||||
| 117 | |||||||||||||||
| 118 | 0 | return false; | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | |||||||||||||||
| 121 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 122 | //// basic checks | ||||||||||||||
| 123 | //// | ||||||||||||||
| 124 | ///////////////////////////////////////////////////////// | ||||||||||||||
| 125 | 0 | bool mycss_check_three_code_points_would_start_identifier(mycss_entry_t* entry, mycss_token_t* token, const char* css, size_t css_offset, size_t css_size) | |||||||||||||
| 126 | { | ||||||||||||||
| 127 | 0 | ▶ | if(css_offset >= css_size) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 128 | 0 | return mycss_check_three_code_points_would_start_identifier_chunk(entry, css_offset); | |||||||||||||
| 129 | |||||||||||||||
| 130 | 0 | const unsigned char *u_css = (const unsigned char*)css; | |||||||||||||
| 131 | |||||||||||||||
| 132 | 0 | ▶ | if(css[css_offset] == '-') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 133 | { | ||||||||||||||
| 134 | 0 | ++css_offset; | |||||||||||||
| 135 | |||||||||||||||
| 136 | 0 | ▶ | if(css[css_offset] == '-' || | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 137 | 0 | mycss_begin_chars_state_map[ u_css[css_offset] ] == MyCSS_TOKENIZER_STATE_NAME_START_CODE_POINT || | |||||||||||||
| 138 | 0 | mycss_check_two_code_points_valid_escape(entry, token, css, css_offset, css_size)) | |||||||||||||
| 139 | { | ||||||||||||||
| 140 | 0 | return true; | |||||||||||||
| 141 | } | ||||||||||||||
| 142 | } | ||||||||||||||
| 143 | 0 | ▶ | else if(mycss_begin_chars_state_map[ u_css[css_offset] ] == MyCSS_TOKENIZER_STATE_NAME_START_CODE_POINT) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 144 | 0 | return true; | |||||||||||||
| 145 | } | ||||||||||||||
| 146 | 0 | ▶ | else if(css[css_offset] == '\\' && mycss_check_two_code_points_valid_escape(entry, token, css, css_offset, css_size)) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 147 | 0 | return true; | |||||||||||||
| 148 | } | ||||||||||||||
| 149 | |||||||||||||||
| 150 | 0 | return false; | |||||||||||||
| 151 | } | ||||||||||||||
| 152 | |||||||||||||||
| 153 | 0 | bool mycss_check_two_code_points_valid_escape(mycss_entry_t* entry, mycss_token_t* token, const char* css, size_t css_offset, size_t css_size) | |||||||||||||
| 154 | { | ||||||||||||||
| 155 | 0 | ▶ | if(css_offset >= css_size) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 156 | 0 | return mycss_check_two_code_points_valid_escape_chunk(entry, css_offset); | |||||||||||||
| 157 | |||||||||||||||
| 158 | 0 | ▶ | if(css[css_offset] == '\\' && css[(css_offset + 1)] != '\n') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 159 | 0 | return true; | |||||||||||||
| 160 | |||||||||||||||
| 161 | 0 | return false; | |||||||||||||
| 162 | } | ||||||||||||||
| 163 | |||||||||||||||
| 164 | 0 | bool mycss_check_three_code_points_would_start_number(mycss_entry_t* entry, mycss_token_t* token, const char* css, size_t css_offset, size_t css_size) | |||||||||||||
| 165 | { | ||||||||||||||
| 166 | 0 | ▶ | if(css_offset >= css_size) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 167 | 0 | return mycss_check_three_code_points_would_start_number_chunk(entry, css_offset); | |||||||||||||
| 168 | |||||||||||||||
| 169 | 0 | ▶ | if(css[css_offset] == '-' || css[css_offset] == '+') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 170 | { | ||||||||||||||
| 171 | 0 | ++css_offset; | |||||||||||||
| 172 | |||||||||||||||
| 173 | 0 | ▶ | if(css[css_offset] >= '0' && css[css_offset] <= '9') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 174 | 0 | return true; | |||||||||||||
| 175 | |||||||||||||||
| 176 | 0 | ▶ | if(css[css_offset] == '.') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 177 | 0 | ++css_offset; | |||||||||||||
| 178 | |||||||||||||||
| 179 | 0 | ▶ | if(css[css_offset] >= '0' && css[css_offset] <= '9') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 180 | 0 | return true; | |||||||||||||
| 181 | } | ||||||||||||||
| 182 | } | ||||||||||||||
| 183 | 0 | ▶ | else if(css[css_offset] == '.') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 184 | 0 | ++css_offset; | |||||||||||||
| 185 | |||||||||||||||
| 186 | 0 | ▶ | if(css[css_offset] >= '0' && css[css_offset] <= '9') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 187 | 0 | return true; | |||||||||||||
| 188 | } | ||||||||||||||
| 189 | 0 | ▶ | else if(css[css_offset] >= '0' && css[css_offset] <= '9') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 190 | 0 | return true; | |||||||||||||
| 191 | |||||||||||||||
| 192 | 0 | return false; | |||||||||||||
| 193 | } | ||||||||||||||
| 194 | |||||||||||||||
| 195 | |||||||||||||||