|
5 | 5 |
|
6 | 6 | #include<math.h>
|
7 | 7 |
|
8 |
| -#include"common/hex_decode.h" |
9 | 8 | #include"ecpgerrno.h"
|
10 | 9 | #include"ecpglib.h"
|
11 | 10 | #include"ecpglib_extern.h"
|
@@ -137,6 +136,57 @@ ecpg_hex_dec_len(unsigned srclen)
|
137 | 136 | returnsrclen >>1;
|
138 | 137 | }
|
139 | 138 |
|
| 139 | +staticinlinechar |
| 140 | +get_hex(charc) |
| 141 | +{ |
| 142 | +staticconstint8hexlookup[128]= { |
| 143 | +-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 144 | +-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 145 | +-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 146 | +0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1, |
| 147 | +-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 148 | +-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 149 | +-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 150 | +-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 151 | +}; |
| 152 | +intres=-1; |
| 153 | + |
| 154 | +if (c>0&&c<127) |
| 155 | +res=hexlookup[(unsignedchar)c]; |
| 156 | + |
| 157 | +return (char)res; |
| 158 | +} |
| 159 | + |
| 160 | +staticunsigned |
| 161 | +hex_decode(constchar*src,unsignedlen,char*dst) |
| 162 | +{ |
| 163 | +constchar*s, |
| 164 | +*srcend; |
| 165 | +charv1, |
| 166 | +v2, |
| 167 | +*p; |
| 168 | + |
| 169 | +srcend=src+len; |
| 170 | +s=src; |
| 171 | +p=dst; |
| 172 | +while (s<srcend) |
| 173 | +{ |
| 174 | +if (*s==' '||*s=='\n'||*s=='\t'||*s=='\r') |
| 175 | +{ |
| 176 | +s++; |
| 177 | +continue; |
| 178 | +} |
| 179 | +v1=get_hex(*s++) <<4; |
| 180 | +if (s >=srcend) |
| 181 | +return-1; |
| 182 | + |
| 183 | +v2=get_hex(*s++); |
| 184 | +*p++=v1 |v2; |
| 185 | +} |
| 186 | + |
| 187 | +returnp-dst; |
| 188 | +} |
| 189 | + |
140 | 190 | unsigned
|
141 | 191 | ecpg_hex_encode(constchar*src,unsignedlen,char*dst)
|
142 | 192 | {
|
|