summaryrefslogtreecommitdiff
path: root/utils/ascii.h
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2017-03-27 15:35:59 +0100
committerMichael Drake <michael.drake@codethink.co.uk>2017-03-27 15:35:59 +0100
commitb14aa97a2a25cc0bcd258216aef7c70f9d354f1e (patch)
tree68a732d6266a99df65e0b9ee1473172174af0623 /utils/ascii.h
parent8caae83d356c80536ac58a84801c861f0e6f0745 (diff)
downloadnetsurf-b14aa97a2a25cc0bcd258216aef7c70f9d354f1e.tar.gz
netsurf-b14aa97a2a25cc0bcd258216aef7c70f9d354f1e.tar.bz2
ASCII: Add hex char to value conversion function.
Diffstat (limited to 'utils/ascii.h')
-rw-r--r--utils/ascii.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/utils/ascii.h b/utils/ascii.h
index 6f7bf6d9a..e5f9949ff 100644
--- a/utils/ascii.h
+++ b/utils/ascii.h
@@ -168,6 +168,26 @@ static inline bool ascii_is_hex(char c)
}
/**
+ * Convert a hexadecimal character to its value.
+ *
+ * \param[in] c Character to convert.
+ * \return value of character (0-15), or -256 if not a hexadecimal character.
+ */
+static inline int ascii_hex_to_value(char c)
+{
+ if (ascii_is_digit(c)) {
+ return c - '0';
+ } else if (ascii_is_af_lower(c)) {
+ return c - 'a' + 10;
+ } else if (ascii_is_af_upper(c)) {
+ return c - 'A' + 10;
+ }
+
+ /* Invalid hex */
+ return -256;
+}
+
+/**
* Convert an upper case character to lower case.
*
* If the given character is not upper case alphabetical, it is returned