Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * chvalid.c: this module implements the character range |
3 | | * validation APIs |
4 | | */ |
5 | | |
6 | | #define IN_LIBXML |
7 | | #include "libxml.h" |
8 | | #include <libxml/chvalid.h> |
9 | | |
10 | | #include <stddef.h> |
11 | | |
12 | | /* |
13 | | * The initial tables ({func_name}_tab) are used to validate whether a |
14 | | * single-byte character is within the specified group. Each table |
15 | | * contains 256 bytes, with each byte representing one of the 256 |
16 | | * possible characters. If the table byte is set, the character is |
17 | | * allowed. |
18 | | * |
19 | | */ |
20 | | |
21 | | #include "codegen/ranges.inc" |
22 | | |
23 | | /** |
24 | | * Does a binary search of the range table to determine if char |
25 | | * is valid |
26 | | * |
27 | | * @param val character to be validated |
28 | | * @param rptr pointer to range to be used to validate |
29 | | * @returns true if character valid, false otherwise |
30 | | */ |
31 | | int |
32 | 25.6k | xmlCharInRange (unsigned int val, const xmlChRangeGroup *rptr) { |
33 | 25.6k | int low, high, mid; |
34 | 25.6k | const xmlChSRange *sptr; |
35 | 25.6k | const xmlChLRange *lptr; |
36 | | |
37 | 25.6k | if (rptr == NULL) return(0); |
38 | 25.6k | if (val < 0x10000) { /* is val in 'short' or 'long' array? */ |
39 | 17.9k | if (rptr->nbShortRange == 0) |
40 | 0 | return 0; |
41 | 17.9k | low = 0; |
42 | 17.9k | high = rptr->nbShortRange - 1; |
43 | 17.9k | sptr = rptr->shortRange; |
44 | 128k | while (low <= high) { |
45 | 123k | mid = (low + high) / 2; |
46 | 123k | if ((unsigned short) val < sptr[mid].low) { |
47 | 23.7k | high = mid - 1; |
48 | 99.2k | } else { |
49 | 99.2k | if ((unsigned short) val > sptr[mid].high) { |
50 | 86.6k | low = mid + 1; |
51 | 86.6k | } else { |
52 | 12.6k | return 1; |
53 | 12.6k | } |
54 | 99.2k | } |
55 | 123k | } |
56 | 17.9k | } else { |
57 | 7.71k | if (rptr->nbLongRange == 0) { |
58 | 7.71k | return 0; |
59 | 7.71k | } |
60 | 0 | low = 0; |
61 | 0 | high = rptr->nbLongRange - 1; |
62 | 0 | lptr = rptr->longRange; |
63 | 0 | while (low <= high) { |
64 | 0 | mid = (low + high) / 2; |
65 | 0 | if (val < lptr[mid].low) { |
66 | 0 | high = mid - 1; |
67 | 0 | } else { |
68 | 0 | if (val > lptr[mid].high) { |
69 | 0 | low = mid + 1; |
70 | 0 | } else { |
71 | 0 | return 1; |
72 | 0 | } |
73 | 0 | } |
74 | 0 | } |
75 | 0 | } |
76 | 5.33k | return 0; |
77 | 25.6k | } |
78 | | |
79 | | |
80 | | /** |
81 | | * @deprecated Use #xmlIsBaseChar_ch or #xmlIsBaseCharQ. |
82 | | * |
83 | | * @param ch character to validate |
84 | | * @returns true if argument valid, false otherwise |
85 | | */ |
86 | | int |
87 | 0 | xmlIsBaseChar(unsigned int ch) { |
88 | 0 | return(xmlIsBaseCharQ(ch)); |
89 | 0 | } |
90 | | |
91 | | |
92 | | /** |
93 | | * @deprecated Use #xmlIsBlank_ch or #xmlIsBlankQ. |
94 | | * |
95 | | * @param ch character to validate |
96 | | * @returns true if argument valid, false otherwise |
97 | | */ |
98 | | int |
99 | 0 | xmlIsBlank(unsigned int ch) { |
100 | 0 | return(xmlIsBlankQ(ch)); |
101 | 0 | } |
102 | | |
103 | | |
104 | | /** |
105 | | * @deprecated Use #xmlIsChar_ch or #xmlIsCharQ. |
106 | | * |
107 | | * @param ch character to validate |
108 | | * @returns true if argument valid, false otherwise |
109 | | */ |
110 | | int |
111 | 0 | xmlIsChar(unsigned int ch) { |
112 | 0 | return(xmlIsCharQ(ch)); |
113 | 0 | } |
114 | | |
115 | | |
116 | | /** |
117 | | * @deprecated Use #xmlIsCombiningQ. |
118 | | * |
119 | | * @param ch character to validate |
120 | | * @returns true if argument valid, false otherwise |
121 | | */ |
122 | | int |
123 | 0 | xmlIsCombining(unsigned int ch) { |
124 | 0 | return(xmlIsCombiningQ(ch)); |
125 | 0 | } |
126 | | |
127 | | |
128 | | /** |
129 | | * @deprecated Use #xmlIsDigit_ch or #xmlIsDigitQ. |
130 | | * |
131 | | * @param ch character to validate |
132 | | * @returns true if argument valid, false otherwise |
133 | | */ |
134 | | int |
135 | 0 | xmlIsDigit(unsigned int ch) { |
136 | 0 | return(xmlIsDigitQ(ch)); |
137 | 0 | } |
138 | | |
139 | | |
140 | | /** |
141 | | * @deprecated Use #xmlIsExtender_ch or #xmlIsExtenderQ. |
142 | | * |
143 | | * @param ch character to validate |
144 | | * @returns true if argument valid, false otherwise |
145 | | */ |
146 | | int |
147 | 0 | xmlIsExtender(unsigned int ch) { |
148 | 0 | return(xmlIsExtenderQ(ch)); |
149 | 0 | } |
150 | | |
151 | | |
152 | | /** |
153 | | * @deprecated Use #xmlIsIdeographicQ. |
154 | | * |
155 | | * @param ch character to validate |
156 | | * @returns true if argument valid, false otherwise |
157 | | */ |
158 | | int |
159 | 0 | xmlIsIdeographic(unsigned int ch) { |
160 | 0 | return(xmlIsIdeographicQ(ch)); |
161 | 0 | } |
162 | | |
163 | | |
164 | | /** |
165 | | * @deprecated Use #xmlIsPubidChar_ch or #xmlIsPubidCharQ. |
166 | | * |
167 | | * @param ch character to validate |
168 | | * @returns true if argument valid, false otherwise |
169 | | */ |
170 | | int |
171 | 0 | xmlIsPubidChar(unsigned int ch) { |
172 | 0 | return(xmlIsPubidCharQ(ch)); |
173 | 0 | } |
174 | | |