QUOTE(3)
okay bestie, welcome to QUOTE(3), a Library Functions Manual page all about quoted character strings. it's giving string-glow-up energy, and yes, we're keeping every single detail π β¨
πΈ NAME πΈ
the squad is quotestrdup, quoterunestrdup, unquotestrdup, unquoterunestrdup, quotestrfmt, quoterunestrfmt, quotefmtinstall, doquote, and needsrcquote β all here for quoted character strings π
π οΈ SYNOPSIS π οΈ
include the headers like this, bestie:
#include <u.h>
#include <libc.h>
and here's the whole function lineup, exactly as written:
char *quotestrdup(char *s)
Rune *quoterunestrdup(Rune *s)
char *unquotestrdup(char *s)
Rune *unquoterunestrdup(Rune *s)
int quotestrfmt(Fmt*)
int quoterunestrfmt(Fmt*)
void quotefmtinstall(void)
int (*doquote)(int c)
int needsrcquote(int c)
π DESCRIPTION π
these routines manipulate character strings, either adding or removing quotes as necessary. in quoted form, strings are in the style of rc(1), with single quotes surrounding the string. embedded single quotes are indicated by a doubled single quote. for instance,
Don't worry!
when quoted becomes
'Don''t worry!'
and the empty string is represented by two quotes, '' π«Ά
the first four functions act as variants of strdup (see strcat(3)). each returns a freshly allocated copy of the string, created using malloc(3). quotestrdup returns a quoted copy of s, while unquotestrdup returns a copy of s with the quotes evaluated. the rune versions of these functions do the same for strings (see runestrcat(3)).
the string returned by quotestrdup or quoterunestrdup has these properties, no cap:
- if the original string
sis empty, the returned string is''. - if
scontains no quotes, blanks, or control characters, the returned string is identical tos. - if
sneeds quotes to be added, the first character of the returned string will be a quote. for example,hello worldbecomes'hello world'nothello' 'world.
the function pointer doquote is nil by default. if it is non-nil, characters are passed to that function to see if they should be quoted. this mechanism allows programs to specify that characters other than blanks, control characters, or quotes be quoted. regardless of the return value of *doquote, blanks, control characters, and quotes are always quoted. needsrcquote is provided as a doquote function that flags any character special to rc(1).
quotestrfmt and quoterunestrfmt are print(3) formatting routines that produce quoted strings as output. they may be installed by hand, but quotefmtinstall installs them under the standard format characters q and Q. (they are not installed automatically.) if the format string includes the alternate format character #, for example %#q, the printed string will always be quoted; otherwise quotes will only be provided if necessary to avoid ambiguity. in <libc.h> there are #pragma statements so the compiler can type-check uses of %q and %Q in print(3) format strings.
π SOURCE π
the source files are serving absolute file-path realness:
/src/lib9/quote.c/src/lib9/fmt/fmtquote.c
π SEE ALSO π
go read these, bestie:
π BUGS π
because it is provided by the format library, doquote is a preprocessor macro defined as fmtdoquote; see intro(3). lowkey a gotcha, but now you know π
π that's the page, bestie! this is QUOTE(3) from the Library Functions Manual; the source files are /src/lib9/quote.c and /src/lib9/fmt/fmtquote.c, and the page doesn't list a date β so no date to spill, periodt π«Άβ¨
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms