mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-16 05:34:00 -04:00
uri: move hex2nibble() to util.h
This commit is contained in:
parent
b8fc56ecb4
commit
1a91cbecc7
2 changed files with 24 additions and 23 deletions
23
uri.c
23
uri.c
|
|
@ -9,30 +9,9 @@
|
||||||
#define LOG_ENABLE_DBG 0
|
#define LOG_ENABLE_DBG 0
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "util.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
enum {
|
|
||||||
HEX_DIGIT_INVALID = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
static uint8_t
|
|
||||||
hex2nibble(char c)
|
|
||||||
{
|
|
||||||
switch (c) {
|
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
|
||||||
return c - '0';
|
|
||||||
|
|
||||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
|
||||||
return c - 'a' + 10;
|
|
||||||
|
|
||||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
|
||||||
return c - 'A' + 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
return HEX_DIGIT_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
uri_parse(const char *uri, size_t len,
|
uri_parse(const char *uri, size_t len,
|
||||||
char **scheme, char **user, char **password, char **host,
|
char **scheme, char **user, char **password, char **host,
|
||||||
|
|
|
||||||
22
util.h
22
util.h
|
|
@ -35,3 +35,25 @@ sdbm_hash(const char *s)
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum {
|
||||||
|
HEX_DIGIT_INVALID = 16
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline uint8_t
|
||||||
|
hex2nibble(char c)
|
||||||
|
{
|
||||||
|
switch (c) {
|
||||||
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
|
return c - '0';
|
||||||
|
|
||||||
|
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||||
|
return c - 'a' + 10;
|
||||||
|
|
||||||
|
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||||
|
return c - 'A' + 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HEX_DIGIT_INVALID;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue