80 lines
3.0 KiB
TeX
80 lines
3.0 KiB
TeX
\section{Manipulating strings}
|
|
|
|
|
|
\begin{description}
|
|
\item[Used files:] stringhax.scm
|
|
\item[Name of the package:] strings
|
|
\end{description}
|
|
|
|
|
|
\subsection*{Overview}
|
|
|
|
This module provides several procedures to manipulate strings.
|
|
|
|
\begin{defundesc}{string-map} {procedure string} {string}
|
|
Does a map on each character of \semvar{string} and returns the
|
|
result, a newly allocated string. \semvar{procedure} takes a
|
|
character and should return a character.
|
|
\end{defundesc}
|
|
|
|
\defun{downcase-string} {string} {string}
|
|
\begin{defundescx}{upcase-string} {string} {string}
|
|
Do what you expect: convert \semvar{string} to downcase or upcase
|
|
using char-downcase or char-upcase, respectively. The result is a
|
|
newly allocated string.
|
|
\end{defundescx}
|
|
|
|
\defun{char-set-index} {string char-set \ovar{start}} {number}
|
|
\begin{defundescx}{char-set-rindex} {string char-set \ovar{start}} {number}
|
|
Returns the index of the first character that is in
|
|
\semvar{char\=set}. \ex{char\=set\=index} searches from left to
|
|
right, \ex{char\=set\=rindex} from right to left. \semvar{start} is
|
|
the index from where to start from and defaults to 0 in
|
|
\ex{char\=set\=index} and \ex{(string-length \semvar{string})} in
|
|
\ex{char\=set\=rindex}. If the search fails, \sharpf{} is returned.
|
|
\end{defundescx}
|
|
|
|
\begin{defundesc}{string-reduce} {default construct string} {string}
|
|
Does a ``fold-right'' on \semvar{string}. It applies
|
|
\semvar{construct} on every character of \semvar{string}.
|
|
\semvar{construct} is initially invoked with the last character of
|
|
string and \semvar{default}. In subsequent invocations, the last
|
|
argument is the return value from the previous invocation of
|
|
\semvar{construct} while the first argument is the character of
|
|
\semvar{string} leading the previous used character. So, the string
|
|
is traversed from right to left. The result of the application of
|
|
\semvar{string-reduce} is the result of the last application of
|
|
\semvar{construct}.
|
|
|
|
Example:
|
|
\begin{code}
|
|
(string-reduce
|
|
""
|
|
(lambda (char str)
|
|
(string-append str (string (char-downcase char))))
|
|
"DOWNCASE")\end{code}
|
|
|
|
results to ``downcase''.
|
|
\end{defundesc}
|
|
|
|
\defun{string-prefix?} {prefix string} {boolean}
|
|
\begin{defundescx}{string-suffix?} {suffix string} {boolean}
|
|
Return \sharpt{} if \semvar{prefix}/\semvar{suffix} is a real
|
|
\semvar{prefix}/\semvar{suffix} of \semvar{string}, otherwise return
|
|
\sharpf. Real prefix/suffix means that \semvar{string} may not be a
|
|
prefix/suffix of \semvar{prefix}/\semvar{suffix} (in other words:
|
|
\semvar{prefix} and \semvar{suffix} have to be real shorter than
|
|
\semvar{string} to be a real prefix or suffix.
|
|
\end{defundescx}
|
|
|
|
\begin{defundesc}{skip-whitespace} {string} {number}
|
|
Returns the index of the first character in \semvar{string} that is
|
|
not a whitespace (as defined in \ex{char-set:whitespace}). If there
|
|
isn't such a character, \sharpf{} is returned.
|
|
\end{defundesc}
|
|
|
|
\begin{defundesc}{trim-spaces} {string} {string}
|
|
Returns a newly allocated string being \semvar{string} without
|
|
leading or trailing spaces (not whitespaces!).
|
|
\end{defundesc}
|