Teach uc_hex_decode to skip spaces
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user