Re: [PATCH v5 02/32] lib/string_helpers: Convert string_escape_mem() to printbuf
From: Andy Shevchenko
Date: Mon Aug 08 2022 - 08:03:46 EST
On Mon, Aug 8, 2022 at 4:41 AM Matthew Wilcox (Oracle)
<willy@xxxxxxxxxxxxx> wrote:
>
> From: Kent Overstreet <kent.overstreet@xxxxxxxxx>
>
> Like the upcoming vsprintf.c conversion, this converts string_escape_mem
> to prt_escaped_string(), which uses and outputs to a printbuf, and makes
> string_escape_mem() a smaller wrapper to support existing users.
>
> The new printbuf helpers greatly simplify the code.
...
> struct device;
> struct file;
> struct task_struct;
> +struct printbuf;
Keep it ordered?
...
> @@ -71,6 +74,7 @@ static inline int string_escape_mem_any_np(const char *src, size_t isz,
> return string_escape_mem(src, isz, dst, osz, ESCAPE_ANY_NP, only);
> }
>
> +
> static inline int string_escape_str(const char *src, char *dst, size_t sz,
> unsigned int flags, const char *only)
> {
Stray change.
...
> if (!(is_append || in_dict) && is_dict &&
> - escape_passthrough(c, &p, end))
> + escape_passthrough(out, c))
That (a bit strange) indentation is on purpose. Can we keep it?
> continue;
...
Not sure if the below was in the original text, but maybe it makes
sense to amend.
> + * Description:
> + * The process of escaping byte buffer includes several parts. They are applied
a byte in the buffer (?)
> + * in the following sequence.
> + *
> + * 1. The character is not matched to the one from @only string and thus
> + * must go as-is to the output.
> + * 2. The character is matched to the printable and ASCII classes, if asked,
> + * and in case of match it passes through to the output.
> + * 3. The character is matched to the printable or ASCII class, if asked,
> + * and in case of match it passes through to the output.
> + * 4. The character is checked if it falls into the class given by @flags.
> + * %ESCAPE_OCTAL and %ESCAPE_HEX are going last since they cover any
> + * character. Note that they actually can't go together, otherwise
> + * %ESCAPE_HEX will be ignored.
> + *
> + * Caller must provide valid source and destination pointers. Be aware that
> + * destination buffer will not be NULL-terminated, thus caller have to append
the caller has
> + * it if needs. The supported flags are::
if needed.
--
With Best Regards,
Andy Shevchenko