line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
Copyright (C) 2016-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 "mycss/check.h" |
22
|
|
|
|
|
|
|
#include "mycss/tokenizer_resource.h" |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#define MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED \ |
25
|
|
|
|
|
|
|
if(css_offset >= buffer->size) { \ |
26
|
|
|
|
|
|
|
buffer = buffer->next; \ |
27
|
|
|
|
|
|
|
css_offset = 0; \ |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
///////////////////////////////////////////////////////// |
31
|
|
|
|
|
|
|
//// For chunk |
32
|
|
|
|
|
|
|
//// |
33
|
|
|
|
|
|
|
///////////////////////////////////////////////////////// |
34
|
0
|
|
|
|
|
|
bool mycss_check_two_code_points_valid_escape_chunk(mycss_entry_t* entry, size_t css_offset) |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
|
|
|
mycore_incoming_buffer_t* buffer = entry->current_buffer; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if(buffer->data[css_offset] == '\\') { |
41
|
0
|
|
|
|
|
|
++css_offset; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if(buffer->data[css_offset] != '\n') |
46
|
0
|
|
|
|
|
|
return true; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return false; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
bool mycss_check_three_code_points_would_start_identifier_chunk(mycss_entry_t* entry, size_t css_offset) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
|
mycore_incoming_buffer_t* buffer = entry->current_buffer; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED |
57
|
0
|
|
|
|
|
|
const unsigned char *u_css = (const unsigned char*)buffer->data; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if(buffer->data[css_offset] == '-') |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
|
++css_offset; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED |
64
|
0
|
|
|
|
|
|
u_css = (const unsigned char*)buffer->data; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if(buffer->data[css_offset] == '-' || |
|
|
0
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
mycss_begin_chars_state_map[ u_css[css_offset] ] == MyCSS_TOKENIZER_STATE_NAME_START_CODE_POINT || |
68
|
0
|
|
|
|
|
|
mycss_check_two_code_points_valid_escape_chunk(entry, css_offset)) |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
|
|
|
return true; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
0
|
0
|
|
|
|
|
else if(mycss_begin_chars_state_map[ u_css[css_offset] ] == MyCSS_TOKENIZER_STATE_NAME_START_CODE_POINT) { |
74
|
0
|
|
|
|
|
|
return true; |
75
|
|
|
|
|
|
|
} |
76
|
0
|
0
|
|
|
|
|
else if(buffer->data[css_offset] == '\\' && mycss_check_two_code_points_valid_escape_chunk(entry, css_offset)) { |
|
|
0
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return true; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return false; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
bool mycss_check_three_code_points_would_start_number_chunk(mycss_entry_t* entry, size_t css_offset) |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
|
|
|
|
|
mycore_incoming_buffer_t* buffer = entry->current_buffer; |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if(buffer->data[css_offset] == '-' || buffer->data[css_offset] == '+') |
|
|
0
|
|
|
|
|
|
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
|
|
|
++css_offset; |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if(buffer->data[css_offset] >= '0' && buffer->data[css_offset] <= '9') |
|
|
0
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return true; |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
if(buffer->data[css_offset] == '.') { |
99
|
0
|
|
|
|
|
|
++css_offset; |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
if(buffer->data[css_offset] >= '0' && buffer->data[css_offset] <= '9') |
|
|
0
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
return true; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
0
|
0
|
|
|
|
|
else if(buffer->data[css_offset] == '.') { |
108
|
0
|
|
|
|
|
|
++css_offset; |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
MyCSS_CHECK_CHUNK_POSITION_AND_SET_IF_NEED |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if(buffer->data[css_offset] >= '0' && buffer->data[css_offset] <= '9') |
|
|
0
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return true; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
0
|
|
|
|
|
else if(buffer->data[css_offset] >= '0' && buffer->data[css_offset] <= '9') |
|
|
0
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return true; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return false; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
///////////////////////////////////////////////////////// |
122
|
|
|
|
|
|
|
//// basic checks |
123
|
|
|
|
|
|
|
//// |
124
|
|
|
|
|
|
|
///////////////////////////////////////////////////////// |
125
|
0
|
|
|
|
|
|
bool mycss_check_three_code_points_would_start_identifier(mycss_entry_t* entry, mycss_token_t* token, const char* css, size_t css_offset, size_t css_size) |
126
|
|
|
|
|
|
|
{ |
127
|
0
|
0
|
|
|
|
|
if(css_offset >= css_size) |
128
|
0
|
|
|
|
|
|
return mycss_check_three_code_points_would_start_identifier_chunk(entry, css_offset); |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
const unsigned char *u_css = (const unsigned char*)css; |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
if(css[css_offset] == '-') |
133
|
|
|
|
|
|
|
{ |
134
|
0
|
|
|
|
|
|
++css_offset; |
135
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
if(css[css_offset] == '-' || |
|
|
0
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
mycss_begin_chars_state_map[ u_css[css_offset] ] == MyCSS_TOKENIZER_STATE_NAME_START_CODE_POINT || |
138
|
0
|
|
|
|
|
|
mycss_check_two_code_points_valid_escape(entry, token, css, css_offset, css_size)) |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
|
|
|
|
|
return true; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
0
|
0
|
|
|
|
|
else if(mycss_begin_chars_state_map[ u_css[css_offset] ] == MyCSS_TOKENIZER_STATE_NAME_START_CODE_POINT) { |
144
|
0
|
|
|
|
|
|
return true; |
145
|
|
|
|
|
|
|
} |
146
|
0
|
0
|
|
|
|
|
else if(css[css_offset] == '\\' && mycss_check_two_code_points_valid_escape(entry, token, css, css_offset, css_size)) { |
|
|
0
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return true; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
return false; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
bool mycss_check_two_code_points_valid_escape(mycss_entry_t* entry, mycss_token_t* token, const char* css, size_t css_offset, size_t css_size) |
154
|
|
|
|
|
|
|
{ |
155
|
0
|
0
|
|
|
|
|
if(css_offset >= css_size) |
156
|
0
|
|
|
|
|
|
return mycss_check_two_code_points_valid_escape_chunk(entry, css_offset); |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
|
if(css[css_offset] == '\\' && css[(css_offset + 1)] != '\n') |
|
|
0
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
return true; |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
return false; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
bool mycss_check_three_code_points_would_start_number(mycss_entry_t* entry, mycss_token_t* token, const char* css, size_t css_offset, size_t css_size) |
165
|
|
|
|
|
|
|
{ |
166
|
0
|
0
|
|
|
|
|
if(css_offset >= css_size) |
167
|
0
|
|
|
|
|
|
return mycss_check_three_code_points_would_start_number_chunk(entry, css_offset); |
168
|
|
|
|
|
|
|
|
169
|
0
|
0
|
|
|
|
|
if(css[css_offset] == '-' || css[css_offset] == '+') |
|
|
0
|
|
|
|
|
|
170
|
|
|
|
|
|
|
{ |
171
|
0
|
|
|
|
|
|
++css_offset; |
172
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
|
if(css[css_offset] >= '0' && css[css_offset] <= '9') |
|
|
0
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
return true; |
175
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
if(css[css_offset] == '.') { |
177
|
0
|
|
|
|
|
|
++css_offset; |
178
|
|
|
|
|
|
|
|
179
|
0
|
0
|
|
|
|
|
if(css[css_offset] >= '0' && css[css_offset] <= '9') |
|
|
0
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
return true; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
0
|
0
|
|
|
|
|
else if(css[css_offset] == '.') { |
184
|
0
|
|
|
|
|
|
++css_offset; |
185
|
|
|
|
|
|
|
|
186
|
0
|
0
|
|
|
|
|
if(css[css_offset] >= '0' && css[css_offset] <= '9') |
|
|
0
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
return true; |
188
|
|
|
|
|
|
|
} |
189
|
0
|
0
|
|
|
|
|
else if(css[css_offset] >= '0' && css[css_offset] <= '9') |
|
|
0
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
return true; |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
return false; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|