[MINOR] tools: add hex2i() function to convert hex char to int
diff --git a/include/common/standard.h b/include/common/standard.h
index 544a5c3..ce3c6b8 100644
--- a/include/common/standard.h
+++ b/include/common/standard.h
@@ -118,6 +118,12 @@
 extern int ishex(char s);
 
 /*
+ * Return integer equivalent of character <c> for a hex digit (0-9, a-f, A-F),
+ * otherwise -1.
+ */
+extern int hex2i(int c);
+
+/*
  * Checks <name> for invalid characters. Valid chars are [A-Za-z0-9_:.-]. If an
  * invalid character is found, a pointer to it is returned. If everything is
  * fine, NULL is returned.
diff --git a/src/standard.c b/src/standard.c
index 6a8724a..aab318b 100644
--- a/src/standard.c
+++ b/src/standard.c
@@ -159,6 +159,21 @@
 }
 
 /*
+ * Return integer equivalent of character <c> for a hex digit (0-9, a-f, A-F),
+ * otherwise -1. This compact form helps gcc produce efficient code.
+ */
+int hex2i(int c)
+{
+	if ((unsigned char)(c -= '0') > 9) {
+		if ((unsigned char)(c -= 'A' - '0') > 5 &&
+		    (unsigned char)(c -= 'a' - 'A') > 5)
+			c = -11;
+		c += 10;
+	}
+	return c;
+}
+
+/*
  * Checks <name> for invalid characters. Valid chars are [A-Za-z0-9_:.-]. If an
  * invalid character is found, a pointer to it is returned. If everything is
  * fine, NULL is returned.