167 lines · 3.0 KB · Text
RawDownload
.TH QUOTE 2.SH NAMEquotestrdup, quoterunestrdup, unquotestrdup, unquoterunestrdup, quotestrfmt, quoterunestrfmt, quotefmtinstall, doquote, needsrcquote \- quoted character strings.SH SYNOPSIS.B #include <u.h>.br.B #include <libc.h>.PP.Bchar *quotestrdup(char *s).PP.BRune *quoterunestrdup(Rune *s).PP.Bchar *unquotestrdup(char *s).PP.BRune *unquoterunestrdup(Rune *s).PP.Bint quotestrfmt(Fmt*).PP.Bint quoterunestrfmt(Fmt*).PP.Bvoid quotefmtinstall(void).PP.Bint (*doquote)(int c).PP.Bint needsrcquote(int c).PP.SH DESCRIPTIONThese routines manipulate character strings, either adding or removingquotes as necessary.In the quoted form, the strings are in the style of.IR rc (1) ,with single quotes surrounding the string.Embedded single quotes are indicated by a doubled single quote.For instance,.IP.EXDon't worry!.EE.PPwhen quoted becomes.IP.EX\&'Don''t worry!'.EE.PPThe empty string is represented by two quotes,.BR '' ..PPThe first four functions act as variants of.B strdup(see.IR strcat (2)).Each returns afreshly allocated copy of the string, created using.IR malloc (2)..I Quotestrdupreturns a quoted copy of.IR s ,while.I unquotestrdupreturns a copy of.IR swith the quotes evaluated.The.I runeversions of these functions do the same for.CW Runestrings (see.IR runestrcat (2))..PPThe string returned by.I quotestrdupor.I quoterunestrduphas the following properties:.TP1.If the original string.IR sis empty, the returned string is.BR '' ..TP2.If.I scontains no quotes, blanks, or control characters,the returned string is identical to.IR s ..TP3.If.I sneeds quotes to be added, the first character of the returnedstring will be a quote.For example,.B hello\ worldbecomes.B \&'hello\ world'not.BR hello'\ 'world ..PPThe function pointer.I doquoteis.B nilby default.If it is non-nil, characters are passed to that function to see if they shouldbe quoted.This mechanism allows programs to specify thatcharacters other than blanks, control characters, or quotes be quoted.Regardless of the return value of.IR *doquote ,blanks, control characters, and quotes are always quoted..I Needsrcquoteis provided as a.I doquotefunction that flags any character special to.IR rc (1)..PP.I Quotestrfmtand.I quoterunestrfmtare.IR print (2)formatting routines that produce quoted strings as output.They may be installed by hand, but.I quotefmtinstallinstalls them under the standard format characters.B qand.BR Q .(They are not installed automatically.)If the format string includes the alternate format character.BR # ,for example.BR %#q ,the printed string will always be quoted; otherwise quotes will only be provided if necessaryto avoid ambiguity.In.B <libc.h>there are.B #pragmastatements so the compiler can type-check uses of.B %qand.B %Qin.IR print (2)format strings..SH SOURCE.B /sys/src/libc/port/quote.c.br.B /sys/src/libc/fmt/fmtquote.c.SH "SEE ALSO.IR rc (1),.IR malloc (2),.IR print (2),.IR strcat (2)