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/mynamespace.h" |
22
|
|
|
|
|
|
|
#include "myhtml/mynamespace_resource.h" |
23
|
|
|
|
|
|
|
#include "mycore/utils/resources.h" |
24
|
|
|
|
|
|
|
|
25
|
7
|
|
|
|
|
|
const myhtml_namespace_detect_name_entry_t * myhtml_namespace_name_entry_by_name(const char* name, size_t length) |
26
|
|
|
|
|
|
|
{ |
27
|
21
|
|
|
|
|
|
size_t idx = ((mycore_string_chars_lowercase_map[ (const unsigned char)name[0] ] * |
28
|
14
|
|
|
|
|
|
mycore_string_chars_lowercase_map[ (const unsigned char)name[(length - 1)] ] * |
29
|
|
|
|
|
|
|
length) |
30
|
7
|
|
|
|
|
|
% MyHTML_NAMESPACE_DETECT_NAME_STATIC_SIZE) + 1; |
31
|
|
|
|
|
|
|
|
32
|
7
|
100
|
|
|
|
|
while (myhtml_namespace_detect_name_entry_static_list_index[idx].name) |
33
|
|
|
|
|
|
|
{ |
34
|
5
|
50
|
|
|
|
|
if(myhtml_namespace_detect_name_entry_static_list_index[idx].name_length == length) { |
35
|
5
|
50
|
|
|
|
|
if(mycore_strncasecmp(myhtml_namespace_detect_name_entry_static_list_index[idx].name, name, length) == 0) |
36
|
5
|
|
|
|
|
|
return &myhtml_namespace_detect_name_entry_static_list_index[idx]; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
if(myhtml_namespace_detect_name_entry_static_list_index[idx].next) |
39
|
0
|
|
|
|
|
|
idx = myhtml_namespace_detect_name_entry_static_list_index[idx].next; |
40
|
|
|
|
|
|
|
else |
41
|
0
|
|
|
|
|
|
return NULL; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
0
|
|
|
|
|
else if(myhtml_namespace_detect_name_entry_static_list_index[idx].name_length > length) { |
44
|
0
|
|
|
|
|
|
return NULL; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
0
|
|
|
|
|
|
idx = myhtml_namespace_detect_name_entry_static_list_index[idx].next; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
|
return NULL; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
7
|
|
|
|
|
|
bool myhtml_namespace_id_by_name(const char *name, size_t length, myhtml_namespace_t *ns) |
55
|
|
|
|
|
|
|
{ |
56
|
7
|
|
|
|
|
|
const myhtml_namespace_detect_name_entry_t *entry = myhtml_namespace_name_entry_by_name(name, length); |
57
|
|
|
|
|
|
|
|
58
|
7
|
100
|
|
|
|
|
if(entry) { |
59
|
5
|
50
|
|
|
|
|
if(ns) |
60
|
5
|
|
|
|
|
|
*ns = entry->ns; |
61
|
|
|
|
|
|
|
|
62
|
5
|
|
|
|
|
|
return true; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
|
return false; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
13
|
|
|
|
|
|
const char * myhtml_namespace_name_by_id(myhtml_namespace_t ns, size_t *length) |
69
|
|
|
|
|
|
|
{ |
70
|
13
|
100
|
|
|
|
|
if(ns > MyHTML_NAMESPACE_LAST_ENTRY) { |
71
|
2
|
100
|
|
|
|
|
if(length) |
72
|
1
|
|
|
|
|
|
*length = 0; |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
|
return NULL; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
11
|
|
|
|
|
|
const char *name_ns = myhtml_namespace_resource_names_map[ns]; |
78
|
|
|
|
|
|
|
|
79
|
11
|
100
|
|
|
|
|
if(length) |
80
|
10
|
|
|
|
|
|
*length = strlen(name_ns); |
81
|
|
|
|
|
|
|
|
82
|
11
|
|
|
|
|
|
return name_ns; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
const char * myhtml_namespace_url_by_id(myhtml_namespace_t ns, size_t *length) |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
0
|
|
|
|
|
if(ns > MyHTML_NAMESPACE_LAST_ENTRY) { |
88
|
0
|
0
|
|
|
|
|
if(length) |
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
|
0
|
|
|
|
|
if(length) { |
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
|
0
|
|
|
|
|
while(myhtml_namespace_detect_url_entry_static_list_index[i].ns) |
107
|
|
|
|
|
|
|
{ |
108
|
0
|
0
|
|
|
|
|
if(myhtml_namespace_detect_url_entry_static_list_index[i].url_length == length) { |
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
|
0
|
|
|
|
|
while(k) { |
115
|
0
|
|
|
|
|
|
k--; |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if(u_url[k] != u_target_url[k]) { |
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
|
|
|
|
|
|
|
|