/* quotearg.c - quote arguments for output
- Copyright (C) 1998-2002, 2004-2012 Free Software Foundation, Inc.
+ Copyright (C) 1998-2002, 2004-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <config.h>
#include "quotearg.h"
+#include "quote.h"
#include "xalloc.h"
#include "c-strcaseeq.h"
static struct quoting_options /* NOT PURE!! */
quoting_options_from_style (enum quoting_style style)
{
- struct quoting_options o = { 0 };
+ struct quoting_options o = { 0, 0, { 0 }, NULL, NULL };
if (style == custom_quoting_style)
abort ();
o.style = style;
if (STRCASEEQ (locale_code, "GB18030", 'G','B','1','8','0','3','0',0,0))
return msgid[0] == '`' ? "\xa1\ae": "\xa1\xaf";
- if (s == clocale_quoting_style)
- return "\"";
-
- return translation;
+ return (s == clocale_quoting_style ? "\"" : "'");
}
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
use Unicode U+2018 (LEFT SINGLE QUOTATION MARK) and
Unicode U+2019 (RIGHT SINGLE QUOTATION MARK). If the
current locale is not Unicode, locale_quoting_style
- will quote `like this', and clocale_quoting_style will
+ will quote 'like this', and clocale_quoting_style will
quote "like this". You should always include translations
for "`" and "'" even if U+2018 and U+2019 are appropriate
for your locale.
if (backslash_escapes
&& quote_string_len
- && i + quote_string_len <= argsize
+ && (i + quote_string_len
+ <= (argsize == SIZE_MAX && 1 < quote_string_len
+ /* Use strlen only if we must: when argsize is SIZE_MAX,
+ and when the quote string is more than 1 byte long.
+ If we do call strlen, save the result. */
+ ? (argsize = strlen (arg)) : argsize))
&& memcmp (arg + i, quote_string, quote_string_len) == 0)
{
if (elide_outer_quotes)
return quotearg_n_custom_mem (0, left_quote, right_quote, arg,
argsize);
}
+
+
+/* The quoting option used by the functions of quote.h. */
+struct quoting_options quote_quoting_options =
+ {
+ locale_quoting_style,
+ 0,
+ { 0 },
+ NULL, NULL
+ };
+
+char const *
+quote_n_mem (int n, char const *arg, size_t argsize)
+{
+ return quotearg_n_options (n, arg, argsize, "e_quoting_options);
+}
+
+char const *
+quote_mem (char const *arg, size_t argsize)
+{
+ return quote_n_mem (0, arg, argsize);
+}
+
+char const *
+quote_n (int n, char const *arg)
+{
+ return quote_n_mem (n, arg, SIZE_MAX);
+}
+
+char const *
+quote (char const *arg)
+{
+ return quote_n (0, arg);
+}