mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-08 10:06:22 -05:00
Merge branch 'hex2nibble'
This commit is contained in:
commit
b4d7a60864
1 changed files with 8 additions and 6 deletions
14
uri.c
14
uri.c
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
|
@ -12,8 +11,12 @@
|
|||
#include "log.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
enum {
|
||||
HEX_DIGIT_INVALID = 16
|
||||
};
|
||||
|
||||
static uint8_t
|
||||
nibble2hex(char c)
|
||||
hex2nibble(char c)
|
||||
{
|
||||
switch (c) {
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
|
|
@ -27,8 +30,7 @@ nibble2hex(char c)
|
|||
return c - 'A' + 10;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return 0;
|
||||
return HEX_DIGIT_INVALID;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
@ -199,8 +201,8 @@ uri_parse(const char *uri, size_t len,
|
|||
encoded_len -= prefix_len;
|
||||
decoded_len += prefix_len;
|
||||
|
||||
if (isxdigit(next[1]) && isxdigit(next[2])) {
|
||||
*p++ = nibble2hex(next[1]) << 4 | nibble2hex(next[2]);
|
||||
if (hex2nibble(next[1]) <= 15 && hex2nibble(next[2]) <= 15) {
|
||||
*p++ = hex2nibble(next[1]) << 4 | hex2nibble(next[2]);
|
||||
decoded_len++;
|
||||
encoded_len -= 3;
|
||||
encoded = next + 3;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue