third_party/modest/source/myhtml/mynamespace.c

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 89 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« third_party/modest/source/myhtml/myhtml.c ↑ Summary third_party/modest/source/myhtml/mystring.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/mynamespace.h"
22 #include "myhtml/mynamespace_resource.h"
23 #include "mycore/utils/resources.h"
24  
25 0 const myhtml_namespace_detect_name_entry_t * myhtml_namespace_name_entry_by_name(const char* name, size_t length)
26 {
27 0 size_t idx = ((mycore_string_chars_lowercase_map[ (const unsigned char)name[0] ] *
28 0 mycore_string_chars_lowercase_map[ (const unsigned char)name[(length - 1)] ] *
29 length)
30 0 % MyHTML_NAMESPACE_DETECT_NAME_STATIC_SIZE) + 1;
31
32 0 ▶ while (myhtml_namespace_detect_name_entry_static_list_index[idx].name)
Branch: 1 branch
BranchTrueFalseTotal
while (myhtml_namespace_detect_name_entry_static_list_index[idx].name) 0 0 0
33 {
34 0 ▶ if(myhtml_namespace_detect_name_entry_static_list_index[idx].name_length == length) {
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_namespace_detect_name_entry_static_list_index[idx].name_length == length) { 0 0 0
35 0 ▶ if(mycore_strncasecmp(myhtml_namespace_detect_name_entry_static_list_index[idx].name, name, length) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(mycore_strncasecmp(myhtml_namespace_detect_name_entry_static_list_index[idx].name, name, length) == 0) 0 0 0
36 0 return &myhtml_namespace_detect_name_entry_static_list_index[idx];
37
38 0 ▶ if(myhtml_namespace_detect_name_entry_static_list_index[idx].next)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_namespace_detect_name_entry_static_list_index[idx].next) 0 0 0
39 0 idx = myhtml_namespace_detect_name_entry_static_list_index[idx].next;
40 else
41 0 return NULL;
42 }
43 0 ▶ else if(myhtml_namespace_detect_name_entry_static_list_index[idx].name_length > length) {
Branch: 1 branch
BranchTrueFalseTotal
else if(myhtml_namespace_detect_name_entry_static_list_index[idx].name_length > length) { 0 0 0
44 0 return NULL;
45 }
46 else {
47 0 idx = myhtml_namespace_detect_name_entry_static_list_index[idx].next;
48 }
49 }
50
51 0 return NULL;
52 }
53  
54 0 bool myhtml_namespace_id_by_name(const char *name, size_t length, myhtml_namespace_t *ns)
55 {
56 0 const myhtml_namespace_detect_name_entry_t *entry = myhtml_namespace_name_entry_by_name(name, length);
57
58 0 ▶ if(entry) {
Branch: 1 branch
BranchTrueFalseTotal
if(entry) { 0 0 0
59 0 ▶ if(ns)
Branch: 1 branch
BranchTrueFalseTotal
if(ns) 0 0 0
60 0 *ns = entry->ns;
61
62 0 return true;
63 }
64
65 0 return false;
66 }
67  
68 0 const char * myhtml_namespace_name_by_id(myhtml_namespace_t ns, size_t *length)
69 {
70 0 ▶ if(ns > MyHTML_NAMESPACE_LAST_ENTRY) {
Branch: 1 branch
BranchTrueFalseTotal
if(ns > MyHTML_NAMESPACE_LAST_ENTRY) { 0 0 0
71 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
72 0 *length = 0;
73
74 0 return NULL;
75 }
76
77 0 const char *name_ns = myhtml_namespace_resource_names_map[ns];
78
79 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
80 0 *length = strlen(name_ns);
81
82 0 return name_ns;
83 }
84  
85 0 const char * myhtml_namespace_url_by_id(myhtml_namespace_t ns, size_t *length)
86 {
87 0 ▶ if(ns > MyHTML_NAMESPACE_LAST_ENTRY) {
Branch: 1 branch
BranchTrueFalseTotal
if(ns > MyHTML_NAMESPACE_LAST_ENTRY) { 0 0 0
88 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
89 0 *length = 0;
90
91 0 return NULL;
92 }
93
94 0 const myhtml_namespace_detect_url_entry_t *url_entry = &myhtml_namespace_detect_url_entry_static_list_index[ns];
95
96 0 ▶ if(length) {
Branch: 1 branch
BranchTrueFalseTotal
if(length) { 0 0 0
97 0 *length = url_entry->url_length;
98 }
99
100 0 return url_entry->url;
101 }
102  
103 0 myhtml_namespace_t myhtml_namespace_id_by_url(const char *url, size_t length)
104 {
105 0 size_t i = 0;
106 0 ▶ while(myhtml_namespace_detect_url_entry_static_list_index[i].ns)
Branch: 1 branch
BranchTrueFalseTotal
while(myhtml_namespace_detect_url_entry_static_list_index[i].ns) 0 0 0
107 {
108 0 ▶ if(myhtml_namespace_detect_url_entry_static_list_index[i].url_length == length) {
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_namespace_detect_url_entry_static_list_index[i].url_length == length) { 0 0 0
109 0 size_t k = length;
110
111 0 const unsigned char *u_url = (const unsigned char*)myhtml_namespace_detect_url_entry_static_list_index[i].url;
112 0 const unsigned char *u_target_url = (const unsigned char*)url;
113
114 0 ▶ while(k) {
Branch: 1 branch
BranchTrueFalseTotal
while(k) { 0 0 0
115 0 k--;
116
117 0 ▶ if(u_url[k] != u_target_url[k]) {
Branch: 1 branch
BranchTrueFalseTotal
if(u_url[k] != u_target_url[k]) { 0 0 0
118 0 i++;
119 0 continue;
120 }
121 }
122
123 0 return myhtml_namespace_detect_url_entry_static_list_index[i].ns;
124 }
125
126 0 i++;
127 }
128
129 0 return MyHTML_NAMESPACE_UNDEF;
130 }
131  
132  
« third_party/modest/source/myhtml/myhtml.c ↑ Summary third_party/modest/source/myhtml/mystring.c »