Teach uc_hex_decode to skip spaces

This commit is contained in:
Nils O. Selåsdal
2013-12-06 23:10:32 +01:00
parent 42612803a1
commit 784dc1cecb
3 changed files with 64 additions and 5 deletions
+17 -1
View File
@@ -1,4 +1,5 @@
#include <stdint.h>
#include <ctype.h>
#include <stddef.h>
#include <string.h>
#include "ucore/string.h"
@@ -79,14 +80,29 @@ uc_hex_decode(const char *in, size_t maxlen,uint8_t *out)
{
size_t i, t;
for (t = 0,i = 0; i + 1 < maxlen && in[i] && in[i + 1]; i+=2 , ++t) {
for (t = 0,i = 0; i + 1 < maxlen ;) {
int hn, ln;
if (!(in[i] && in[i + 1])) {
break;
}
if (in[i] == ' ' ||
in[i] == '\t' ||
in[i] == '\r' ||
in[i] == '\n') {
i++;
continue;
}
hn = char_to_bin(in[i]);
ln = char_to_bin(in[i + 1]);
if (hn == -1 || ln == -1)
return NULL;
out[t] = (hn << 4 ) | ln;
i += 2;
t++;
}
return &out[t];