Next: , Previous: , Up: API Reference   [Contents][Index]


3.5 Strings

Grip procedures and variables to process strings. The module is loaded by entering the following:

(use-modules (grip string))

Procedures

string-replace-all
string-delete-all
string-escape
string-escape-sql
string-escape-filename
string-tokens
string-contains-ixs
string-contains-ci-ixs
string-span
string-read

Variables

%filename-reserved-chars

Procedures

Procedure: string-replace-all str s1 s2 [#:start 0] [#:end (string-length str)]

Returns a string.

Replace all occurrences of s1 in the start end range of str by s2. It is an error to pass an empty s1 value.

Procedure: string-delete-all str s1 [#:start 0] [#:end (string-length str)]

Returns a string.

Delete all occurrences of s1 in the start end range of str. It is an error to pass an empty s1 value.

Procedure: string-escape str c1 c2 c3 …

Returns a string.

Replaces all str occurrences of c1, c2, c3 … by \c1, \c2, \c3

Procedure: string-escape-sql str

Returns a string.

Replaces all str occurrences of ' by ''.

Procedure: string-escape-filename str [chars %filename-reserved-chars]

Returns a string.

This procedure is implemented as (apply string-escape str chars), where chars, which is optional, defaults to the list given by %filename-reserved-chars.

If you provide your own list of chars and if it contains \, then it must be the first element of the list (since \ is the escape char itself).

Procedure: string-tokens str [#:start 0] [#:end (string-length str)] c1 c2 c3 …

Returns a a list of strings.

Split the string into a list of substring, where each substrig is a maximal non-empty contiguous sequence of characters, defined as:

(char-set-complement (apply char-set chars))

If start or end are provided, they restrict string-tokens to operate on the indicated substring of str.

Procedure: string-contains-ixs s1 s2 [#:start1 0] [end1 (string-length s1)] [#:start2 0] [end2 (string-length s2)]

Returns three values.

If s1 contains s2, the returned values are the s1 index of the first char of s2, the s1 index of the first char that follows s2, and the length of s2. Otherwise, it returns #f #f and the length of s2.

The optional keyword start/end indices maybe be provided to restrict the operation to the indicated substring.

Procedure: string-contains-ci-ixs s1 s2 [#:start1 0] [#:end1 (string-length s1)] [#:start2 0] [#:end2 (string-length s2)]

Returns three values.

If s1 contains s2, the returned values are the s1 index of the first char of s2, the s1 index of the first char that follows s2, and the length of s2. Otherwise, it returns #f #f and the length of s2.

The optional keyword start/end indices maybe be provided to restrict the operation to the indicated substring.

Character comparison is done case-insensitively.

Procedure: string-span str p1 v1 p2 v2 p3 v3 …

Returns a string.

Makes a ‘span’ string as defined by the Pango Text Attribute Markup Language. Note that string-span does not verify the validity of provided properties and values. For example:

(string-span "Guile" "foreground" "blue" "size" "x-large")
-|
$2 = "<span foreground=\"blue\" size=\"x-large\">Guile</span>"

It is an error to pass an odd quantity of properties and values.

Procedure: string-read str

Returns a value.

The returned value is the result of calling read upon str, as in:

(with-input-from-string str read)

Variables

Variable: %filename-reserved-chars

A list containing the following characters:

 \ space < > | ( ) & ; # ? *

Next: , Previous: , Up: API Reference   [Contents][Index]