mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Consolidate some ASCII tables in isc/ascii
and isc/hex
There were a number of places that had copies of various ASCII tables (case conversion, hex and decimal conversion) that are intended to be faster than the ctype.h macros, or avoid locale pollution. Move them into libisc, and wrap the lookup tables with macros that avoid the ctype.h gotchas.
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
@@ -22,6 +21,23 @@
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#define D ('0' - 0x0) /* ascii '0' to hex */
|
||||
#define U ('A' - 0xA) /* ascii 'A' to hex */
|
||||
#define L ('a' - 0xa) /* ascii 'a' to hex */
|
||||
|
||||
const uint8_t isc__hex_char[256] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, D, D, D, D, D, D, D, D, D, D, 0, 0, 0, 0, 0, 0, 0, U,
|
||||
U, U, U, U, U, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, L, L, L, L, L, L, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
#undef D
|
||||
#undef U
|
||||
#undef L
|
||||
|
||||
#define RETERR(x) \
|
||||
do { \
|
||||
isc_result_t _r = (x); \
|
||||
@@ -86,12 +102,13 @@ hex_decode_init(hex_decode_ctx_t *ctx, int length, isc_buffer_t *target) {
|
||||
|
||||
static isc_result_t
|
||||
hex_decode_char(hex_decode_ctx_t *ctx, int c) {
|
||||
const char *s;
|
||||
uint8_t hexval;
|
||||
|
||||
if ((s = strchr(hex, toupper(c))) == NULL) {
|
||||
hexval = isc_hex_char(c);
|
||||
if (hexval == 0) {
|
||||
return (ISC_R_BADHEX);
|
||||
}
|
||||
ctx->val[ctx->digits++] = (int)(s - hex);
|
||||
ctx->val[ctx->digits++] = c - hexval;
|
||||
if (ctx->digits == 2) {
|
||||
unsigned char num;
|
||||
|
||||
|
Reference in New Issue
Block a user