From 1a91cbecc7c3931f0b406fe9c4d5c98efc7d8863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 2 Jan 2022 18:28:10 +0100 Subject: [PATCH] uri: move hex2nibble() to util.h --- uri.c | 25 ++----------------------- util.h | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/uri.c b/uri.c index e747991d..39073bde 100644 --- a/uri.c +++ b/uri.c @@ -9,30 +9,9 @@ #define LOG_ENABLE_DBG 0 #include "log.h" #include "debug.h" +#include "util.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 uri_parse(const char *uri, size_t len, char **scheme, char **user, char **password, char **host, @@ -118,7 +97,7 @@ uri_parse(const char *uri, size_t len, LOG_DBG("user: \"%.*s\"", (int)user_len, start); } - + start = user_pw_end + 1; left = len - (start - uri); auth_left -= user_pw_len + 1; diff --git a/util.h b/util.h index aa9fc8ba..683dbd4a 100644 --- a/util.h +++ b/util.h @@ -35,3 +35,25 @@ sdbm_hash(const char *s) 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; +}