File Coverage

third_party/modest/source/myhtml/charef.c
Criterion Covered Total %
statement 22 67 32.8
branch 12 44 27.2
condition n/a
subroutine n/a
pod n/a
total 34 111 30.6


line stmt bran cond sub pod time code
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 0         while (named_character_references[pos].ch)
30             {
31 0 0         if(named_character_references[pos].ch == u_begin[*offset])
32             {
33 0           (*offset)++;
34            
35 0 0         if(named_character_references[pos].next == 0 || *offset >= size) {
    0          
36 0 0         if(data_size)
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 0         else if(u_begin[*offset] > named_character_references[pos].ch) {
45 0           pos++;
46             }
47             else {
48 0           break;
49             }
50             }
51            
52 0 0         if(data_size)
53 0           *data_size = named_character_references[pos].codepoints_len;
54            
55 0           return &named_character_references[pos];
56             }
57              
58 128           const charef_entry_t * myhtml_charef_get_first_position(const char begin)
59             {
60 128           return &named_character_references[ (unsigned const char)begin ];
61             }
62              
63 128           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 128           unsigned const char* u_begin = (unsigned const char*)begin;
66            
67 128 50         if(u_begin[*offset] == '&') {
68 0           result->is_done = 1;
69            
70 0 0         if(result->curr_entry->codepoints_len)
71 0           return result->curr_entry;
72 0 0         else if(result->last_entry) {
73 0           *offset = result->last_offset;
74 0           return result->last_entry;
75             }
76            
77 0           return &named_character_references[0];
78             }
79            
80 128           result->is_done = 0;
81            
82 1888 50         while (named_character_references[pos].ch)
83             {
84 1888 100         if(named_character_references[pos].ch == u_begin[*offset])
85             {
86 384 100         if(u_begin[*offset] == ';') {
87 128           result->is_done = 1;
88            
89 128           result->curr_entry = &named_character_references[pos];
90 128           return result->curr_entry;
91             }
92            
93 256           (*offset)++;
94            
95 256 50         if(named_character_references[pos].next == 0) {
96 0           result->is_done = 1;
97 0           return &named_character_references[pos];
98             }
99            
100 256 50         if(*offset >= size)
101             {
102 0           result->curr_entry = &named_character_references[pos];
103            
104 0 0         if(named_character_references[pos].codepoints_len) {
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 256 50         if(u_begin[*offset] == '&') {
113 0           result->is_done = 1;
114 0           result->curr_entry = &named_character_references[pos];
115            
116 0 0         if(result->curr_entry->codepoints_len)
117 0           return result->curr_entry;
118 0 0         else if(result->last_entry) {
119 0           *offset = result->last_offset;
120 0           return result->last_entry;
121             }
122            
123 0           return &named_character_references[0];
124             }
125            
126 256 100         if(named_character_references[pos].codepoints_len) {
127 128           result->last_offset = *offset;
128 128           result->last_entry = &named_character_references[pos];
129             }
130            
131 256           pos = named_character_references[pos].next;
132             }
133 1504 50         else if(u_begin[*offset] > named_character_references[pos].ch) {
134 1504           pos++;
135             }
136             else {
137 0           break;
138             }
139             }
140            
141 0           result->is_done = 1;
142            
143 0 0         if(result->last_entry) {
144 0           *offset = result->last_offset;
145 0           return result->last_entry;
146             }
147            
148 0           return &named_character_references[0];
149             }
150              
151