* lib/quotearg.c (quotearg_buffer_restyled): Don't escape \ when
eliding outer quotes.
* lib/quotearg.h: Document this.
* tests/test-quotearg.c (result_strings, inputs, results_g)
(flag_results, locale_results): Test it by adding a new string to
each test group.
(compare_strings): Test new string.
Signed-off-by: Eric Blake <ebb9@byu.net>
+2008-02-16 Eric Blake <ebb9@byu.net>
+
+ Avoid doubling \ in common case of "c-maybe" quoting style.
+ * lib/quotearg.c (quotearg_buffer_restyled): Don't escape \ when
+ eliding outer quotes.
+ * lib/quotearg.h: Document this.
+ * tests/test-quotearg.c (result_strings, inputs, results_g)
+ (flag_results, locale_results): Test it by adding a new string to
+ each test group.
+ (compare_strings): Test new string.
+
2008-02-13 Eric Blake <ebb9@byu.net>
Avoid trigraph quoting in default output.
2008-02-13 Eric Blake <ebb9@byu.net>
Avoid trigraph quoting in default output.
case '\r': esc = 'r'; goto c_and_shell_escape;
case '\t': esc = 't'; goto c_and_shell_escape;
case '\v': esc = 'v'; goto c_escape;
case '\r': esc = 'r'; goto c_and_shell_escape;
case '\t': esc = 't'; goto c_and_shell_escape;
case '\v': esc = 'v'; goto c_escape;
- case '\\': esc = c; goto c_and_shell_escape;
+ case '\\': esc = c;
+ /* No need to escape the escape if we are trying to elide
+ outer quotes and nothing else is problematic. */
+ if (backslash_escapes && elide_outer_quotes && quote_string_len)
+ goto store_c;
c_and_shell_escape:
if (quoting_style == shell_always_quoting_style
c_and_shell_escape:
if (quoting_style == shell_always_quoting_style
QA_ELIDE_NULL_BYTES = 0x01,
/* Omit the surrounding quote characters if no escaped characters
QA_ELIDE_NULL_BYTES = 0x01,
/* Omit the surrounding quote characters if no escaped characters
+ are encountered. Note that if no other character needs
+ escaping, then neither does the escape character. */
QA_ELIDE_OUTER_QUOTES = 0x02,
/* In the c_quoting_style and c_maybe_quoting_style, split ANSI
QA_ELIDE_OUTER_QUOTES = 0x02,
/* In the c_quoting_style and c_maybe_quoting_style, split ANSI
char const *str3; /* Translation of "simple". */
char const *str4; /* Translation of " \t\n'\"\033?""?/\\". */
char const *str5; /* Translation of "a:b". */
char const *str3; /* Translation of "simple". */
char const *str4; /* Translation of " \t\n'\"\033?""?/\\". */
char const *str5; /* Translation of "a:b". */
+ char const *str6; /* Translation of "a\\b". */
};
struct result_groups {
};
struct result_groups {
};
static struct result_strings inputs = {
};
static struct result_strings inputs = {
- "", "\0001\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b"
+ "", "\0001\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b"
};
static struct result_groups results_g[] = {
/* literal_quoting_style */
};
static struct result_groups results_g[] = {
/* literal_quoting_style */
- { { "", "\0""1\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b" },
- { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b" },
- { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b" } },
+ { { "", "\0""1\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" },
+ { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" },
+ { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" } },
/* shell_quoting_style */
/* shell_quoting_style */
- { { "''", "\0""1\0", 3, "simple", "' \t\n'\\''\"\033?""?/\\'", "a:b" },
- { "''", "1", 1, "simple", "' \t\n'\\''\"\033?""?/\\'", "a:b" },
- { "''", "1", 1, "simple", "' \t\n'\\''\"\033?""?/\\'", "'a:b'" } },
+ { { "''", "\0""1\0", 3, "simple", "' \t\n'\\''\"\033?""?/\\'", "a:b",
+ "'a\\b'" },
+ { "''", "1", 1, "simple", "' \t\n'\\''\"\033?""?/\\'", "a:b",
+ "'a\\b'" },
+ { "''", "1", 1, "simple", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
+ "'a\\b'" } },
/* shell_always_quoting_style */
/* shell_always_quoting_style */
- { { "''", "'\0""1\0'", 5, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'" },
- { "''", "'1'", 3, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'" },
- { "''", "'1'", 3, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'" } },
+ { { "''", "'\0""1\0'", 5, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
+ "'a\\b'" },
+ { "''", "'1'", 3, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
+ "'a\\b'" },
+ { "''", "'1'", 3, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
+ "'a\\b'" } },
/* c_quoting_style */
{ { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
/* c_quoting_style */
{ { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
- "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"" },
+ "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" },
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
- "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"" },
+ "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" },
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
- "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"" } },
+ "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"" } },
/* c_maybe_quoting_style */
{ { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
/* c_maybe_quoting_style */
{ { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
/* escape_quoting_style */
/* escape_quoting_style */
- { { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a:b" },
- { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a:b" },
- { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a\\:b" } },
+ { { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a:b",
+ "a\\\\b" },
+ { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a:b",
+ "a\\\\b" },
+ { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a\\:b",
+ "a\\\\b" } },
/* locale_quoting_style */
{ { "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'",
/* locale_quoting_style */
{ { "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'",
{ "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'",
{ "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'",
{ "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'",
{ "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'",
+ "`a\\:b'", "`a\\\\b'" } },
/* clocale_quoting_style */
{ { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
/* clocale_quoting_style */
{ { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
- "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"" },
+ "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" },
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
- "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"" },
+ "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" },
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
- "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"" } }
+ "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"" } }
};
static struct result_groups flag_results[] = {
/* literal_quoting_style and QA_ELIDE_NULL_BYTES */
};
static struct result_groups flag_results[] = {
/* literal_quoting_style and QA_ELIDE_NULL_BYTES */
- { { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b" },
- { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b" },
- { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b" } },
+ { { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" },
+ { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" },
+ { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" } },
/* c_quoting_style and QA_ELIDE_OUTER_QUOTES */
{ { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
/* c_quoting_style and QA_ELIDE_OUTER_QUOTES */
{ { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
/* c_quoting_style and QA_SPLIT_TRIGRAPHS */
{ { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
/* c_quoting_style and QA_SPLIT_TRIGRAPHS */
{ { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
- "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"" },
+ "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" },
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
- "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"" },
+ "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" },
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
- "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a\\:b\"" } }
+ "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"" } }
};
#if ENABLE_NLS
static struct result_groups locale_results[] = {
/* locale_quoting_style */
{ { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
};
#if ENABLE_NLS
static struct result_groups locale_results[] = {
/* locale_quoting_style */
{ { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
- LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ },
+ LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ },
{ LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
{ LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
- LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ },
+ LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ },
{ LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
{ LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
- LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ } },
+ LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ } },
/* clocale_quoting_style */
{ { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
/* clocale_quoting_style */
{ { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
- LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ },
+ LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ },
{ LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
{ LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
- LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ },
+ LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ },
{ LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
{ LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
- LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ } }
+ LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ } }
};
#endif /* ENABLE_NLS */
};
#endif /* ENABLE_NLS */
len = SIZE_MAX;
p = func (inputs.str5, &len);
compare (results->str5, strlen (results->str5), p, len);
len = SIZE_MAX;
p = func (inputs.str5, &len);
compare (results->str5, strlen (results->str5), p, len);
+
+ len = strlen (inputs.str6);
+ p = func (inputs.str6, &len);
+ compare (results->str6, strlen (results->str6), p, len);