summaryrefslogtreecommitdiffstats
path: root/lib/string_helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r--lib/string_helpers.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 3a90a9e2b94a..963050c0283e 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -231,35 +231,36 @@ static bool unescape_special(char **src, char **dst)
231 * @src: source buffer (escaped) 231 * @src: source buffer (escaped)
232 * @dst: destination buffer (unescaped) 232 * @dst: destination buffer (unescaped)
233 * @size: size of the destination buffer (0 to unlimit) 233 * @size: size of the destination buffer (0 to unlimit)
234 * @flags: combination of the flags (bitwise OR): 234 * @flags: combination of the flags.
235 * %UNESCAPE_SPACE: 235 *
236 * Description:
237 * The function unquotes characters in the given string.
238 *
239 * Because the size of the output will be the same as or less than the size of
240 * the input, the transformation may be performed in place.
241 *
242 * Caller must provide valid source and destination pointers. Be aware that
243 * destination buffer will always be NULL-terminated. Source string must be
244 * NULL-terminated as well. The supported flags are::
245 *
246 * UNESCAPE_SPACE:
236 * '\f' - form feed 247 * '\f' - form feed
237 * '\n' - new line 248 * '\n' - new line
238 * '\r' - carriage return 249 * '\r' - carriage return
239 * '\t' - horizontal tab 250 * '\t' - horizontal tab
240 * '\v' - vertical tab 251 * '\v' - vertical tab
241 * %UNESCAPE_OCTAL: 252 * UNESCAPE_OCTAL:
242 * '\NNN' - byte with octal value NNN (1 to 3 digits) 253 * '\NNN' - byte with octal value NNN (1 to 3 digits)
243 * %UNESCAPE_HEX: 254 * UNESCAPE_HEX:
244 * '\xHH' - byte with hexadecimal value HH (1 to 2 digits) 255 * '\xHH' - byte with hexadecimal value HH (1 to 2 digits)
245 * %UNESCAPE_SPECIAL: 256 * UNESCAPE_SPECIAL:
246 * '\"' - double quote 257 * '\"' - double quote
247 * '\\' - backslash 258 * '\\' - backslash
248 * '\a' - alert (BEL) 259 * '\a' - alert (BEL)
249 * '\e' - escape 260 * '\e' - escape
250 * %UNESCAPE_ANY: 261 * UNESCAPE_ANY:
251 * all previous together 262 * all previous together
252 * 263 *
253 * Description:
254 * The function unquotes characters in the given string.
255 *
256 * Because the size of the output will be the same as or less than the size of
257 * the input, the transformation may be performed in place.
258 *
259 * Caller must provide valid source and destination pointers. Be aware that
260 * destination buffer will always be NULL-terminated. Source string must be
261 * NULL-terminated as well.
262 *
263 * Return: 264 * Return:
264 * The amount of the characters processed to the destination buffer excluding 265 * The amount of the characters processed to the destination buffer excluding
265 * trailing '\0' is returned. 266 * trailing '\0' is returned.
@@ -441,7 +442,29 @@ static bool escape_hex(unsigned char c, char **dst, char *end)
441 * @isz: source buffer size 442 * @isz: source buffer size
442 * @dst: destination buffer (escaped) 443 * @dst: destination buffer (escaped)
443 * @osz: destination buffer size 444 * @osz: destination buffer size
444 * @flags: combination of the flags (bitwise OR): 445 * @flags: combination of the flags
446 * @only: NULL-terminated string containing characters used to limit
447 * the selected escape class. If characters are included in @only
448 * that would not normally be escaped by the classes selected
449 * in @flags, they will be copied to @dst unescaped.
450 *
451 * Description:
452 * The process of escaping byte buffer includes several parts. They are applied
453 * in the following sequence.
454 *
455 * 1. The character is matched to the printable class, if asked, and in
456 * case of match it passes through to the output.
457 * 2. The character is not matched to the one from @only string and thus
458 * must go as-is to the output.
459 * 3. The character is checked if it falls into the class given by @flags.
460 * %ESCAPE_OCTAL and %ESCAPE_HEX are going last since they cover any
461 * character. Note that they actually can't go together, otherwise
462 * %ESCAPE_HEX will be ignored.
463 *
464 * Caller must provide valid source and destination pointers. Be aware that
465 * destination buffer will not be NULL-terminated, thus caller have to append
466 * it if needs. The supported flags are::
467 *
445 * %ESCAPE_SPACE: (special white space, not space itself) 468 * %ESCAPE_SPACE: (special white space, not space itself)
446 * '\f' - form feed 469 * '\f' - form feed
447 * '\n' - new line 470 * '\n' - new line
@@ -464,26 +487,6 @@ static bool escape_hex(unsigned char c, char **dst, char *end)
464 * all previous together 487 * all previous together
465 * %ESCAPE_HEX: 488 * %ESCAPE_HEX:
466 * '\xHH' - byte with hexadecimal value HH (2 digits) 489 * '\xHH' - byte with hexadecimal value HH (2 digits)
467 * @only: NULL-terminated string containing characters used to limit
468 * the selected escape class. If characters are included in @only
469 * that would not normally be escaped by the classes selected
470 * in @flags, they will be copied to @dst unescaped.
471 *
472 * Description:
473 * The process of escaping byte buffer includes several parts. They are applied
474 * in the following sequence.
475 * 1. The character is matched to the printable class, if asked, and in
476 * case of match it passes through to the output.
477 * 2. The character is not matched to the one from @only string and thus
478 * must go as-is to the output.
479 * 3. The character is checked if it falls into the class given by @flags.
480 * %ESCAPE_OCTAL and %ESCAPE_HEX are going last since they cover any
481 * character. Note that they actually can't go together, otherwise
482 * %ESCAPE_HEX will be ignored.
483 *
484 * Caller must provide valid source and destination pointers. Be aware that
485 * destination buffer will not be NULL-terminated, thus caller have to append
486 * it if needs.
487 * 490 *
488 * Return: 491 * Return:
489 * The total size of the escaped output that would be generated for 492 * The total size of the escaped output that would be generated for