diff options
author | Mark Brown <broonie@kernel.org> | 2015-10-12 13:09:27 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-10-12 13:09:27 -0400 |
commit | 79828b4fa835f73cdaf4bffa48696abdcbea9d02 (patch) | |
tree | 5e0fa7156acb75ba603022bc807df8f2fedb97a8 /lib/string_helpers.c | |
parent | 721b51fcf91898299d96f4b72cb9434cda29dce6 (diff) | |
parent | 8c1a9d6323abf0fb1e5dad96cf3f1c783505ea5a (diff) |
Merge remote-tracking branch 'asoc/fix/rt5645' into asoc-fix-rt5645
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r-- | lib/string_helpers.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index c98ae818eb4e..54036ce2e2dd 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c | |||
@@ -410,7 +410,7 @@ static bool escape_hex(unsigned char c, char **dst, char *end) | |||
410 | * @dst: destination buffer (escaped) | 410 | * @dst: destination buffer (escaped) |
411 | * @osz: destination buffer size | 411 | * @osz: destination buffer size |
412 | * @flags: combination of the flags (bitwise OR): | 412 | * @flags: combination of the flags (bitwise OR): |
413 | * %ESCAPE_SPACE: | 413 | * %ESCAPE_SPACE: (special white space, not space itself) |
414 | * '\f' - form feed | 414 | * '\f' - form feed |
415 | * '\n' - new line | 415 | * '\n' - new line |
416 | * '\r' - carriage return | 416 | * '\r' - carriage return |
@@ -432,16 +432,18 @@ static bool escape_hex(unsigned char c, char **dst, char *end) | |||
432 | * all previous together | 432 | * all previous together |
433 | * %ESCAPE_HEX: | 433 | * %ESCAPE_HEX: |
434 | * '\xHH' - byte with hexadecimal value HH (2 digits) | 434 | * '\xHH' - byte with hexadecimal value HH (2 digits) |
435 | * @esc: NULL-terminated string of characters any of which, if found in | 435 | * @only: NULL-terminated string containing characters used to limit |
436 | * the source, has to be escaped | 436 | * the selected escape class. If characters are included in @only |
437 | * that would not normally be escaped by the classes selected | ||
438 | * in @flags, they will be copied to @dst unescaped. | ||
437 | * | 439 | * |
438 | * Description: | 440 | * Description: |
439 | * The process of escaping byte buffer includes several parts. They are applied | 441 | * The process of escaping byte buffer includes several parts. They are applied |
440 | * in the following sequence. | 442 | * in the following sequence. |
441 | * 1. The character is matched to the printable class, if asked, and in | 443 | * 1. The character is matched to the printable class, if asked, and in |
442 | * case of match it passes through to the output. | 444 | * case of match it passes through to the output. |
443 | * 2. The character is not matched to the one from @esc string and thus | 445 | * 2. The character is not matched to the one from @only string and thus |
444 | * must go as is to the output. | 446 | * must go as-is to the output. |
445 | * 3. The character is checked if it falls into the class given by @flags. | 447 | * 3. The character is checked if it falls into the class given by @flags. |
446 | * %ESCAPE_OCTAL and %ESCAPE_HEX are going last since they cover any | 448 | * %ESCAPE_OCTAL and %ESCAPE_HEX are going last since they cover any |
447 | * character. Note that they actually can't go together, otherwise | 449 | * character. Note that they actually can't go together, otherwise |
@@ -458,11 +460,11 @@ static bool escape_hex(unsigned char c, char **dst, char *end) | |||
458 | * dst for a '\0' terminator if and only if ret < osz. | 460 | * dst for a '\0' terminator if and only if ret < osz. |
459 | */ | 461 | */ |
460 | int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, | 462 | int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, |
461 | unsigned int flags, const char *esc) | 463 | unsigned int flags, const char *only) |
462 | { | 464 | { |
463 | char *p = dst; | 465 | char *p = dst; |
464 | char *end = p + osz; | 466 | char *end = p + osz; |
465 | bool is_dict = esc && *esc; | 467 | bool is_dict = only && *only; |
466 | 468 | ||
467 | while (isz--) { | 469 | while (isz--) { |
468 | unsigned char c = *src++; | 470 | unsigned char c = *src++; |
@@ -471,7 +473,7 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, | |||
471 | * Apply rules in the following sequence: | 473 | * Apply rules in the following sequence: |
472 | * - the character is printable, when @flags has | 474 | * - the character is printable, when @flags has |
473 | * %ESCAPE_NP bit set | 475 | * %ESCAPE_NP bit set |
474 | * - the @esc string is supplied and does not contain a | 476 | * - the @only string is supplied and does not contain a |
475 | * character under question | 477 | * character under question |
476 | * - the character doesn't fall into a class of symbols | 478 | * - the character doesn't fall into a class of symbols |
477 | * defined by given @flags | 479 | * defined by given @flags |
@@ -479,7 +481,7 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, | |||
479 | * output buffer. | 481 | * output buffer. |
480 | */ | 482 | */ |
481 | if ((flags & ESCAPE_NP && isprint(c)) || | 483 | if ((flags & ESCAPE_NP && isprint(c)) || |
482 | (is_dict && !strchr(esc, c))) { | 484 | (is_dict && !strchr(only, c))) { |
483 | /* do nothing */ | 485 | /* do nothing */ |
484 | } else { | 486 | } else { |
485 | if (flags & ESCAPE_SPACE && escape_space(c, &p, end)) | 487 | if (flags & ESCAPE_SPACE && escape_space(c, &p, end)) |