1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 26 окт. 2019 г.
7  *
8  * lsp-plugins is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * any later version.
12  *
13  * lsp-plugins is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #include <core/files/xml/const.h>
23 
24 namespace lsp
25 {
26     namespace xml
27     {
is_valid_char(lsp_swchar_t c,xml_version_t version)28         bool is_valid_char(lsp_swchar_t c, xml_version_t version)
29         {
30             if (version == XML_VERSION_1_0)
31             {
32                 if ((c >= 0x20) && (c <= 0xd7ff))
33                     return true;
34                 if ((c == 0x9) || (c == 0xa) || (c == 0xd))
35                     return true;
36             }
37             else
38             {
39                 if ((c >= 1) && (c <= 0xd7ff))
40                     return true;
41             }
42             if ((c >= 0xe000) && (c <= 0xfffd))
43                 return true;
44             return (c >= 0x10000) && (c <= 0x10ffff);
45         }
46 
is_name_first(lsp_swchar_t c)47         bool is_name_first(lsp_swchar_t c)
48         {
49             if ((c >= 'a') && (c <= 'z'))
50                 return true;
51             if ((c >= 'A') && (c <= 'Z'))
52                 return true;
53             if ((c == ':') || (c == '_'))
54                 return true;
55             if ((c >= 0xc0) && (c <= 0xd6))
56                 return true;
57             if ((c >= 0xd8) && (c <= 0xf6))
58                 return true;
59             if ((c >= 0xf8) && (c <= 0x2ff))
60                 return true;
61             if ((c >= 0x370) && (c <= 0x37d))
62                 return true;
63             if ((c >= 0x37f) && (c <= 0x1fff))
64                 return true;
65             if ((c >= 0x200c) && (c <= 0x200d))
66                 return true;
67             if ((c >= 0x2070) && (c <= 0x218f))
68                 return true;
69             if ((c >= 0x2c00) && (c <= 0x2fef))
70                 return true;
71             if ((c >= 0x3001) && (c <= 0xd7ff))
72                 return true;
73             if ((c >= 0xf900) && (c <= 0xfdcf))
74                 return true;
75             if ((c >= 0xfdf0) && (c <= 0xfffd))
76                 return true;
77             if ((c >= 0x10000) && (c <= 0xeffff))
78                 return true;
79 
80             return false;
81         }
82 
is_name_next(lsp_swchar_t c)83         bool is_name_next(lsp_swchar_t c)
84         {
85             if ((c >= '0') && (c <= '9'))
86                 return true;
87             if ((c == '-') || (c == '.') || (c == 0xb7))
88                 return true;
89             if (is_name_first(c))
90                 return true;
91             if ((c >= 0x300) && (c <= 0x36f))
92                 return true;
93             if ((c >= 0x203f) && (c <= 0x2040))
94                 return true;
95             return false;
96         }
97 
is_whitespace(lsp_swchar_t c)98         bool is_whitespace(lsp_swchar_t c)
99         {
100             switch (c)
101             {
102                 case 0x20:
103                 case 0x09:
104                 case 0x0d:
105                 case 0x0a:
106                     return true;
107             }
108             return false;
109         }
110 
is_pubid_char(lsp_swchar_t c)111         bool is_pubid_char(lsp_swchar_t c)
112         {
113             if ((c >= 'a') && (c <= 'z'))
114                 return true;
115             if ((c >= 'A') && (c <= 'Z'))
116                 return true;
117             if ((c >= '0') && (c <= '9'))
118                 return true;
119 
120             switch (c)
121             {
122                 case 0x20: case 0x0d: case 0x0a: case '\'':
123                 case '-': case '(': case ')': case '+':
124                 case ',': case '.': case '/': case ':':
125                 case '=': case '?': case ';': case '!':
126                 case '*': case '#': case '@': case '$':
127                 case '_': case '%':
128                     return true;
129             }
130             return false;
131         }
132 
is_restricted_char(lsp_swchar_t c,xml_version_t version)133         bool is_restricted_char(lsp_swchar_t c, xml_version_t version)
134         {
135             if (version <= XML_VERSION_1_0)
136                 return false;
137 
138             if ((c >= 0x01) && (c <= 0x08))
139                 return true;
140             if ((c >= 0x0b) && (c <= 0x0c))
141                 return true;
142             if ((c >= 0x0e) && (c <= 0x1f))
143                 return true;
144             if ((c >= 0x7f) && (c <= 0x84))
145                 return true;
146             if ((c >= 0x86) && (c <= 0x9f))
147                 return true;
148 
149             return false;
150         }
151 
is_encoding_first(lsp_swchar_t c)152         bool is_encoding_first(lsp_swchar_t c)
153         {
154             if ((c >= 'a') && (c <= 'z'))
155                 return true;
156             if ((c >= 'A') && (c <= 'Z'))
157                 return true;
158             return false;
159         }
160 
is_encoding_next(lsp_swchar_t c)161         bool is_encoding_next(lsp_swchar_t c)
162         {
163             if (is_encoding_first(c))
164                 return true;
165             if ((c >= '0') && (c <= '9'))
166                 return true;
167 
168             return ((c == '_') || (c == '.') || (c == '-'));
169         }
170     }
171 }
172 
173 
174