blob: dfeb25972c35a3ae7f5f089cf9b0d031710153de [file] [log] [blame]
rsc78e51a82005-01-14 03:45:44 +00001.TH QUOTE 3
2.SH NAME
3quotestrdup, quoterunestrdup, unquotestrdup, unquoterunestrdup, quotestrfmt, quoterunestrfmt, quotefmtinstall, fmtdoquote \- quoted character strings
4.SH SYNOPSIS
5.B #include <utf.h>
6.br
7.B #include <fmt.h>
8.PP
9.B
10char *quotestrdup(char *s)
11.PP
12.B
13Rune *quoterunestrdup(Rune *s)
14.PP
15.B
16char *unquotestrdup(char *s)
17.PP
18.B
19Rune *unquoterunestrdup(Rune *s)
20.PP
21.B
22int quotestrfmt(Fmt*)
23.PP
24.B
25int quoterunestrfmt(Fmt*)
26.PP
27.B
28void quotefmtinstall(void)
29.PP
30.B
31int (*fmtdoquote)(int c)
32.PP
33.SH DESCRIPTION
34These routines manipulate character strings, either adding or removing
35quotes as necessary.
36In the quoted form, the strings are in the style of
37.IR rc (1) ,
38with single quotes surrounding the string.
39Embedded single quotes are indicated by a doubled single quote.
40For instance,
41.IP
42.EX
43Don't worry!
44.EE
45.PP
46when quoted becomes
47.IP
48.EX
49\&'Don''t worry!'
50.EE
51.PP
52The empty string is represented by two quotes,
53.BR '' .
54.PP
55The first four functions act as variants of
56.B strdup
57(see
58.IR strcat (3)).
59Each returns a
60freshly allocated copy of the string, created using
61.IR malloc (3).
62.I Quotestrdup
63returns a quoted copy of
64.IR s ,
65while
66.I unquotestrdup
67returns a copy of
68.IR s
69with the quotes evaluated.
70The
71.I rune
72versions of these functions do the same for
73.CW Rune
74strings (see
75.IR runestrcat (3)).
76.PP
77The string returned by
78.I quotestrdup
79or
80.I quoterunestrdup
81has the following properties:
82.TP
831.
84If the original string
85.IR s
86is empty, the returned string is
87.BR '' .
88.TP
892.
90If
91.I s
92contains no quotes, blanks, or control characters,
93the returned string is identical to
94.IR s .
95.TP
963.
97If
98.I s
99needs quotes to be added, the first character of the returned
100string will be a quote.
101For example,
102.B hello\ world
103becomes
104.B \&'hello\ world'
105not
106.BR hello'\ 'world .
107.PP
108The function pointer
109.I fmtdoquote
110is
111.B nil
112by default.
113If it is non-nil, characters are passed to that function to see if they should
114be quoted.
115This mechanism allows programs to specify that
116characters other than blanks, control characters, or quotes be quoted.
117Regardless of the return value of
118.IR *fmtdoquote ,
119blanks, control characters, and quotes are always quoted.
120.I Needsrcquote
121is provided as a
122.I fmtdoquote
123function that flags any character special to
124.IR rc (1).
125.PP
126.I Quotestrfmt
127and
128.I quoterunestrfmt
129are
130.IR print (3)
131formatting routines that produce quoted strings as output.
132They may be installed by hand, but
133.I quotefmtinstall
134installs them under the standard format characters
135.B q
136and
137.BR Q .
138(They are not installed automatically.)
139If the format string includes the alternate format character
140.BR # ,
141for example
142.BR %#q ,
143the printed string will always be quoted; otherwise quotes will only be provided if necessary
144to avoid ambiguity.
145.SH SOURCE
146.B http://swtch.com/plan9port/unix
147.SH "SEE ALSO
148.IR rc (1),
149.IR malloc (3),
150.IR print (3),
151.IR strcat (3)