From: David Bremner <bremner@debian.org> Initial use case is to recognize input tokens for batch tagging that need quoting. --- util/hex-escape.c | 7 +++++++ util/hex-escape.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/util/hex-escape.c b/util/hex-escape.c index b7e2e07..b601a33 100644 --- a/util/hex-escape.c +++ b/util/hex-escape.c @@ -24,6 +24,7 @@ #include <ctype.h> #include "error_util.h" #include "hex-escape.h" +#include "string-util.h" static const size_t default_buf_size = 1024; @@ -38,6 +39,12 @@ is_output (char c) return (strchr (output_charset, c) != NULL); } +size_t +hex_invariant (const char *str, size_t len) +{ + return strnspn (str, len, output_charset); +} + static int maybe_realloc (void *ctx, size_t needed, char **out, size_t *out_size) { diff --git a/util/hex-escape.h b/util/hex-escape.h index 5182042..e7d0b31 100644 --- a/util/hex-escape.h +++ b/util/hex-escape.h @@ -38,4 +38,12 @@ hex_decode (void *talloc_ctx, const char *in, char **out, */ hex_status_t hex_decode_inplace (char *s); + +/* + * Calculate the length of the initial segment of str that would not + * be changed by hex encoding. Consider at most `len' characters + * (bytes) before stopping. + */ +size_t +hex_invariant (const char *str, size_t len); #endif -- 1.7.10.4