| 1 |
|
| /* |
| 2 |
|
| Copyright 2015-2016 Alexander Borisov |
| 3 |
|
| |
| 4 |
|
| Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
|
| you may not use this file except in compliance with the License. |
| 6 |
|
| You may obtain a copy of the License at |
| 7 |
|
| |
| 8 |
|
| http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| |
| 10 |
|
| Unless required by applicable law or agreed to in writing, software |
| 11 |
|
| distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
|
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
|
| See the License for the specific language governing permissions and |
| 14 |
|
| limitations under the License. |
| 15 |
|
| |
| 16 |
|
| Author: lex.borisov@gmail.com (Alexander Borisov) |
| 17 |
|
| */ |
| 18 |
|
| |
| 19 |
|
| #include "myhtml/utils/resources.h" |
| 20 |
|
| #include "myhtml/mystring.h" |
| 21 |
|
| |
| 22 |
|
| |
| 23 |
0 |
| char * myhtml_string_init(mchar_async_t *mchar, size_t node_idx, myhtml_string_t* str, size_t size) |
| 24 |
|
| { |
| 25 |
0 |
| str->data = mchar_async_malloc(mchar, node_idx, size); |
| 26 |
0 |
| str->size = size; |
| 27 |
0 |
| str->node_idx = node_idx; |
| 28 |
0 |
| str->mchar = mchar; |
| 29 |
|
| |
| 30 |
0 |
| myhtml_string_clean(str); |
| 31 |
|
| |
| 32 |
0 |
| return str->data; |
| 33 |
|
| } |
| 34 |
|
| |
| 35 |
0 |
| void myhtml_string_clean(myhtml_string_t* str) |
| 36 |
|
| { |
| 37 |
0 |
| str->length = 0; |
| 38 |
0 |
| } |
| 39 |
|
| |
| 40 |
1 |
| void myhtml_string_clean_all(myhtml_string_t* str) |
| 41 |
|
| { |
| 42 |
1 |
| memset(str, 0, sizeof(myhtml_string_t)); |
| 43 |
1 |
| } |
| 44 |
|
| |
| 45 |
0 |
| myhtml_string_t * myhtml_string_destroy(myhtml_string_t* str, bool destroy_obj) |
| 46 |
|
| { |
| 47 |
0 |
▶ | if(str == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(str == NULL) |
0 |
0 |
0 |
|
| 48 |
0 |
| return NULL; |
| 49 |
|
| |
| 50 |
0 |
▶ | if(str->data && str->mchar && str->node_idx) |
Branch: 3 branches
| Branch | True | False | Total |
| if(str->data && str->mchar && str->node_idx) |
0 |
0 |
0 |
| if(str->data && str->mchar && str->node_idx) |
0 |
0 |
0 |
| if(str->data && str->mchar && str->node_idx) |
0 |
0 |
0 |
|
| 51 |
0 |
| mchar_async_free(str->mchar, str->node_idx, str->data); |
| 52 |
|
| |
| 53 |
0 |
▶ | if(destroy_obj && str) |
Branch: 2 branches
| Branch | True | False | Total |
| if(destroy_obj && str) |
0 |
0 |
0 |
| if(destroy_obj && str) |
0 |
0 |
0 |
|
| 54 |
0 |
| free(str); |
| 55 |
|
| |
| 56 |
0 |
| return NULL; |
| 57 |
|
| } |
| 58 |
|
| |
| 59 |
0 |
| char * myhtml_string_data_alloc(mchar_async_t *mchar, size_t node_id, size_t size) |
| 60 |
|
| { |
| 61 |
0 |
| return mchar_async_malloc(mchar, node_id, size); |
| 62 |
|
| } |
| 63 |
|
| |
| 64 |
0 |
| char * myhtml_string_data_realloc(mchar_async_t *mchar, size_t node_id, char *data, size_t len_to_copy, size_t size) |
| 65 |
|
| { |
| 66 |
0 |
| return mchar_async_realloc(mchar, node_id, data, len_to_copy, size); |
| 67 |
|
| } |
| 68 |
|
| |
| 69 |
0 |
| void myhtml_string_data_free(mchar_async_t *mchar, size_t node_id, char *data) |
| 70 |
|
| { |
| 71 |
0 |
| mchar_async_free(mchar, node_id, data); |
| 72 |
0 |
| } |
| 73 |
|
| |
| 74 |
0 |
| char * myhtml_string_data(myhtml_string_t *str) |
| 75 |
|
| { |
| 76 |
0 |
▶ | if(str == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(str == NULL) |
0 |
0 |
0 |
|
| 77 |
0 |
| return NULL; |
| 78 |
|
| |
| 79 |
0 |
| return str->data; |
| 80 |
|
| } |
| 81 |
|
| |
| 82 |
0 |
| size_t myhtml_string_length(myhtml_string_t *str) |
| 83 |
|
| { |
| 84 |
0 |
▶ | if(str == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(str == NULL) |
0 |
0 |
0 |
|
| 85 |
0 |
| return 0; |
| 86 |
|
| |
| 87 |
0 |
| return str->length; |
| 88 |
|
| } |
| 89 |
|
| |
| 90 |
0 |
| size_t myhtml_string_size(myhtml_string_t *str) |
| 91 |
|
| { |
| 92 |
0 |
▶ | if(str == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(str == NULL) |
0 |
0 |
0 |
|
| 93 |
0 |
| return 0; |
| 94 |
|
| |
| 95 |
0 |
| return str->size; |
| 96 |
|
| } |
| 97 |
|
| |
| 98 |
0 |
| char * myhtml_string_data_set(myhtml_string_t *str, char *data) |
| 99 |
|
| { |
| 100 |
0 |
▶ | if(str == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(str == NULL) |
0 |
0 |
0 |
|
| 101 |
0 |
| return NULL; |
| 102 |
|
| |
| 103 |
0 |
| str->data = data; |
| 104 |
0 |
| return str->data; |
| 105 |
|
| } |
| 106 |
|
| |
| 107 |
0 |
| size_t myhtml_string_size_set(myhtml_string_t *str, size_t size) |
| 108 |
|
| { |
| 109 |
0 |
▶ | if(str == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(str == NULL) |
0 |
0 |
0 |
|
| 110 |
0 |
| return 0; |
| 111 |
|
| |
| 112 |
0 |
| str->size = size; |
| 113 |
0 |
| return str->size; |
| 114 |
|
| } |
| 115 |
|
| |
| 116 |
0 |
| size_t myhtml_string_length_set(myhtml_string_t *str, size_t length) |
| 117 |
|
| { |
| 118 |
0 |
▶ | if(str == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(str == NULL) |
0 |
0 |
0 |
|
| 119 |
0 |
| return 0; |
| 120 |
|
| |
| 121 |
0 |
| str->length = length; |
| 122 |
0 |
| return str->length; |
| 123 |
|
| } |
| 124 |
|
| |
| 125 |
0 |
| char * myhtml_string_realloc(mchar_async_t *mchar, size_t node_id, myhtml_string_t *str, size_t new_size) |
| 126 |
|
| { |
| 127 |
0 |
▶ | if(str == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(str == NULL) |
0 |
0 |
0 |
|
| 128 |
0 |
| return 0; |
| 129 |
|
| |
| 130 |
|
| char *tmp; |
| 131 |
|
| |
| 132 |
0 |
▶ | if(str->data) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->data) { |
0 |
0 |
0 |
|
| 133 |
0 |
| tmp = mchar_async_realloc(str->mchar, str->node_idx, str->data, str->length, new_size); |
| 134 |
|
| } |
| 135 |
|
| else { |
| 136 |
0 |
| tmp = mchar_async_malloc(mchar, node_id, new_size); |
| 137 |
|
| |
| 138 |
0 |
| str->mchar = mchar; |
| 139 |
0 |
| str->node_idx = node_id; |
| 140 |
|
| } |
| 141 |
|
| |
| 142 |
0 |
▶ | if(tmp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tmp) { |
0 |
0 |
0 |
|
| 143 |
0 |
| str->size = new_size; |
| 144 |
0 |
| str->data = tmp; |
| 145 |
|
| } |
| 146 |
|
| else |
| 147 |
0 |
| return NULL; |
| 148 |
|
| |
| 149 |
0 |
| return str->data; |
| 150 |
|
| } |
| 151 |
|
| |
| 152 |
0 |
| bool myhtml_string_release(myhtml_string_t* str, size_t size) |
| 153 |
|
| { |
| 154 |
0 |
| char* tmp = mchar_async_realloc(str->mchar, str->node_idx, str->data, str->length, size); |
| 155 |
|
| |
| 156 |
0 |
▶ | if(tmp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tmp) { |
0 |
0 |
0 |
|
| 157 |
0 |
| str->size = size; |
| 158 |
0 |
| str->data = tmp; |
| 159 |
|
| } |
| 160 |
|
| else |
| 161 |
0 |
| return false; |
| 162 |
|
| |
| 163 |
0 |
| return true; |
| 164 |
|
| } |
| 165 |
|
| |
| 166 |
0 |
| void _myhtml_string_charef_append(myhtml_string_t* str, const char sm) |
| 167 |
|
| { |
| 168 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 2, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 2, 32); |
0 |
0 |
0 |
|
| 169 |
|
| |
| 170 |
0 |
| str->data[str->length] = sm; |
| 171 |
0 |
| str->length++; |
| 172 |
|
| |
| 173 |
0 |
| str->data[str->length] = '\0'; |
| 174 |
0 |
| } |
| 175 |
|
| |
| 176 |
0 |
| size_t _myhtml_string_append_char_references_state_0(myhtml_string_char_ref_chunk_t *chunk, myhtml_string_t* str, const char* buff, size_t offset, size_t size) |
| 177 |
|
| { |
| 178 |
0 |
| size_t tmp_offset = offset; |
| 179 |
|
| |
| 180 |
0 |
▶ | while(offset < size) |
Branch: 1 branch
| Branch | True | False | Total |
| while(offset < size) |
0 |
0 |
0 |
|
| 181 |
|
| { |
| 182 |
0 |
▶ | if(buff[offset] == '&') |
Branch: 1 branch
| Branch | True | False | Total |
| if(buff[offset] == '&') |
0 |
0 |
0 |
|
| 183 |
|
| { |
| 184 |
0 |
▶ | if(chunk->encoding == MyHTML_ENCODING_UTF_8) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(chunk->encoding == MyHTML_ENCODING_UTF_8) { |
0 |
0 |
0 |
|
| 185 |
0 |
| myhtml_string_append_with_preprocessing(str, &buff[tmp_offset], (offset - tmp_offset), chunk->emit_null_char); |
| 186 |
|
| } |
| 187 |
|
| else { |
| 188 |
0 |
| myhtml_string_append_chunk_with_convert_encoding_with_preprocessing(str, &chunk->res, &buff[tmp_offset], (offset - tmp_offset), chunk->encoding); |
| 189 |
0 |
| myhtml_encoding_result_clean(&chunk->res); |
| 190 |
|
| } |
| 191 |
|
| |
| 192 |
0 |
| chunk->begin = str->length; |
| 193 |
0 |
| chunk->state = 1; |
| 194 |
|
| |
| 195 |
0 |
| _myhtml_string_charef_append(str, buff[offset]); |
| 196 |
|
| |
| 197 |
0 |
| offset++; |
| 198 |
0 |
| return offset; |
| 199 |
|
| } |
| 200 |
|
| |
| 201 |
0 |
| offset++; |
| 202 |
|
| } |
| 203 |
|
| |
| 204 |
0 |
▶ | if(chunk->encoding == MyHTML_ENCODING_UTF_8) |
Branch: 1 branch
| Branch | True | False | Total |
| if(chunk->encoding == MyHTML_ENCODING_UTF_8) |
0 |
0 |
0 |
|
| 205 |
0 |
| myhtml_string_append_with_preprocessing(str, &buff[tmp_offset], (offset - tmp_offset), chunk->emit_null_char); |
| 206 |
|
| else |
| 207 |
0 |
| myhtml_string_append_chunk_with_convert_encoding_with_preprocessing(str, &chunk->res, &buff[tmp_offset], (offset - tmp_offset), chunk->encoding); |
| 208 |
|
| |
| 209 |
0 |
| return offset; |
| 210 |
|
| } |
| 211 |
|
| |
| 212 |
0 |
| size_t _myhtml_string_append_char_references_state_1(myhtml_string_char_ref_chunk_t *chunk, myhtml_string_t* str, const char* buff, size_t offset, size_t size) |
| 213 |
|
| { |
| 214 |
0 |
▶ | if(buff[offset] == '#') |
Branch: 1 branch
| Branch | True | False | Total |
| if(buff[offset] == '#') |
0 |
0 |
0 |
|
| 215 |
|
| { |
| 216 |
0 |
| _myhtml_string_charef_append(str, buff[offset]); |
| 217 |
0 |
| offset++; |
| 218 |
|
| |
| 219 |
0 |
| chunk->l_data = 0; |
| 220 |
|
| |
| 221 |
0 |
▶ | if(offset >= size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(offset >= size) { |
0 |
0 |
0 |
|
| 222 |
0 |
| chunk->state = 3; |
| 223 |
0 |
| return offset; |
| 224 |
|
| } |
| 225 |
|
| |
| 226 |
0 |
▶ | if(buff[offset] == 'x' || buff[offset] == 'X') { |
Branch: 2 branches
| Branch | True | False | Total |
| if(buff[offset] == 'x' || buff[offset] == 'X') { |
0 |
0 |
0 |
| if(buff[offset] == 'x' || buff[offset] == 'X') { |
0 |
0 |
0 |
|
| 227 |
0 |
| _myhtml_string_charef_append(str, buff[offset]); |
| 228 |
0 |
| offset++; |
| 229 |
|
| |
| 230 |
0 |
| chunk->state = 5; |
| 231 |
|
| } |
| 232 |
|
| else |
| 233 |
0 |
| chunk->state = 4; |
| 234 |
|
| } |
| 235 |
|
| else { |
| 236 |
0 |
| chunk->charef_res.last_entry = NULL; |
| 237 |
0 |
| chunk->charef_res.curr_entry = myhtml_charef_get_first_position(buff[offset]); |
| 238 |
|
| |
| 239 |
0 |
▶ | if(chunk->charef_res.curr_entry->ch == '\0') |
Branch: 1 branch
| Branch | True | False | Total |
| if(chunk->charef_res.curr_entry->ch == '\0') |
0 |
0 |
0 |
|
| 240 |
0 |
| chunk->state = 0; |
| 241 |
|
| else { |
| 242 |
0 |
| chunk->state = 2; |
| 243 |
|
| |
| 244 |
0 |
| _myhtml_string_charef_append(str, buff[offset]); |
| 245 |
0 |
| offset++; |
| 246 |
|
| } |
| 247 |
|
| } |
| 248 |
|
| |
| 249 |
0 |
| return offset; |
| 250 |
|
| } |
| 251 |
|
| |
| 252 |
0 |
| size_t _myhtml_string_append_char_references_state_2(myhtml_string_char_ref_chunk_t *chunk, myhtml_string_t* str, const char* buff, size_t offset, size_t size) |
| 253 |
|
| { |
| 254 |
0 |
| size_t tmp_offset = offset; |
| 255 |
|
| |
| 256 |
0 |
| const charef_entry_t *current_entry = myhtml_charef_find_by_pos(chunk->charef_res.curr_entry->next, buff, &offset, size, &chunk->charef_res); |
| 257 |
|
| |
| 258 |
0 |
▶ | if(chunk->charef_res.is_done) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(chunk->charef_res.is_done) { |
0 |
0 |
0 |
|
| 259 |
0 |
| chunk->state = 0; |
| 260 |
|
| |
| 261 |
0 |
▶ | if(buff[offset] == ';') |
Branch: 1 branch
| Branch | True | False | Total |
| if(buff[offset] == ';') |
0 |
0 |
0 |
|
| 262 |
0 |
| offset++; |
| 263 |
|
| else { |
| 264 |
0 |
▶ | if(chunk->is_attributes && |
Branch: 1 branch
| Branch | True | False | Total |
| if(chunk->is_attributes && |
0 |
0 |
0 |
|
| 265 |
0 |
▶ | (buff[offset] == '=' || myhtml_string_alphanumeric_character[ (unsigned char)buff[offset] ] != 0xff)) |
Branch: 2 branches
| Branch | True | False | Total |
| (buff[offset] == '=' || myhtml_string_alphanumeric_character[ (unsigned char)buff[offset] ] != 0xff)) |
0 |
0 |
0 |
| (buff[offset] == '=' || myhtml_string_alphanumeric_character[ (unsigned char)buff[offset] ] != 0xff)) |
0 |
0 |
0 |
|
| 266 |
|
| { |
| 267 |
0 |
▶ | if(chunk->encoding == MyHTML_ENCODING_UTF_8) |
Branch: 1 branch
| Branch | True | False | Total |
| if(chunk->encoding == MyHTML_ENCODING_UTF_8) |
0 |
0 |
0 |
|
| 268 |
0 |
| myhtml_string_append_with_preprocessing(str, &buff[tmp_offset], (offset - tmp_offset), chunk->emit_null_char); |
| 269 |
|
| else |
| 270 |
0 |
| myhtml_string_append_chunk_with_convert_encoding_with_preprocessing(str, &chunk->res, &buff[tmp_offset], (offset - tmp_offset), chunk->encoding); |
| 271 |
|
| |
| 272 |
0 |
| return offset; |
| 273 |
|
| } |
| 274 |
|
| } |
| 275 |
|
| |
| 276 |
0 |
▶ | if(current_entry->codepoints_len) |
Branch: 1 branch
| Branch | True | False | Total |
| if(current_entry->codepoints_len) |
0 |
0 |
0 |
|
| 277 |
|
| { |
| 278 |
0 |
▶ | for (size_t i = 0; i < current_entry->codepoints_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < current_entry->codepoints_len; i++) { |
0 |
0 |
0 |
|
| 279 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 280 |
|
| |
| 281 |
0 |
| chunk->begin += myhtml_encoding_codepoint_to_ascii_utf_8(current_entry->codepoints[i], &str->data[chunk->begin]); |
| 282 |
|
| } |
| 283 |
|
| |
| 284 |
0 |
| str->length = chunk->begin; |
| 285 |
|
| } |
| 286 |
|
| else { |
| 287 |
0 |
▶ | if(chunk->encoding == MyHTML_ENCODING_UTF_8) |
Branch: 1 branch
| Branch | True | False | Total |
| if(chunk->encoding == MyHTML_ENCODING_UTF_8) |
0 |
0 |
0 |
|
| 288 |
0 |
| myhtml_string_append_with_preprocessing(str, &buff[tmp_offset], (offset - tmp_offset), chunk->emit_null_char); |
| 289 |
|
| else |
| 290 |
0 |
| myhtml_string_append_chunk_with_convert_encoding_with_preprocessing(str, &chunk->res, &buff[tmp_offset], (offset - tmp_offset), chunk->encoding); |
| 291 |
|
| } |
| 292 |
|
| |
| 293 |
0 |
| chunk->charef_res.last_entry = NULL; |
| 294 |
|
| } |
| 295 |
|
| else { |
| 296 |
0 |
▶ | if(chunk->encoding == MyHTML_ENCODING_UTF_8) |
Branch: 1 branch
| Branch | True | False | Total |
| if(chunk->encoding == MyHTML_ENCODING_UTF_8) |
0 |
0 |
0 |
|
| 297 |
0 |
| myhtml_string_append_with_preprocessing(str, &buff[tmp_offset], (offset - tmp_offset), chunk->emit_null_char); |
| 298 |
|
| else |
| 299 |
0 |
| myhtml_string_append_chunk_with_convert_encoding_with_preprocessing(str, &chunk->res, &buff[tmp_offset], (offset - tmp_offset), chunk->encoding); |
| 300 |
|
| } |
| 301 |
|
| |
| 302 |
0 |
| return offset; |
| 303 |
|
| } |
| 304 |
|
| |
| 305 |
0 |
| size_t _myhtml_string_append_char_references_state_3(myhtml_string_char_ref_chunk_t *chunk, myhtml_string_t* str, const char* buff, size_t offset, size_t size) |
| 306 |
|
| { |
| 307 |
0 |
▶ | if(buff[offset] == 'x' || buff[offset] == 'X') { |
Branch: 2 branches
| Branch | True | False | Total |
| if(buff[offset] == 'x' || buff[offset] == 'X') { |
0 |
0 |
0 |
| if(buff[offset] == 'x' || buff[offset] == 'X') { |
0 |
0 |
0 |
|
| 308 |
0 |
| _myhtml_string_charef_append(str, buff[offset]); |
| 309 |
0 |
| offset++; |
| 310 |
|
| |
| 311 |
0 |
| chunk->state = 5; |
| 312 |
|
| } |
| 313 |
|
| else |
| 314 |
0 |
| chunk->state = 4; |
| 315 |
|
| |
| 316 |
0 |
| return offset; |
| 317 |
|
| } |
| 318 |
|
| |
| 319 |
0 |
| void _myhtml_string_append_char_references_state_end(myhtml_string_char_ref_chunk_t *chunk, myhtml_string_t* str) |
| 320 |
|
| { |
| 321 |
0 |
| str->length = chunk->begin; |
| 322 |
|
| |
| 323 |
|
| /* 4 is max utf8 byte + \0 */ |
| 324 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 5, 12); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 5, 12); |
0 |
0 |
0 |
|
| 325 |
|
| |
| 326 |
0 |
▶ | if(chunk->l_data <= 0x9F) |
Branch: 1 branch
| Branch | True | False | Total |
| if(chunk->l_data <= 0x9F) |
0 |
0 |
0 |
|
| 327 |
0 |
| chunk->l_data = replacement_character[chunk->l_data]; |
| 328 |
0 |
▶ | else if(chunk->l_data >= 0xD800 && chunk->l_data <= 0xDFFF) |
Branch: 2 branches
| Branch | True | False | Total |
| else if(chunk->l_data >= 0xD800 && chunk->l_data <= 0xDFFF) |
0 |
0 |
0 |
| else if(chunk->l_data >= 0xD800 && chunk->l_data <= 0xDFFF) |
0 |
0 |
0 |
|
| 329 |
0 |
| chunk->l_data = replacement_character[0]; |
| 330 |
0 |
▶ | else if(chunk->l_data > 0x10FFFF) |
Branch: 1 branch
| Branch | True | False | Total |
| else if(chunk->l_data > 0x10FFFF) |
0 |
0 |
0 |
|
| 331 |
0 |
| chunk->l_data = replacement_character[0]; |
| 332 |
|
| |
| 333 |
|
| // if(chunk->l_data == 0x10FFFE) |
| 334 |
|
| // chunk->l_data = replacement_character[0]; |
| 335 |
|
| |
| 336 |
0 |
| str->length += myhtml_encoding_codepoint_to_ascii_utf_8(chunk->l_data, &str->data[chunk->begin]); |
| 337 |
0 |
| str->data[str->length] = '\0'; |
| 338 |
0 |
| } |
| 339 |
|
| |
| 340 |
0 |
| size_t _myhtml_string_append_char_references_state_4(myhtml_string_char_ref_chunk_t *chunk, myhtml_string_t* str, const unsigned char *buff, size_t offset, size_t size) |
| 341 |
|
| { |
| 342 |
0 |
| size_t tmp_offset = offset; |
| 343 |
|
| |
| 344 |
0 |
▶ | while(offset < size) |
Branch: 1 branch
| Branch | True | False | Total |
| while(offset < size) |
0 |
0 |
0 |
|
| 345 |
|
| { |
| 346 |
0 |
▶ | if(myhtml_string_chars_num_map[ buff[offset] ] == 0xff) |
Branch: 1 branch
| Branch | True | False | Total |
| if(myhtml_string_chars_num_map[ buff[offset] ] == 0xff) |
0 |
0 |
0 |
|
| 347 |
|
| { |
| 348 |
0 |
| chunk->state = 0; |
| 349 |
|
| |
| 350 |
0 |
| myhtml_string_append_with_preprocessing(str, (const char*)&buff[tmp_offset], (offset - tmp_offset), chunk->emit_null_char); |
| 351 |
|
| |
| 352 |
0 |
▶ | if((str->length - (chunk->begin + 2)) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if((str->length - (chunk->begin + 2)) == 0) { |
0 |
0 |
0 |
|
| 353 |
0 |
| return offset; |
| 354 |
|
| } |
| 355 |
|
| |
| 356 |
0 |
▶ | if(buff[offset] == ';') |
Branch: 1 branch
| Branch | True | False | Total |
| if(buff[offset] == ';') |
0 |
0 |
0 |
|
| 357 |
0 |
| offset++; |
| 358 |
|
| |
| 359 |
0 |
| _myhtml_string_append_char_references_state_end(chunk, str); |
| 360 |
0 |
| return offset; |
| 361 |
|
| } |
| 362 |
|
| |
| 363 |
0 |
▶ | if(chunk->l_data <= 0x10FFFF) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(chunk->l_data <= 0x10FFFF) { |
0 |
0 |
0 |
|
| 364 |
0 |
| chunk->l_data = myhtml_string_chars_num_map[ buff[offset] ] + chunk->l_data * 10; |
| 365 |
|
| } |
| 366 |
|
| |
| 367 |
0 |
| offset++; |
| 368 |
|
| } |
| 369 |
|
| |
| 370 |
0 |
| myhtml_string_append_with_preprocessing(str, (const char*)&buff[tmp_offset], (offset - tmp_offset), chunk->emit_null_char); |
| 371 |
|
| |
| 372 |
0 |
| return offset; |
| 373 |
|
| } |
| 374 |
|
| |
| 375 |
0 |
| size_t _myhtml_string_append_char_references_state_5(myhtml_string_char_ref_chunk_t *chunk, myhtml_string_t* str, const char* buff, size_t offset, size_t size) |
| 376 |
|
| { |
| 377 |
0 |
| unsigned const char *u_buff = (unsigned const char*)buff; |
| 378 |
0 |
| size_t current_len = (str->length - (chunk->begin + 3)); |
| 379 |
|
| |
| 380 |
0 |
| size_t tmp_offset = offset, tmp_set_to = offset; |
| 381 |
|
| |
| 382 |
0 |
▶ | while(offset < size) |
Branch: 1 branch
| Branch | True | False | Total |
| while(offset < size) |
0 |
0 |
0 |
|
| 383 |
|
| { |
| 384 |
0 |
▶ | if(myhtml_string_chars_hex_map[ u_buff[offset] ] == 0xff) |
Branch: 1 branch
| Branch | True | False | Total |
| if(myhtml_string_chars_hex_map[ u_buff[offset] ] == 0xff) |
0 |
0 |
0 |
|
| 385 |
|
| { |
| 386 |
0 |
▶ | if(((offset - tmp_offset) + current_len) > 6) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(((offset - tmp_offset) + current_len) > 6) { |
0 |
0 |
0 |
|
| 387 |
0 |
| chunk->l_data = 0xFFFFFF; |
| 388 |
|
| } |
| 389 |
|
| |
| 390 |
0 |
| chunk->state = 0; |
| 391 |
0 |
| myhtml_string_append_with_preprocessing(str, &buff[tmp_offset], (tmp_set_to - tmp_offset), chunk->emit_null_char); |
| 392 |
|
| |
| 393 |
0 |
▶ | if((str->length - (chunk->begin + 3)) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if((str->length - (chunk->begin + 3)) == 0) { |
0 |
0 |
0 |
|
| 394 |
0 |
| return offset; |
| 395 |
|
| } |
| 396 |
|
| |
| 397 |
0 |
▶ | if(buff[offset] == ';') |
Branch: 1 branch
| Branch | True | False | Total |
| if(buff[offset] == ';') |
0 |
0 |
0 |
|
| 398 |
0 |
| offset++; |
| 399 |
|
| |
| 400 |
0 |
| _myhtml_string_append_char_references_state_end(chunk, str); |
| 401 |
0 |
| return offset; |
| 402 |
|
| } |
| 403 |
|
| |
| 404 |
0 |
▶ | if(((offset - tmp_offset) + current_len) < 7) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(((offset - tmp_offset) + current_len) < 7) { |
0 |
0 |
0 |
|
| 405 |
0 |
| chunk->l_data <<= 4; |
| 406 |
0 |
| chunk->l_data |= myhtml_string_chars_hex_map[ u_buff[offset] ]; |
| 407 |
|
| |
| 408 |
0 |
| tmp_set_to++; |
| 409 |
|
| } |
| 410 |
|
| |
| 411 |
0 |
| offset++; |
| 412 |
|
| } |
| 413 |
|
| |
| 414 |
0 |
▶ | if(((offset - tmp_offset) + current_len) > 6) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(((offset - tmp_offset) + current_len) > 6) { |
0 |
0 |
0 |
|
| 415 |
0 |
| chunk->l_data = 0xFFFFFF; |
| 416 |
|
| } |
| 417 |
|
| |
| 418 |
0 |
| myhtml_string_append_with_preprocessing(str, &buff[tmp_offset], (offset - tmp_offset), chunk->emit_null_char); |
| 419 |
|
| |
| 420 |
0 |
| return offset; |
| 421 |
|
| } |
| 422 |
|
| |
| 423 |
0 |
| void myhtml_string_append_charef(myhtml_string_char_ref_chunk_t *chunk, myhtml_string_t* str, const char* buff, size_t size) |
| 424 |
|
| { |
| 425 |
0 |
| size_t offset = 0; |
| 426 |
|
| |
| 427 |
0 |
▶ | while (offset < size) |
Branch: 1 branch
| Branch | True | False | Total |
| while (offset < size) |
0 |
0 |
0 |
|
| 428 |
|
| { |
| 429 |
0 |
| switch (chunk->state) { |
| 430 |
0 |
| case 1: |
| 431 |
0 |
| offset = _myhtml_string_append_char_references_state_1(chunk, str, buff, offset, size); |
| 432 |
0 |
| break; |
| 433 |
0 |
| case 2: |
| 434 |
0 |
| offset = _myhtml_string_append_char_references_state_2(chunk, str, buff, offset, size); |
| 435 |
0 |
| break; |
| 436 |
0 |
| case 3: |
| 437 |
0 |
| offset = _myhtml_string_append_char_references_state_3(chunk, str, buff, offset, size); |
| 438 |
0 |
| break; |
| 439 |
0 |
| case 4: |
| 440 |
0 |
| offset = _myhtml_string_append_char_references_state_4(chunk, str, (const unsigned char*)buff, offset, size); |
| 441 |
0 |
| break; |
| 442 |
0 |
| case 5: |
| 443 |
0 |
| offset = _myhtml_string_append_char_references_state_5(chunk, str, buff, offset, size); |
| 444 |
0 |
| break; |
| 445 |
0 |
| default: |
| 446 |
0 |
| offset = _myhtml_string_append_char_references_state_0(chunk, str, buff, offset, size); |
| 447 |
0 |
| break; |
| 448 |
|
| } |
| 449 |
|
| } |
| 450 |
0 |
| } |
| 451 |
|
| |
| 452 |
0 |
| void myhtml_string_append_charef_end(myhtml_string_char_ref_chunk_t *chunk, myhtml_string_t* str) |
| 453 |
|
| { |
| 454 |
0 |
▶ | if(chunk->state == 2 && chunk->charef_res.last_entry) |
Branch: 2 branches
| Branch | True | False | Total |
| if(chunk->state == 2 && chunk->charef_res.last_entry) |
0 |
0 |
0 |
| if(chunk->state == 2 && chunk->charef_res.last_entry) |
0 |
0 |
0 |
|
| 455 |
0 |
| { |
| 456 |
0 |
| const charef_entry_t *entry = chunk->charef_res.last_entry; |
| 457 |
|
| |
| 458 |
0 |
▶ | for (size_t i = 0; i < entry->codepoints_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < entry->codepoints_len; i++) { |
0 |
0 |
0 |
|
| 459 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 460 |
|
| |
| 461 |
0 |
| chunk->begin += myhtml_encoding_codepoint_to_ascii_utf_8(entry->codepoints[i], &str->data[chunk->begin]); |
| 462 |
|
| } |
| 463 |
|
| |
| 464 |
0 |
| str->length = chunk->begin; |
| 465 |
|
| } |
| 466 |
0 |
▶ | else if(chunk->state == 4) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if(chunk->state == 4) { |
0 |
0 |
0 |
|
| 467 |
0 |
▶ | if((str->length - (chunk->begin + 2))) |
Branch: 1 branch
| Branch | True | False | Total |
| if((str->length - (chunk->begin + 2))) |
0 |
0 |
0 |
|
| 468 |
0 |
| _myhtml_string_append_char_references_state_end(chunk, str); |
| 469 |
|
| } |
| 470 |
0 |
▶ | else if(chunk->state == 5) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if(chunk->state == 5) { |
0 |
0 |
0 |
|
| 471 |
0 |
▶ | if((str->length - (chunk->begin + 3))) |
Branch: 1 branch
| Branch | True | False | Total |
| if((str->length - (chunk->begin + 3))) |
0 |
0 |
0 |
|
| 472 |
0 |
| _myhtml_string_append_char_references_state_end(chunk, str); |
| 473 |
|
| } |
| 474 |
|
| |
| 475 |
0 |
▶ | if(str->length) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->length) { |
0 |
0 |
0 |
|
| 476 |
0 |
▶ | if(str->data[ (str->length - 1) ] == '\r') { |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->data[ (str->length - 1) ] == '\r') { |
0 |
0 |
0 |
|
| 477 |
0 |
| str->data[ (str->length - 1) ] = '\n'; |
| 478 |
|
| } |
| 479 |
|
| } |
| 480 |
0 |
| } |
| 481 |
|
| |
| 482 |
0 |
| void myhtml_string_append(myhtml_string_t* str, const char* buff, size_t length) |
| 483 |
|
| { |
| 484 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, (length + 1), (length + 32)); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, (length + 1), (length + 32)); |
0 |
0 |
0 |
|
| 485 |
|
| |
| 486 |
0 |
| memcpy(&str->data[str->length], buff, (sizeof(char) * length)); |
| 487 |
|
| |
| 488 |
0 |
| str->length += length; |
| 489 |
0 |
| str->data[str->length] = '\0'; |
| 490 |
0 |
| } |
| 491 |
|
| |
| 492 |
0 |
| void myhtml_string_append_with_preprocessing(myhtml_string_t* str, const char* buff, size_t length, bool emit_null_chars) |
| 493 |
|
| { |
| 494 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, (length + 1), 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, (length + 1), 32); |
0 |
0 |
0 |
|
| 495 |
|
| |
| 496 |
0 |
| unsigned char *data = (unsigned char*)str->data; |
| 497 |
0 |
| const unsigned char *u_buff = (unsigned char*)buff; |
| 498 |
|
| |
| 499 |
0 |
▶ | for (size_t i = 0; i < length; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < length; i++) |
0 |
0 |
0 |
|
| 500 |
|
| { |
| 501 |
0 |
▶ | if(u_buff[i] == 0x0D) |
Branch: 1 branch
| Branch | True | False | Total |
| if(u_buff[i] == 0x0D) |
0 |
0 |
0 |
|
| 502 |
|
| { |
| 503 |
0 |
| data[str->length] = 0x0A; |
| 504 |
|
| |
| 505 |
0 |
▶ | if((i+1) < length && u_buff[(i + 1)] == 0x0A) { |
Branch: 2 branches
| Branch | True | False | Total |
| if((i+1) < length && u_buff[(i + 1)] == 0x0A) { |
0 |
0 |
0 |
| if((i+1) < length && u_buff[(i + 1)] == 0x0A) { |
0 |
0 |
0 |
|
| 506 |
0 |
| i++; |
| 507 |
|
| } |
| 508 |
|
| } |
| 509 |
0 |
▶ | else if(u_buff[i] == 0x00 && emit_null_chars == false) |
Branch: 2 branches
| Branch | True | False | Total |
| else if(u_buff[i] == 0x00 && emit_null_chars == false) |
0 |
0 |
0 |
| else if(u_buff[i] == 0x00 && emit_null_chars == false) |
0 |
0 |
0 |
|
| 510 |
|
| { |
| 511 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 512 |
|
| |
| 513 |
0 |
▶ | if((unsigned char *)str->data != data) |
Branch: 1 branch
| Branch | True | False | Total |
| if((unsigned char *)str->data != data) |
0 |
0 |
0 |
|
| 514 |
0 |
| data = (unsigned char*)str->data; |
| 515 |
|
| |
| 516 |
|
| // Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD) |
| 517 |
0 |
| data[str->length] = 0xEF; str->length++; |
| 518 |
0 |
| data[str->length] = 0xBF; str->length++; |
| 519 |
0 |
| data[str->length] = 0xBD; |
| 520 |
|
| } |
| 521 |
|
| else { |
| 522 |
0 |
| data[str->length] = u_buff[i]; |
| 523 |
|
| } |
| 524 |
|
| |
| 525 |
0 |
| str->length++; |
| 526 |
|
| |
| 527 |
0 |
▶ | if(str->length >= str->size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->length >= str->size) { |
0 |
0 |
0 |
|
| 528 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 529 |
|
| |
| 530 |
0 |
▶ | if((unsigned char *)str->data != data) |
Branch: 1 branch
| Branch | True | False | Total |
| if((unsigned char *)str->data != data) |
0 |
0 |
0 |
|
| 531 |
0 |
| data = (unsigned char*)str->data; |
| 532 |
|
| } |
| 533 |
|
| } |
| 534 |
|
| |
| 535 |
0 |
| str->data[str->length] = '\0'; |
| 536 |
0 |
| } |
| 537 |
|
| |
| 538 |
0 |
| void myhtml_string_append_lowercase_with_preprocessing(myhtml_string_t* str, const char* buff, size_t length) |
| 539 |
|
| { |
| 540 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, (length + 1), 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, (length + 1), 32); |
0 |
0 |
0 |
|
| 541 |
|
| |
| 542 |
0 |
| unsigned char *data = (unsigned char*)str->data; |
| 543 |
0 |
| const unsigned char *u_buff = (unsigned char*)buff; |
| 544 |
|
| |
| 545 |
0 |
▶ | for (size_t i = 0; i < length; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < length; i++) |
0 |
0 |
0 |
|
| 546 |
|
| { |
| 547 |
0 |
▶ | if(u_buff[i] == 0x0D) |
Branch: 1 branch
| Branch | True | False | Total |
| if(u_buff[i] == 0x0D) |
0 |
0 |
0 |
|
| 548 |
|
| { |
| 549 |
0 |
| data[str->length] = 0x0A; |
| 550 |
|
| |
| 551 |
0 |
▶ | if((i+1) < length && u_buff[(i + 1)] == 0x0A) { |
Branch: 2 branches
| Branch | True | False | Total |
| if((i+1) < length && u_buff[(i + 1)] == 0x0A) { |
0 |
0 |
0 |
| if((i+1) < length && u_buff[(i + 1)] == 0x0A) { |
0 |
0 |
0 |
|
| 552 |
0 |
| i++; |
| 553 |
|
| } |
| 554 |
|
| } |
| 555 |
0 |
▶ | else if(u_buff[i] == 0x00) |
Branch: 1 branch
| Branch | True | False | Total |
| else if(u_buff[i] == 0x00) |
0 |
0 |
0 |
|
| 556 |
|
| { |
| 557 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 558 |
|
| |
| 559 |
0 |
▶ | if((unsigned char *)str->data != data) |
Branch: 1 branch
| Branch | True | False | Total |
| if((unsigned char *)str->data != data) |
0 |
0 |
0 |
|
| 560 |
0 |
| data = (unsigned char*)str->data; |
| 561 |
|
| |
| 562 |
|
| // Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD) |
| 563 |
0 |
| data[str->length] = 0xEF; str->length++; |
| 564 |
0 |
| data[str->length] = 0xBF; str->length++; |
| 565 |
0 |
| data[str->length] = 0xBD; |
| 566 |
|
| } |
| 567 |
|
| else { |
| 568 |
0 |
| data[str->length] = myhtml_string_chars_lowercase_map[ u_buff[i] ]; |
| 569 |
|
| } |
| 570 |
|
| |
| 571 |
0 |
| str->length++; |
| 572 |
|
| |
| 573 |
0 |
▶ | if(str->length >= str->size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->length >= str->size) { |
0 |
0 |
0 |
|
| 574 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 575 |
|
| |
| 576 |
0 |
▶ | if((unsigned char *)str->data != data) |
Branch: 1 branch
| Branch | True | False | Total |
| if((unsigned char *)str->data != data) |
0 |
0 |
0 |
|
| 577 |
0 |
| data = (unsigned char*)str->data; |
| 578 |
|
| } |
| 579 |
|
| } |
| 580 |
|
| |
| 581 |
0 |
| str->data[str->length] = '\0'; |
| 582 |
0 |
| } |
| 583 |
|
| |
| 584 |
0 |
| void myhtml_string_append_with_convert_encoding_with_preprocessing(myhtml_string_t* str, const char* buff, size_t length, myhtml_encoding_t encoding) |
| 585 |
|
| { |
| 586 |
|
| myhtml_encoding_result_t res; |
| 587 |
0 |
| myhtml_encoding_result_clean(&res); |
| 588 |
|
| |
| 589 |
0 |
| myhtml_string_append_chunk_with_convert_encoding_with_preprocessing(str, &res, buff, length, encoding); |
| 590 |
0 |
| } |
| 591 |
|
| |
| 592 |
0 |
| void myhtml_string_append_chunk_with_convert_encoding_with_preprocessing(myhtml_string_t* str, myhtml_encoding_result_t* res, const char* buff, size_t length, myhtml_encoding_t encoding) |
| 593 |
|
| { |
| 594 |
0 |
| unsigned const char* u_buff = (unsigned const char*)buff; |
| 595 |
0 |
| myhtml_encoding_custom_f func = myhtml_encoding_get_function_by_id(encoding); |
| 596 |
|
| |
| 597 |
0 |
▶ | for (size_t i = 0; i < length; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < length; i++) |
0 |
0 |
0 |
|
| 598 |
|
| { |
| 599 |
0 |
▶ | if(func(u_buff[i], res) == MyHTML_ENCODING_STATUS_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(func(u_buff[i], res) == MyHTML_ENCODING_STATUS_OK) { |
0 |
0 |
0 |
|
| 600 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 601 |
|
| |
| 602 |
0 |
| size_t len = myhtml_encoding_codepoint_to_ascii_utf_8(res->result, &str->data[str->length]); |
| 603 |
|
| |
| 604 |
0 |
▶ | if(len == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(len == 1) { |
0 |
0 |
0 |
|
| 605 |
|
| // change \r\n to \n |
| 606 |
0 |
▶ | if(str->length > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->length > 0) { |
0 |
0 |
0 |
|
| 607 |
0 |
▶ | if(str->data[(str->length - 1)] == '\r') { |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->data[(str->length - 1)] == '\r') { |
0 |
0 |
0 |
|
| 608 |
0 |
| str->data[(str->length - 1)] = '\n'; |
| 609 |
|
| |
| 610 |
0 |
▶ | if(str->data[str->length] == '\n') |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->data[str->length] == '\n') |
0 |
0 |
0 |
|
| 611 |
0 |
| str->length--; |
| 612 |
|
| |
| 613 |
0 |
| str->length += len; |
| 614 |
0 |
| continue; |
| 615 |
|
| } |
| 616 |
|
| } |
| 617 |
|
| |
| 618 |
0 |
▶ | if(str->data[str->length] == 0x00) |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->data[str->length] == 0x00) |
0 |
0 |
0 |
|
| 619 |
|
| { |
| 620 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 621 |
|
| |
| 622 |
|
| // Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD) |
| 623 |
0 |
| str->data[str->length] = 0xEF; str->length++; |
| 624 |
0 |
| str->data[str->length] = 0xBF; str->length++; |
| 625 |
0 |
| str->data[str->length] = 0xBD; |
| 626 |
|
| } |
| 627 |
|
| } |
| 628 |
|
| |
| 629 |
0 |
| str->length += len; |
| 630 |
|
| |
| 631 |
0 |
▶ | if(str->length >= str->size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->length >= str->size) { |
0 |
0 |
0 |
|
| 632 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 633 |
|
| } |
| 634 |
|
| } |
| 635 |
|
| } |
| 636 |
|
| |
| 637 |
0 |
▶ | MyHTML_STRING_APPEND_BYTE_WITHOUT_INCREMENT('\0', str, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_APPEND_BYTE_WITHOUT_INCREMENT('\0', str, 1); |
0 |
0 |
0 |
|
| 638 |
0 |
| } |
| 639 |
|
| |
| 640 |
0 |
| void myhtml_string_append_with_convert_encoding(myhtml_string_t* str, const char* buff, size_t length, myhtml_encoding_t encoding) |
| 641 |
|
| { |
| 642 |
|
| myhtml_encoding_result_t res; |
| 643 |
0 |
| myhtml_encoding_result_clean(&res); |
| 644 |
|
| |
| 645 |
0 |
| myhtml_string_append_chunk_with_convert_encoding(str, &res, buff, length, encoding); |
| 646 |
0 |
| } |
| 647 |
|
| |
| 648 |
0 |
| void myhtml_string_append_chunk_with_convert_encoding(myhtml_string_t* str, myhtml_encoding_result_t* res, const char* buff, size_t length, myhtml_encoding_t encoding) |
| 649 |
|
| { |
| 650 |
0 |
| unsigned const char* u_buff = (unsigned const char*)buff; |
| 651 |
0 |
| myhtml_encoding_custom_f func = myhtml_encoding_get_function_by_id(encoding); |
| 652 |
|
| |
| 653 |
0 |
▶ | for (size_t i = 0; i < length; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < length; i++) |
0 |
0 |
0 |
|
| 654 |
|
| { |
| 655 |
0 |
▶ | if(func(u_buff[i], res) == MyHTML_ENCODING_STATUS_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(func(u_buff[i], res) == MyHTML_ENCODING_STATUS_OK) { |
0 |
0 |
0 |
|
| 656 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 5, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 5, 32); |
0 |
0 |
0 |
|
| 657 |
0 |
| str->length += myhtml_encoding_codepoint_to_ascii_utf_8(res->result, &str->data[str->length]); |
| 658 |
|
| } |
| 659 |
|
| } |
| 660 |
|
| |
| 661 |
0 |
▶ | MyHTML_STRING_APPEND_BYTE_WITHOUT_INCREMENT('\0', str, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_APPEND_BYTE_WITHOUT_INCREMENT('\0', str, 1); |
0 |
0 |
0 |
|
| 662 |
0 |
| } |
| 663 |
|
| |
| 664 |
0 |
| void myhtml_string_append_one(myhtml_string_t* str, const char data) |
| 665 |
|
| { |
| 666 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 2, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 2, 32); |
0 |
0 |
0 |
|
| 667 |
0 |
| MyHTML_STRING_APPEND_BYTE_WITHOUT_REALLOC(data, str); |
| 668 |
0 |
| MyHTML_STRING_APPEND_BYTE_WITHOUT_INCREMENT_REALLOC('\0', str); |
| 669 |
0 |
| } |
| 670 |
|
| |
| 671 |
0 |
| void myhtml_string_append_one_with_convert_encoding(myhtml_string_t* str, myhtml_encoding_result_t* res, const char data, myhtml_encoding_t encoding) |
| 672 |
|
| { |
| 673 |
0 |
| myhtml_encoding_custom_f func = myhtml_encoding_get_function_by_id(encoding); |
| 674 |
|
| |
| 675 |
0 |
▶ | if(func((unsigned const char)data, res) == MyHTML_ENCODING_STATUS_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(func((unsigned const char)data, res) == MyHTML_ENCODING_STATUS_OK) { |
0 |
0 |
0 |
|
| 676 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 5, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 5, 32); |
0 |
0 |
0 |
|
| 677 |
0 |
| str->length += myhtml_encoding_codepoint_to_ascii_utf_8(res->result, &str->data[str->length]); |
| 678 |
|
| |
| 679 |
0 |
| MyHTML_STRING_APPEND_BYTE_WITHOUT_INCREMENT_REALLOC('\0', str); |
| 680 |
|
| } |
| 681 |
0 |
| } |
| 682 |
|
| |
| 683 |
0 |
| void myhtml_string_append_lowercase(myhtml_string_t* str, const char* data, size_t length) |
| 684 |
|
| { |
| 685 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, (length + 1), 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, (length + 1), 32); |
0 |
0 |
0 |
|
| 686 |
|
| |
| 687 |
0 |
| unsigned char *ref = (unsigned char*)&str->data[str->length]; |
| 688 |
0 |
| unsigned char *buf = (unsigned char*)data; |
| 689 |
|
| |
| 690 |
|
| size_t i; |
| 691 |
0 |
▶ | for(i = 0; i < length; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < length; i++) { |
0 |
0 |
0 |
|
| 692 |
0 |
| ref[i] = myhtml_string_chars_lowercase_map[ buf[i] ]; |
| 693 |
|
| } |
| 694 |
|
| |
| 695 |
0 |
| ref[i] = '\0'; |
| 696 |
0 |
| str->length += length; |
| 697 |
0 |
| } |
| 698 |
|
| |
| 699 |
0 |
| void myhtml_string_append_lowercase_ascii_with_convert_encoding(myhtml_string_t* str, const char* buff, size_t length, myhtml_encoding_t encoding) |
| 700 |
|
| { |
| 701 |
|
| myhtml_encoding_result_t res; |
| 702 |
0 |
| myhtml_encoding_result_clean(&res); |
| 703 |
|
| |
| 704 |
0 |
| myhtml_string_append_chunk_lowercase_ascii_with_convert_encoding(str, &res, buff, length, encoding); |
| 705 |
0 |
| } |
| 706 |
|
| |
| 707 |
0 |
| void myhtml_string_append_chunk_lowercase_ascii_with_convert_encoding(myhtml_string_t* str, myhtml_encoding_result_t* res, const char* buff, size_t length, myhtml_encoding_t encoding) |
| 708 |
|
| { |
| 709 |
0 |
| unsigned const char* u_buff = (unsigned const char*)buff; |
| 710 |
0 |
| myhtml_encoding_custom_f func = myhtml_encoding_get_function_by_id(encoding); |
| 711 |
|
| |
| 712 |
0 |
▶ | for (size_t i = 0; i < length; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < length; i++) |
0 |
0 |
0 |
|
| 713 |
|
| { |
| 714 |
0 |
▶ | if(func(u_buff[i], res) == MyHTML_ENCODING_STATUS_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(func(u_buff[i], res) == MyHTML_ENCODING_STATUS_OK) { |
0 |
0 |
0 |
|
| 715 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 716 |
|
| |
| 717 |
0 |
| size_t insert_len = myhtml_encoding_codepoint_to_ascii_utf_8(res->result, &str->data[str->length]); |
| 718 |
|
| |
| 719 |
0 |
▶ | if(insert_len == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(insert_len == 1) { |
0 |
0 |
0 |
|
| 720 |
0 |
| str->data[str->length] = myhtml_string_chars_lowercase_map[ u_buff[i] ]; |
| 721 |
|
| } |
| 722 |
|
| |
| 723 |
0 |
| str->length += insert_len; |
| 724 |
|
| } |
| 725 |
|
| } |
| 726 |
|
| |
| 727 |
0 |
▶ | MyHTML_STRING_APPEND_BYTE_WITHOUT_INCREMENT('\0', str, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_APPEND_BYTE_WITHOUT_INCREMENT('\0', str, 1); |
0 |
0 |
0 |
|
| 728 |
0 |
| } |
| 729 |
|
| |
| 730 |
0 |
| void myhtml_string_copy(myhtml_string_t* dest, myhtml_string_t* target) |
| 731 |
|
| { |
| 732 |
0 |
| myhtml_string_append(dest, target->data, target->length); |
| 733 |
0 |
| } |
| 734 |
|
| |
| 735 |
1 |
| size_t myhtml_string_raw_copy(char* str1, const char* str2, size_t size) |
| 736 |
|
| { |
| 737 |
1 |
| str1[size] = '\0'; |
| 738 |
|
| |
| 739 |
8 |
▶ | while(size) { |
Branch: 1 branch
| Branch | True | False | Total |
| while(size) { |
7 |
1 |
8 |
|
| 740 |
7 |
| size--; |
| 741 |
7 |
| str1[size] = str2[size]; |
| 742 |
|
| } |
| 743 |
|
| |
| 744 |
1 |
| return size; |
| 745 |
|
| } |
| 746 |
|
| |
| 747 |
0 |
| size_t myhtml_string_raw_set_replacement_character(myhtml_string_t* target, size_t position) |
| 748 |
|
| { |
| 749 |
|
| // Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD) |
| 750 |
0 |
| target->data[(position)] = 0xEF; |
| 751 |
0 |
| target->data[(position + 1)] = 0xBF; |
| 752 |
0 |
| target->data[(position + 2)] = 0xBD; |
| 753 |
|
| |
| 754 |
0 |
| return 3; |
| 755 |
|
| } |
| 756 |
|
| |
| 757 |
0 |
| void myhtml_string_append_with_replacement_null_characters_only(myhtml_string_t* str, const char* buff, size_t length) |
| 758 |
|
| { |
| 759 |
0 |
| unsigned char *data = (unsigned char*)str->data; |
| 760 |
0 |
| const unsigned char *u_buff = (unsigned char*)buff; |
| 761 |
|
| |
| 762 |
0 |
▶ | for (size_t i = 0; i < length; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < length; i++) |
0 |
0 |
0 |
|
| 763 |
|
| { |
| 764 |
0 |
▶ | if(u_buff[i] == 0x00) |
Branch: 1 branch
| Branch | True | False | Total |
| if(u_buff[i] == 0x00) |
0 |
0 |
0 |
|
| 765 |
|
| { |
| 766 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 767 |
|
| |
| 768 |
0 |
▶ | if((unsigned char *)str->data != data) |
Branch: 1 branch
| Branch | True | False | Total |
| if((unsigned char *)str->data != data) |
0 |
0 |
0 |
|
| 769 |
0 |
| data = (unsigned char*)str->data; |
| 770 |
|
| |
| 771 |
|
| // Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD) |
| 772 |
0 |
| data[str->length] = 0xEF; str->length++; |
| 773 |
0 |
| data[str->length] = 0xBF; str->length++; |
| 774 |
0 |
| data[str->length] = 0xBD; |
| 775 |
|
| } |
| 776 |
|
| else { |
| 777 |
0 |
| data[str->length] = u_buff[i]; |
| 778 |
|
| } |
| 779 |
|
| |
| 780 |
0 |
▶ | if(str->length >= str->size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(str->length >= str->size) { |
0 |
0 |
0 |
|
| 781 |
0 |
▶ | MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
Branch: 1 branch
| Branch | True | False | Total |
| MyHTML_STRING_REALLOC_IF_NEED(str, 4, 32); |
0 |
0 |
0 |
|
| 782 |
|
| |
| 783 |
0 |
▶ | if((unsigned char *)str->data != data) |
Branch: 1 branch
| Branch | True | False | Total |
| if((unsigned char *)str->data != data) |
0 |
0 |
0 |
|
| 784 |
0 |
| data = (unsigned char*)str->data; |
| 785 |
|
| } |
| 786 |
|
| |
| 787 |
0 |
| str->length++; |
| 788 |
|
| } |
| 789 |
|
| |
| 790 |
0 |
| str->data[str->length] = '\0'; |
| 791 |
0 |
| } |
| 792 |
|
| |
| 793 |
0 |
| void myhtml_string_stay_only_whitespace(myhtml_string_t* target) |
| 794 |
|
| { |
| 795 |
0 |
| char *data = target->data; |
| 796 |
0 |
| size_t pos = 0; |
| 797 |
|
| |
| 798 |
0 |
▶ | for(size_t i = 0; i < target->length; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(size_t i = 0; i < target->length; i++) |
0 |
0 |
0 |
|
| 799 |
|
| { |
| 800 |
0 |
▶ | if(myhtml_mystring_whitespace(data[i], ==, ||)) { |
Branch: 5 branches
| Branch | True | False | Total |
| if(myhtml_mystring_whitespace(data[i], ==, ||)) { |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], ==, ||)) { |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], ==, ||)) { |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], ==, ||)) { |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], ==, ||)) { |
0 |
0 |
0 |
|
| 801 |
0 |
| data[pos] = data[i]; |
| 802 |
0 |
| pos++; |
| 803 |
|
| } |
| 804 |
|
| } |
| 805 |
|
| |
| 806 |
0 |
| target->length = pos; |
| 807 |
0 |
| } |
| 808 |
|
| |
| 809 |
0 |
| size_t myhtml_string_crop_whitespace_from_begin(myhtml_string_t* target) |
| 810 |
|
| { |
| 811 |
0 |
| char *data = target->data; |
| 812 |
|
| size_t i; |
| 813 |
|
| |
| 814 |
0 |
▶ | for(i = 0; i < target->length; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < target->length; i++) { |
0 |
0 |
0 |
|
| 815 |
0 |
▶ | if(myhtml_mystring_whitespace(data[i], !=, &&)) |
Branch: 5 branches
| Branch | True | False | Total |
| if(myhtml_mystring_whitespace(data[i], !=, &&)) |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], !=, &&)) |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], !=, &&)) |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], !=, &&)) |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], !=, &&)) |
0 |
0 |
0 |
|
| 816 |
0 |
| break; |
| 817 |
|
| } |
| 818 |
|
| |
| 819 |
0 |
▶ | if(i) |
Branch: 1 branch
| Branch | True | False | Total |
| if(i) |
0 |
0 |
0 |
|
| 820 |
0 |
| target->data = mchar_async_crop_first_chars_without_cache(target->data, i); |
| 821 |
|
| |
| 822 |
0 |
| target->length -= i; |
| 823 |
|
| |
| 824 |
0 |
| return i; |
| 825 |
|
| } |
| 826 |
|
| |
| 827 |
0 |
| size_t myhtml_string_whitespace_from_begin(myhtml_string_t* target) |
| 828 |
|
| { |
| 829 |
0 |
| char *data = target->data; |
| 830 |
|
| size_t i; |
| 831 |
|
| |
| 832 |
0 |
▶ | for(i = 0; i < target->length; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < target->length; i++) { |
0 |
0 |
0 |
|
| 833 |
0 |
▶ | if(myhtml_mystring_whitespace(data[i], !=, &&)) |
Branch: 5 branches
| Branch | True | False | Total |
| if(myhtml_mystring_whitespace(data[i], !=, &&)) |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], !=, &&)) |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], !=, &&)) |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], !=, &&)) |
0 |
0 |
0 |
| if(myhtml_mystring_whitespace(data[i], !=, &&)) |
0 |
0 |
0 |
|
| 834 |
0 |
| break; |
| 835 |
|
| } |
| 836 |
|
| |
| 837 |
0 |
| return i; |
| 838 |
|
| } |
| 839 |
|
| |
| 840 |
|
| |