Documentation about quote and quotearg modules.
[gnulib.git] / doc / quote.texi
1 @node Quoting
2 @section Quoting
3
4 @cindex Quoting
5 @findex quote
6 @findex quotearg
7
8 Gnulib provides @samp{quote} and @samp{quotearg} modules to help with
9 quoting text, such as file names, in messages to the user.  Here's an
10 example of using @samp{quote}:
11
12 @example
13 #include <quote.h>
14  ...
15   error (0, errno, _("cannot change owner of %s"), quote (fname));
16 @end example
17
18 This differs from
19
20 @example
21   error (0, errno, _("cannot change owner of `%s'"), fname);
22 @end example
23
24 @noindent in that @code{quote} escapes unusual characters in
25 @code{fname}, e.g., @samp{'} and control characters like @samp{\n}.
26
27 @findex quote_n
28 However, a caveat: @code{quote} reuses the storage that it returns.
29 Hence if you need more than one thing quoted at the same time, you
30 need to use @code{quote_n}.
31
32 @findex quotearg_alloc
33 Also, the quote module is not suited for multithreaded applications.
34 In that case, you have to use @code{quotearg_alloc}, defined in the
35 @samp{quotearg} module, which is decidedly less convenient.