From 8eb024d589c63ad941766acedfd7f4228117e20c Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 27 Oct 2013 20:17:29 +0200 Subject: [PATCH] scanner-utils: add helper for hex string escape Like the already existing oct. Signed-off-by: Ran Benita --- src/scanner-utils.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 -- 2.7.4