summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2013-10-27 20:17:29 +0200
committerRan Benita <ran234@gmail.com>2014-10-02 22:21:06 +0300
commit8eb024d589c63ad941766acedfd7f4228117e20c (patch)
tree715cd1feeb5c049a870a801c6c0185db62a76e25
parentbc3b4c084a4b4858319ba4843fae99b6fb77994a (diff)
downloadxorg-lib-libxkbcommon-8eb024d589c63ad941766acedfd7f4228117e20c.tar.gz
scanner-utils: add helper for hex string escape
Like the already existing oct. Signed-off-by: Ran Benita <ran234@gmail.com>
-rw-r--r--src/scanner-utils.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/scanner-utils.h b/src/scanner-utils.h
index fc231ab..57c5ec5 100644
--- a/src/scanner-utils.h
+++ b/src/scanner-utils.h
@@ -156,4 +156,17 @@ oct(struct scanner *s, uint8_t *out)
return i > 0;
}
+static inline bool
+hex(struct scanner *s, uint8_t *out)
+{
+ int i;
+ for (i = 0, *out = 0; is_xdigit(peek(s)) && i < 2; i++) {
+ const char c = next(s);
+ const char offset = (c >= '0' && c <= '9' ? '0' :
+ c >= 'a' && c <= 'f' ? 'a' - 10 : 'A' - 10);
+ *out = *out * 16 + c - offset;
+ }
+ return i > 0;
+}
+
#endif