|
3 | 3 |
|
4 | 4 | static inline int is_utf8(const char *s, int len) |
5 | 5 | { |
6 | | - int i; |
7 | | - const unsigned char *bytes = (const unsigned char *)s; |
8 | | - |
9 | | - if (len < 1) { |
10 | | - /* NOTE: always return 1 when passed string is null */ |
11 | | - return 1; |
12 | | - } |
13 | | - |
14 | | - for (i = 0; i < len; i++) { |
15 | | - /* ASCII */ |
16 | | - if (bytes[0] == 0x09 || |
17 | | - bytes[0] == 0x0A || |
18 | | - bytes[0] == 0x0D || |
19 | | - (bytes[0] >= 0x20 && bytes[0] <= 0x7E) |
20 | | - ) { |
21 | | - bytes += 1; |
22 | | - continue; |
23 | | - } |
24 | | - |
25 | | - /* non-overlong 2-byte */ |
26 | | - if (((i+1) <= len) && |
27 | | - (bytes[0] >= 0xC2 && bytes[0] <= 0xDF) && |
28 | | - (bytes[1] >= 0x80 && bytes[1] <= 0xBF)) { |
29 | | - bytes += 2; |
30 | | - i+=1; |
31 | | - continue; |
32 | | - } |
33 | | - |
34 | | - /* excluding overlongs */ |
35 | | - if (((i+2) <= len) && |
36 | | - bytes[0] == 0xE0 && |
37 | | - (bytes[1] >= 0xA0 && bytes[1] <= 0xBF) && |
38 | | - (bytes[2] >= 0x80 && bytes[2] <= 0xBF) |
39 | | - ) { |
40 | | - bytes += 3; |
41 | | - i+=2; |
42 | | - continue; |
43 | | - } |
44 | | - |
45 | | - /* straight 3-byte */ |
46 | | - if (((i+2) <= len) && |
47 | | - ((bytes[0] >= 0xE1 && bytes[0] <= 0xEC) || |
48 | | - bytes[0] == 0xEE || |
49 | | - bytes[0] == 0xEF) && |
50 | | - (bytes[1] >= 0x80 && bytes[1] <= 0xBF) && |
51 | | - (bytes[2] >= 0x80 && bytes[2] <= 0xBF) |
52 | | - ) { |
53 | | - bytes += 3; |
54 | | - i+=2; |
55 | | - continue; |
56 | | - } |
57 | | - |
58 | | - /* excluding surrogates */ |
59 | | - if (((i+2) <= len) && |
60 | | - bytes[0] == 0xED && |
61 | | - (bytes[1] >= 0x80 && bytes[1] <= 0x9F) && |
62 | | - (bytes[2] >= 0x80 && bytes[2] <= 0xBF) |
63 | | - ) { |
64 | | - bytes += 3; |
65 | | - i+=2; |
66 | | - continue; |
67 | | - } |
68 | | - |
69 | | - /* planes 1-3 */ |
70 | | - if (((i+3) <= len) && |
71 | | - bytes[0] == 0xF0 && |
72 | | - (bytes[1] >= 0x90 && bytes[1] <= 0xBF) && |
73 | | - (bytes[2] >= 0x80 && bytes[2] <= 0xBF) && |
74 | | - (bytes[3] >= 0x80 && bytes[3] <= 0xBF) |
75 | | - ) { |
76 | | - bytes += 4; |
77 | | - i+=3; |
78 | | - continue; |
79 | | - } |
80 | | - |
81 | | - /* planes 4-15 */ |
82 | | - if (((i+3) <= len) && |
83 | | - bytes[0] >= 0xF1 && bytes[0] <= 0xF3 && |
84 | | - bytes[1] >= 0x80 && bytes[1] <= 0xBF && |
85 | | - bytes[2] >= 0x80 && bytes[2] <= 0xBF && |
86 | | - bytes[3] >= 0x80 && bytes[3] <= 0xBF |
87 | | - ) { |
88 | | - bytes += 4; |
89 | | - i+=3; |
90 | | - continue; |
91 | | - } |
92 | | - |
93 | | - /* plane 16 */ |
94 | | - if (((i+3) <= len) && |
95 | | - bytes[0] == 0xF4 && |
96 | | - (bytes[1] >= 0x80 && bytes[1] <= 0x8F) && |
97 | | - (bytes[2] >= 0x80 && bytes[2] <= 0xBF) && |
98 | | - (bytes[3] >= 0x80 && bytes[3] <= 0xBF) |
99 | | - ) { |
100 | | - bytes += 4; |
101 | | - i+=3; |
102 | | - continue; |
103 | | - } |
104 | | - |
105 | | - return 0; |
106 | | - } |
107 | | - |
108 | | - return 1; |
| 6 | + int i; |
| 7 | + const unsigned char *bytes = (const unsigned char *)s; |
| 8 | + |
| 9 | + if (len < 1) { |
| 10 | + /* NOTE: always return 1 when passed string is null */ |
| 11 | + return 1; |
| 12 | + } |
| 13 | + |
| 14 | + for (i = 0; i < len; i++) { |
| 15 | + /* ASCII */ |
| 16 | + if (bytes[0] == 0x09 || |
| 17 | + bytes[0] == 0x0A || |
| 18 | + bytes[0] == 0x0D || |
| 19 | + (bytes[0] >= 0x20 && bytes[0] <= 0x7E) |
| 20 | + ) { |
| 21 | + bytes += 1; |
| 22 | + continue; |
| 23 | + } |
| 24 | + |
| 25 | + /* non-overlong 2-byte */ |
| 26 | + if (((i+1) <= len) && |
| 27 | + (bytes[0] >= 0xC2 && bytes[0] <= 0xDF) && |
| 28 | + (bytes[1] >= 0x80 && bytes[1] <= 0xBF)) { |
| 29 | + bytes += 2; |
| 30 | + i+=1; |
| 31 | + continue; |
| 32 | + } |
| 33 | + |
| 34 | + /* excluding overlongs */ |
| 35 | + if (((i+2) <= len) && |
| 36 | + bytes[0] == 0xE0 && |
| 37 | + (bytes[1] >= 0xA0 && bytes[1] <= 0xBF) && |
| 38 | + (bytes[2] >= 0x80 && bytes[2] <= 0xBF) |
| 39 | + ) { |
| 40 | + bytes += 3; |
| 41 | + i+=2; |
| 42 | + continue; |
| 43 | + } |
| 44 | + |
| 45 | + /* straight 3-byte */ |
| 46 | + if (((i+2) <= len) && |
| 47 | + ((bytes[0] >= 0xE1 && bytes[0] <= 0xEC) || |
| 48 | + bytes[0] == 0xEE || |
| 49 | + bytes[0] == 0xEF) && |
| 50 | + (bytes[1] >= 0x80 && bytes[1] <= 0xBF) && |
| 51 | + (bytes[2] >= 0x80 && bytes[2] <= 0xBF) |
| 52 | + ) { |
| 53 | + bytes += 3; |
| 54 | + i+=2; |
| 55 | + continue; |
| 56 | + } |
| 57 | + |
| 58 | + /* excluding surrogates */ |
| 59 | + if (((i+2) <= len) && |
| 60 | + bytes[0] == 0xED && |
| 61 | + (bytes[1] >= 0x80 && bytes[1] <= 0x9F) && |
| 62 | + (bytes[2] >= 0x80 && bytes[2] <= 0xBF) |
| 63 | + ) { |
| 64 | + bytes += 3; |
| 65 | + i+=2; |
| 66 | + continue; |
| 67 | + } |
| 68 | + |
| 69 | + /* planes 1-3 */ |
| 70 | + if (((i+3) <= len) && |
| 71 | + bytes[0] == 0xF0 && |
| 72 | + (bytes[1] >= 0x90 && bytes[1] <= 0xBF) && |
| 73 | + (bytes[2] >= 0x80 && bytes[2] <= 0xBF) && |
| 74 | + (bytes[3] >= 0x80 && bytes[3] <= 0xBF) |
| 75 | + ) { |
| 76 | + bytes += 4; |
| 77 | + i+=3; |
| 78 | + continue; |
| 79 | + } |
| 80 | + |
| 81 | + /* planes 4-15 */ |
| 82 | + if (((i+3) <= len) && |
| 83 | + bytes[0] >= 0xF1 && bytes[0] <= 0xF3 && |
| 84 | + bytes[1] >= 0x80 && bytes[1] <= 0xBF && |
| 85 | + bytes[2] >= 0x80 && bytes[2] <= 0xBF && |
| 86 | + bytes[3] >= 0x80 && bytes[3] <= 0xBF |
| 87 | + ) { |
| 88 | + bytes += 4; |
| 89 | + i+=3; |
| 90 | + continue; |
| 91 | + } |
| 92 | + |
| 93 | + /* plane 16 */ |
| 94 | + if (((i+3) <= len) && |
| 95 | + bytes[0] == 0xF4 && |
| 96 | + (bytes[1] >= 0x80 && bytes[1] <= 0x8F) && |
| 97 | + (bytes[2] >= 0x80 && bytes[2] <= 0xBF) && |
| 98 | + (bytes[3] >= 0x80 && bytes[3] <= 0xBF) |
| 99 | + ) { |
| 100 | + bytes += 4; |
| 101 | + i+=3; |
| 102 | + continue; |
| 103 | + } |
| 104 | + |
| 105 | + return 0; |
| 106 | + } |
| 107 | + |
| 108 | + return 1; |
109 | 109 | } |
110 | 110 |
|
111 | 111 |
|
112 | 112 | static inline uint32_t zigzag_encode32(int32_t n) { |
113 | | - // Note: the right-shift must be arithmetic |
114 | | - return (n << 1) ^ (n >> 31); |
| 113 | + // Note: the right-shift must be arithmetic |
| 114 | + return (n << 1) ^ (n >> 31); |
115 | 115 | } |
116 | 116 |
|
117 | 117 | static inline int32_t zigzag_decode32(uint32_t n) { |
118 | | - return (n >> 1) ^ - (int32_t)(n & 1); |
| 118 | + return (n >> 1) ^ - (int32_t)(n & 1); |
119 | 119 | } |
120 | 120 |
|
121 | 121 | static inline uint64_t zigzag_encode64(int64_t n) { |
122 | | - // Note: the right-shift must be arithmetic |
123 | | - return (n << 1) ^ (n >> 63); |
| 122 | + // Note: the right-shift must be arithmetic |
| 123 | + return (n << 1) ^ (n >> 63); |
124 | 124 | } |
125 | 125 |
|
126 | 126 | static inline int64_t zigzag_decode64(uint64_t n) { |
127 | | - return (n >> 1) ^ - (int64_t)(n & 1); |
| 127 | + return (n >> 1) ^ - (int64_t)(n & 1); |
128 | 128 | } |
129 | 129 |
|
130 | 130 | static inline uint64_t encode_double(double value) { |
131 | | - union { |
132 | | - double d; |
133 | | - uint64_t v; |
134 | | - } u; |
135 | | - u.d = value; |
| 131 | + union { |
| 132 | + double d; |
| 133 | + uint64_t v; |
| 134 | + } u; |
| 135 | + u.d = value; |
136 | 136 |
|
137 | | - return u.v; |
| 137 | + return u.v; |
138 | 138 | } |
139 | 139 |
|
140 | 140 | static inline double decode_double(uint64_t value) { |
141 | | - union { |
142 | | - double d; |
143 | | - uint64_t v; |
144 | | - } u; |
145 | | - u.v = value; |
| 141 | + union { |
| 142 | + double d; |
| 143 | + uint64_t v; |
| 144 | + } u; |
| 145 | + u.v = value; |
146 | 146 |
|
147 | | - return u.d; |
| 147 | + return u.d; |
148 | 148 | } |
149 | 149 |
|
150 | 150 | static inline uint32_t encode_float(float value) { |
151 | | - union { |
152 | | - float f; |
153 | | - uint32_t v; |
154 | | - } u; |
155 | | - u.f = value; |
| 151 | + union { |
| 152 | + float f; |
| 153 | + uint32_t v; |
| 154 | + } u; |
| 155 | + u.f = value; |
156 | 156 |
|
157 | | - return u.v; |
| 157 | + return u.v; |
158 | 158 | } |
159 | 159 |
|
160 | 160 | static inline float decode_float(int32_t value) { |
161 | | - union { |
162 | | - float f; |
163 | | - uint32_t v; |
164 | | - } u; |
165 | | - u.v = value; |
| 161 | + union { |
| 162 | + float f; |
| 163 | + uint32_t v; |
| 164 | + } u; |
| 165 | + u.v = value; |
166 | 166 |
|
167 | | - return u.f; |
| 167 | + return u.f; |
168 | 168 | } |
169 | 169 |
|
170 | 170 | static inline int php_protocolbuffers_get_lval_from_hash_by_tag(HashTable *proto, ulong tag, const char *name, size_t name_len TSRMLS_DC) |
171 | 171 | { |
172 | | - zval **d, **dd; |
| 172 | + zval **d, **dd; |
173 | 173 |
|
174 | | - if (zend_hash_index_find(proto, tag, (void **)&d) != SUCCESS) { |
175 | | - return 0; |
176 | | - } |
| 174 | + if (zend_hash_index_find(proto, tag, (void **)&d) != SUCCESS) { |
| 175 | + return 0; |
| 176 | + } |
177 | 177 |
|
178 | | - if (Z_TYPE_PP(d) != IS_ARRAY) { |
179 | | - return 0; |
180 | | - } |
| 178 | + if (Z_TYPE_PP(d) != IS_ARRAY) { |
| 179 | + return 0; |
| 180 | + } |
181 | 181 |
|
182 | | - if (zend_hash_find(Z_ARRVAL_PP(d), (char*)name, name_len, (void **)&dd) == SUCCESS) { |
183 | | - return Z_LVAL_PP(dd); |
184 | | - } |
| 182 | + if (zend_hash_find(Z_ARRVAL_PP(d), (char*)name, name_len, (void **)&dd) == SUCCESS) { |
| 183 | + return Z_LVAL_PP(dd); |
| 184 | + } |
185 | 185 |
|
186 | | - return 0; |
| 186 | + return 0; |
187 | 187 | } |
188 | 188 |
|
189 | 189 | static inline int php_protocolbuffers_get_zval_from_hash_by_tag(HashTable *proto, ulong tag, const char *name, size_t name_len, zval **result TSRMLS_DC) |
190 | 190 | { |
191 | | - zval **d, **dd; |
| 191 | + zval **d, **dd; |
192 | 192 |
|
193 | | - if (zend_hash_index_find(proto, tag, (void **)&d) != SUCCESS) { |
194 | | - return 0; |
195 | | - } |
| 193 | + if (zend_hash_index_find(proto, tag, (void **)&d) != SUCCESS) { |
| 194 | + return 0; |
| 195 | + } |
196 | 196 |
|
197 | | - if (Z_TYPE_PP(d) != IS_ARRAY) { |
198 | | - return 0; |
199 | | - } |
| 197 | + if (Z_TYPE_PP(d) != IS_ARRAY) { |
| 198 | + return 0; |
| 199 | + } |
200 | 200 |
|
201 | | - if (zend_hash_find(Z_ARRVAL_PP(d), (char*)name, name_len, (void **)&dd) == SUCCESS) { |
202 | | - *result = *dd; |
203 | | - return 1; |
204 | | - } |
| 201 | + if (zend_hash_find(Z_ARRVAL_PP(d), (char*)name, name_len, (void **)&dd) == SUCCESS) { |
| 202 | + *result = *dd; |
| 203 | + return 1; |
| 204 | + } |
205 | 205 |
|
206 | | - return 0; |
| 206 | + return 0; |
207 | 207 | } |
208 | 208 |
|
209 | 209 | static inline const char* ReadVarint32FromArray(const char* buffer, uint* value, const char* buffer_end) { |
|
0 commit comments