« third_party/modest/source/myhtml/callback.c
↑ Summary
third_party/modest/source/myhtml/data_process.c »
| 1 | /* | ||||||||||||||
| 2 | Copyright (C) 2015-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 "myhtml/charef.h" | ||||||||||||||
| 22 | #include "myhtml/charef_resource.h" | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 0 | const charef_entry_t * myhtml_charef_find(const char *begin, size_t *offset, size_t size, size_t *data_size) | |||||||||||||
| 25 | { | ||||||||||||||
| 26 | 0 | unsigned const char* u_begin = (unsigned const char*)begin; | |||||||||||||
| 27 | 0 | size_t pos = (size_t)(*u_begin); | |||||||||||||
| 28 | |||||||||||||||
| 29 | 0 | ▶ | while (named_character_references[pos].ch) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | { | ||||||||||||||
| 31 | 0 | ▶ | if(named_character_references[pos].ch == u_begin[*offset]) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | { | ||||||||||||||
| 33 | 0 | (*offset)++; | |||||||||||||
| 34 | |||||||||||||||
| 35 | 0 | ▶ | if(named_character_references[pos].next == 0 || *offset >= size) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 36 | 0 | ▶ | if(data_size) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 0 | *data_size = named_character_references[pos].codepoints_len; | |||||||||||||
| 38 | |||||||||||||||
| 39 | 0 | return &named_character_references[pos]; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | 0 | pos = named_character_references[pos].next; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | 0 | ▶ | else if(u_begin[*offset] > named_character_references[pos].ch) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | 0 | pos++; | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | else { | ||||||||||||||
| 48 | 0 | break; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 0 | ▶ | if(data_size) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 0 | *data_size = named_character_references[pos].codepoints_len; | |||||||||||||
| 54 | |||||||||||||||
| 55 | 0 | return &named_character_references[pos]; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | const charef_entry_t * myhtml_charef_get_first_position(const char begin) | |||||||||||||
| 59 | { | ||||||||||||||
| 60 | 0 | return &named_character_references[ (unsigned const char)begin ]; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | 0 | const charef_entry_t * myhtml_charef_find_by_pos(size_t pos, const char *begin, size_t *offset, size_t size, charef_entry_result_t *result) | |||||||||||||
| 64 | { | ||||||||||||||
| 65 | 0 | unsigned const char* u_begin = (unsigned const char*)begin; | |||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | ▶ | if(u_begin[*offset] == '&') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | 0 | result->is_done = 1; | |||||||||||||
| 69 | |||||||||||||||
| 70 | 0 | ▶ | if(result->curr_entry->codepoints_len) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 71 | 0 | return result->curr_entry; | |||||||||||||
| 72 | 0 | ▶ | else if(result->last_entry) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 73 | 0 | *offset = result->last_offset; | |||||||||||||
| 74 | 0 | return result->last_entry; | |||||||||||||
| 75 | } | ||||||||||||||
| 76 | |||||||||||||||
| 77 | 0 | return &named_character_references[0]; | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | result->is_done = 0; | |||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | ▶ | while (named_character_references[pos].ch) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 83 | { | ||||||||||||||
| 84 | 0 | ▶ | if(named_character_references[pos].ch == u_begin[*offset]) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | { | ||||||||||||||
| 86 | 0 | ▶ | if(u_begin[*offset] == ';') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 87 | 0 | result->is_done = 1; | |||||||||||||
| 88 | |||||||||||||||
| 89 | 0 | result->curr_entry = &named_character_references[pos]; | |||||||||||||
| 90 | 0 | return result->curr_entry; | |||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 0 | (*offset)++; | |||||||||||||
| 94 | |||||||||||||||
| 95 | 0 | ▶ | if(named_character_references[pos].next == 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 96 | 0 | result->is_done = 1; | |||||||||||||
| 97 | 0 | return &named_character_references[pos]; | |||||||||||||
| 98 | } | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | ▶ | if(*offset >= size) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 101 | { | ||||||||||||||
| 102 | 0 | result->curr_entry = &named_character_references[pos]; | |||||||||||||
| 103 | |||||||||||||||
| 104 | 0 | ▶ | if(named_character_references[pos].codepoints_len) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 105 | 0 | result->last_offset = *offset; | |||||||||||||
| 106 | 0 | result->last_entry = &named_character_references[pos]; | |||||||||||||
| 107 | } | ||||||||||||||
| 108 | |||||||||||||||
| 109 | 0 | return result->curr_entry; | |||||||||||||
| 110 | } | ||||||||||||||
| 111 | |||||||||||||||
| 112 | 0 | ▶ | if(u_begin[*offset] == '&') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 113 | 0 | result->is_done = 1; | |||||||||||||
| 114 | 0 | result->curr_entry = &named_character_references[pos]; | |||||||||||||
| 115 | |||||||||||||||
| 116 | 0 | ▶ | if(result->curr_entry->codepoints_len) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 117 | 0 | return result->curr_entry; | |||||||||||||
| 118 | 0 | ▶ | else if(result->last_entry) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 119 | 0 | *offset = result->last_offset; | |||||||||||||
| 120 | 0 | return result->last_entry; | |||||||||||||
| 121 | } | ||||||||||||||
| 122 | |||||||||||||||
| 123 | 0 | return &named_character_references[0]; | |||||||||||||
| 124 | } | ||||||||||||||
| 125 | |||||||||||||||
| 126 | 0 | ▶ | if(named_character_references[pos].codepoints_len) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 127 | 0 | result->last_offset = *offset; | |||||||||||||
| 128 | 0 | result->last_entry = &named_character_references[pos]; | |||||||||||||
| 129 | } | ||||||||||||||
| 130 | |||||||||||||||
| 131 | 0 | pos = named_character_references[pos].next; | |||||||||||||
| 132 | } | ||||||||||||||
| 133 | 0 | ▶ | else if(u_begin[*offset] > named_character_references[pos].ch) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 134 | 0 | pos++; | |||||||||||||
| 135 | } | ||||||||||||||
| 136 | else { | ||||||||||||||
| 137 | 0 | break; | |||||||||||||
| 138 | } | ||||||||||||||
| 139 | } | ||||||||||||||
| 140 | |||||||||||||||
| 141 | 0 | result->is_done = 1; | |||||||||||||
| 142 | |||||||||||||||
| 143 | 0 | ▶ | if(result->last_entry) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 144 | 0 | *offset = result->last_offset; | |||||||||||||
| 145 | 0 | return result->last_entry; | |||||||||||||
| 146 | } | ||||||||||||||
| 147 | |||||||||||||||
| 148 | 0 | return &named_character_references[0]; | |||||||||||||
| 149 | } | ||||||||||||||
| 150 | |||||||||||||||
| 151 | |||||||||||||||