util: add support for forcing printing string as hex-escaped
This could be useful in cases when some binary data should not be interpreted as an ASCII string, but rather as an array of byte values. * defs.h (QUOTE_FORCE_HEX): New macro constant. * util.c (quote_string): Enable use_hex when QUOTE_FORCE_HEX is set in user_style parameter.
This commit is contained in:
parent
a8f0442fd7
commit
34a920baad
1
defs.h
1
defs.h
@ -505,6 +505,7 @@ extern int next_set_bit(const void *bit_array, unsigned cur_bit, unsigned size_b
|
||||
#define QUOTE_0_TERMINATED 0x01
|
||||
#define QUOTE_OMIT_LEADING_TRAILING_QUOTES 0x02
|
||||
#define QUOTE_OMIT_TRAILING_0 0x08
|
||||
#define QUOTE_FORCE_HEX 0x10
|
||||
|
||||
extern int string_quote(const char *, char *, unsigned int, unsigned int);
|
||||
extern int print_quoted_string(const char *, unsigned int, unsigned int);
|
||||
|
4
util.c
4
util.c
@ -654,9 +654,9 @@ string_quote(const char *instr, char *outstr, const unsigned int size,
|
||||
eol = 0x100; /* this can never match a char */
|
||||
|
||||
usehex = 0;
|
||||
if (xflag > 1)
|
||||
if ((xflag > 1) || (style & QUOTE_FORCE_HEX)) {
|
||||
usehex = 1;
|
||||
else if (xflag) {
|
||||
} else if (xflag) {
|
||||
/* Check for presence of symbol which require
|
||||
to hex-quote the whole string. */
|
||||
for (i = 0; i < size; ++i) {
|
||||
|
Loading…
Reference in New Issue
Block a user