15
15
16
16
#include <ctype.h>
17
17
18
+ #include "common/hex_decode.h"
18
19
#include "mb/pg_wchar.h"
19
20
#include "utils/builtins.h"
20
21
#include "utils/memutils.h"
@@ -146,17 +147,6 @@ binary_decode(PG_FUNCTION_ARGS)
146
147
147
148
static const char hextbl []= "0123456789abcdef" ;
148
149
149
- static const int8 hexlookup [128 ]= {
150
- -1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,
151
- -1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,
152
- -1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,
153
- 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,
154
- -1 ,10 ,11 ,12 ,13 ,14 ,15 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,
155
- -1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,
156
- -1 ,10 ,11 ,12 ,13 ,14 ,15 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,
157
- -1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,
158
- };
159
-
160
150
uint64
161
151
hex_encode (const char * src ,size_t len ,char * dst )
162
152
{
@@ -171,58 +161,6 @@ hex_encode(const char *src, size_t len, char *dst)
171
161
return (uint64 )len * 2 ;
172
162
}
173
163
174
- static inline char
175
- get_hex (const char * cp )
176
- {
177
- unsignedchar c = (unsignedchar )* cp ;
178
- int res = -1 ;
179
-
180
- if (c < 127 )
181
- res = hexlookup [c ];
182
-
183
- if (res < 0 )
184
- ereport (ERROR ,
185
- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
186
- errmsg ("invalid hexadecimal digit: \"%.*s\"" ,
187
- pg_mblen (cp ),cp )));
188
-
189
- return (char )res ;
190
- }
191
-
192
- uint64
193
- hex_decode (const char * src ,size_t len ,char * dst )
194
- {
195
- const char * s ,
196
- * srcend ;
197
- char v1 ,
198
- v2 ,
199
- * p ;
200
-
201
- srcend = src + len ;
202
- s = src ;
203
- p = dst ;
204
- while (s < srcend )
205
- {
206
- if (* s == ' ' || * s == '\n' || * s == '\t' || * s == '\r' )
207
- {
208
- s ++ ;
209
- continue ;
210
- }
211
- v1 = get_hex (s ) <<4 ;
212
- s ++ ;
213
- if (s >=srcend )
214
- ereport (ERROR ,
215
- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
216
- errmsg ("invalid hexadecimal data: odd number of digits" )));
217
-
218
- v2 = get_hex (s );
219
- s ++ ;
220
- * p ++ = v1 |v2 ;
221
- }
222
-
223
- return p - dst ;
224
- }
225
-
226
164
static uint64
227
165
hex_enc_len (const char * src ,size_t srclen )
228
166
{