.TH STRING 2.SH NAMEstring: append, drop, in, prefix, quoted, splitl, splitr, splitstrl,splitstrr, take, tobig, toint, toreal, tolower, toupper, unquoted \- string operations.SH SYNOPSIS.EXinclude "string.m";str := load String String->PATH; append: fn(s: string, l: list of string): list of string;drop: fn(s, cl: string): string;in: fn(c: int, cl: string): int;prefix: fn(pre, s: string): int;splitl: fn(s, cl: string): (string, string);splitr: fn(s, cl: string): (string, string);splitstrl: fn(s, t: string): (string, string);splitstrr: fn(s, t: string): (string, string);take: fn(s, cl: string): string;tobig: fn(s: string, base: int): (big, string);toint: fn(s: string, base: int): (int, string);toreal: fn(s: string, base: int): (real, string);tolower: fn(s: string): string;toupper: fn(s: string): string;quoted: fn(args: list of string): string;unquoted: fn(s: string): list of string;.EE.SH DESCRIPTIONThe.I clargument to some of these functions is a character class in whicha.B -between any two characters indicates a range and a.B ^in the first position means.I not inthe class.Example of classes are.B \&"a-zA-Z"and.B\&"^acg-mr"\c\&..PP.B Appendappends string.I sto the end of string list.IR l ..PP.B Dropremoves the maximal prefix of string.I sthat is in class.IR cl ..PP.B Inreturns 1 ifcharacter.I cis in class.I cland 0 if it is not. .PP.B Prefixreturns 1 if string.I preis a prefix of string.I sand 0 if it is not..PP.B Splitlsplits string.I sjust before the first character in class.IR cl ..PP.B Splitrsplits string.I sjust after the last character in class.IR cl ..PP.B Splitstrlsplits string.I sjust before the leftmost segment of string.I sthat consists entirely of string.IR t ,and returns a tuple with the resulting pair of strings.If.I tdoes not occur in.IR s ,the result is.RI ( s , nil )..PP.B Splitstrrsplits string.I sjust after the rightmost segment of string.I sthat consists entirely of string.IR t ,and returns a tuple with the resulting pair of strings.If.I tdoes not occur in.IR s ,the result is.RI ( nil, s )..PP.B Takereturns the maximal prefix of string.I sthat is in class.IR cl ..PP.B Tointreturns as an integer the value represented by the string.IR s .The string is scanned up to the first character inconsistentwith.IR base .The first inconsistent character marks the beginning of thereturned string.Leading white-space characters are ignored.The.I basecan be any integer in the range 2 to 36, inclusive;or 0 in which case the base can be specified as partof the string, in Limbo style (e.g. 16rffff)..PP.B Tobighas the same specification as.B tointexcept that converts to 64-bit.BR big ..PP.B Torealis similar to.BR toint ,except that it expects a floating-point number after optional leading white space:an optional sign, then a string of digits containing a decimal point, then an optional.RB ` e 'or.RB ` E 'followed by an optionally signed decimal integer exponent.The string of digits can optionally be preceded by a base (radix) specifierof the form.IB B r ,as for integers.Any exponent is then interpreted as a power of that base.Alternatively, following any leading white space and an optional sign, either.B nanor.B infinitycan appear, in any case, and.B torealwill return the appropriate value for IEEE floating-point..PP.B Tolowerconverts all upper case letters in the string.I sto lower case letters..PP.B Toupperconverts all lower case letters in the string.I sto upper case letters..PP.B Quotedtakes a list of strings,.IR args ,and returns a single string with the value of each element of.I argsseparated from the next by a single space.When forming the string, the text of any element thatcontains white space or single quotes is first quoted bysurrounding it by single quotes.RB ( ' ... ' )within which each existing single quote is doubled.RB ( '' ),following the conventions of.IR sh (1)..PP.B Unquotedtakes a string.IR s ,quoted according to the conventions of.BR quoted ,and splits it into separate strings.It splits the string at each maximal sequence ofunquoted white space (blank, newline or tab),stripping single quotes except where paired,to form the corresponding list of strings,which it returns..SH SOURCE.B /appl/lib/string.b
.TH STRING 2
.SH NAME
string: append, drop, in, prefix, quoted, splitl, splitr, splitstrl,
splitstrr, take, tobig, toint, toreal, tolower, toupper, unquoted \- string operations
.SH SYNOPSIS
.EX
include "string.m";
str := load String String->PATH;
append: fn(s: string, l: list of string): list of string;
drop: fn(s, cl: string): string;
in: fn(c: int, cl: string): int;
prefix: fn(pre, s: string): int;
splitl: fn(s, cl: string): (string, string);
splitr: fn(s, cl: string): (string, string);
splitstrl: fn(s, t: string): (string, string);
splitstrr: fn(s, t: string): (string, string);
take: fn(s, cl: string): string;
tobig: fn(s: string, base: int): (big, string);
toint: fn(s: string, base: int): (int, string);
toreal: fn(s: string, base: int): (real, string);
tolower: fn(s: string): string;
toupper: fn(s: string): string;
quoted: fn(args: list of string): string;
unquoted: fn(s: string): list of string;
.EE
.SH DESCRIPTION
The
.I cl
argument to some of these functions is a character class in which
a
.B -
between any two characters indicates a range and a
.B ^
in the first position means
.I not in
the class.
Example of classes are
.B \&"a-zA-Z"
and
.B
\&"^acg-mr"\c
\&.
.PP
.B Append
appends string
.I s
to the end of string list
.IR l .
.PP
.B Drop
removes the maximal prefix of string
.I s
that is in class
.IR cl .
.PP
.B In
returns 1 if
character
.I c
is in class
.I cl
and 0 if it is not.
.PP
.B Prefix
returns 1 if string
.I pre
is a prefix of string
.I s
and 0 if it is not.
.PP
.B Splitl
splits string
.I s
just before the first character in class
.IR cl .
.PP
.B Splitr
splits string
.I s
just after the last character in class
.IR cl .
.PP
.B Splitstrl
splits string
.I s
just before the leftmost segment of string
.I s
that consists entirely of string
.IR t ,
and returns a tuple with the resulting pair of strings.
If
.I t
does not occur in
.IR s ,
the result is
.RI ( s , nil ).
.PP
.B Splitstrr
splits string
.I s
just after the rightmost segment of string
.I s
that consists entirely of string
.IR t ,
and returns a tuple with the resulting pair of strings.
If
.I t
does not occur in
.IR s ,
the result is
.RI ( nil, s ).
.PP
.B Take
returns the maximal prefix of string
.I s
that is in class
.IR cl .
.PP
.B Toint
returns as an integer the value represented by the string
.IR s .
The string is scanned up to the first character inconsistent
with
.IR base .
The first inconsistent character marks the beginning of the
returned string.
Leading white-space characters are ignored.
The
.I base
can be any integer in the range 2 to 36, inclusive;
or 0 in which case the base can be specified as part
of the string, in Limbo style (e.g. 16rffff).
.PP
.B Tobig
has the same specification as
.B toint
except that converts to 64-bit
.BR big .
.PP
.B Toreal
is similar to
.BR toint ,
except that it expects a floating-point number after optional leading white space:
an optional sign, then a string of digits containing a decimal point, then an optional
.RB ` e '
or
.RB ` E '
followed by an optionally signed decimal integer exponent.
The string of digits can optionally be preceded by a base (radix) specifier
of the form
.IB B r ,
as for integers.
Any exponent is then interpreted as a power of that base.
Alternatively, following any leading white space and an optional sign, either
.B nan
or
.B infinity
can appear, in any case, and
.B toreal
will return the appropriate value for IEEE floating-point.
.PP
.B Tolower
converts all upper case letters in the string
.I s
to lower case letters.
.PP
.B Toupper
converts all lower case letters in the string
.I s
to upper case letters.
.PP
.B Quoted
takes a list of strings,
.IR args ,
and returns a single string with the value of each element of
.I args
separated from the next by a single space.
When forming the string, the text of any element that
contains white space or single quotes is first quoted by
surrounding it by single quotes
.RB ( ' ... ' )
within which each existing single quote is doubled
.RB ( '' ),
following the conventions of
.IR sh (1).
.PP
.B Unquoted
takes a string
.IR s ,
quoted according to the conventions of
.BR quoted ,
and splits it into separate strings.
It splits the string at each maximal sequence of
unquoted white space (blank, newline or tab),
stripping single quotes except where paired,
to form the corresponding list of strings,
which it returns.
.SH SOURCE
.B /appl/lib/string.b