lib: unify conversions to/from hex

Curl_hexbyte - output a byte as a two-digit ASCII hex number

Curl_hexval - convert an ASCII hex digit to its binary value

... instead of duplicating similar code and hexdigit strings in numerous
places.

Closes #16888
This commit is contained in:
Daniel Stenberg 2025-03-31 23:12:09 +02:00
parent 1d84d683bb
commit 0c6e63a1be
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
8 changed files with 69 additions and 71 deletions

View file

@ -102,6 +102,13 @@ int Curl_str_cspn(const char **linep, struct Curl_str *out, const char *cspn);
void Curl_str_trimblanks(struct Curl_str *out);
void Curl_str_passblanks(const char **linep);
/* given a hexadecimal letter, return the binary value. '0' returns 0, 'a'
returns 10. THIS ONLY WORKS ON VALID HEXADECIMAL LETTER INPUT. Verify
before calling this!
*/
extern const unsigned char Curl_hexasciitable[];
#define Curl_hexval(x) (unsigned char)(Curl_hexasciitable[(x) - '0'] & 0x0f)
#define curlx_str_number(x,y,z) Curl_str_number(x,y,z)
#define curlx_str_octal(x,y,z) Curl_str_octal(x,y,z)
#define curlx_str_single(x,y) Curl_str_single(x,y)