aboutsummaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-01-14 12:49:25 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-01-14 12:49:25 +0000
commit2d3d8ca3d01627bf12ac651477b5c7db72ecbdeb (patch)
tree160ba09cd922c3e12288bb09770e8c06bd3f1325 /util.h
parenttest: config: tweak.grapheme-shaping can’t be set when grapheme-clustering has been disabled (diff)
parentdoc: foot.1: XTGETTCAP (diff)
Merge branch 'xtgettcap'
Closes #846
Diffstat (limited to 'util.h')
-rw-r--r--util.h22
1 files changed, 22 insertions, 0 deletions
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;
+}