[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.1.9 Strings
There are three different syntaxes for strings in Bigloo: traditional,
foreign or Unicode. The traditional syntax for strings may conform to
the Revised Report, see (R5RS)r5rs.info.
With the foreign syntax, C escape
sequences are interpreted as specified by ISO-C. In addition, Bigloo’s
reader evaluate \x??
sequence as an hexadecimal escape
character. For Unicode syntax, see Unicode (UCS-2) Strings. Only
the reader distinguishes between these three appearances of strings;
i.e., there is only one type of string at evaluation-time. The regular
expression describing the syntax for foreign string is:
#"([^"]|\")*"
. Escape characters are controlled by
the parameter bigloo-strict-r5rs-strings
(see Parameters).
The library functions for string processing are:
- library procedure: string=? string1 string2
This function returns
#t
if the string1 and string2 are made of the same characters. It returns#f
otherwise.
- bigloo procedure: substring=? string1 string2 len
This function returns
#t
if string1 and string2 have a common prefix of size len.(substring=? "abcdef" "ab9989898" 2) ⇒ #t (substring=? "abcdef" "ab9989898" 3) ⇒ #f
- bigloo procedure: substring-at? string1 string2 offset [len]
- bigloo procedure: substring-ci-at? string1 string2 offset [len]
This function returns
#t
if string2 is at position offset in the stringstring1
. It returns#f
otherwise.(substring-at? "abcdefghij" "def" 3) ⇒ #t (substring-at? "abcdefghij" "def" 2) ⇒ #f (substring-at? "abcdefghij" "defz" 3) ⇒ #f (substring-at? "abcdefghij" "defz" 3 3) ⇒ #t
- library procedure: string-ci=? string1 string2
- bigloo procedure: substring-ci=? string1 string2 len
- library procedure: string<? string1 string2
- library procedure: string>? string1 string2
- library procedure: string<=? string1 string2
- library procedure: string>=? string1 string2
- library procedure: string-ci<? string1 string2
- library procedure: string-ci>? string1 string2
- library procedure: string-ci<=? string1 string2
- library procedure: string-ci>=? string1 string2
- bigloo procedure: string-index string charset [start 0]
- bigloo procedure: string-index-right string charset [start len-1]
-
Returns the first occurrence of a character of char-or-set in string. The argument charset is either a character or a string. If no character is found,
string-index
returns#f
.
- bigloo procedure: string-skip string charset [start 0]
- bigloo procedure: string-skip-right string charset [start len-1]
-
string-skip
(resp.string-skip-right
) searches through the string from the left (resp. right), returning the index of the first occurrence of a character which- equals char/char-set/pred (if it is a character);
- is in char/char-set/pred (if it is a character set);
- satisfies the predicate char/char-set/pred (if it is a procedure).
If no match is found, the functions return false.
The start and end parameters specify the beginning and end indices of the search; the search includes the start index, but not the end index. Be careful of "fencepost" considerations: when searching right-to-left, the first index considered is end-1 whereas when searching left-to-right, the first index considered is start That is, the start/end indices describe a same half-open interval [start,end).
- bigloo procedure: string-contains string1 string2 [start 0]
- bigloo procedure: string-contains-ci string1 string2 [start 0]
-
Does string string1 contain string string2?
Return the index in string1 where string2 occurs first as a substring, or false.
string-contains-ci
is the case-insensitive variant. Case-insensitive comparison is done by case-folding characters with the operation:(char-downcase (char-upcase c))
- bigloo procedure: string-compare3 string1 string2
- bigloo procedure: string-compare3-ci string1 string2
This function compares string1 and string2. It returns a negative integer if string1 < string2. It returns zero if the string1 equal string2. It returns a positive integer if string1 > string2.
- bigloo procedure: string-natural-compare3 string1 string2 [start1 0] [start2 0]
- bigloo procedure: string-natural-compare3-ci string1 string2 [start1 0] [start2 0]
This function compares string1 and string2 according to a natural string order. It returns a negative integer if string1 < string2. It returns zero if the string1 equal string2. It returns a positive integer if string1 > string2.
(string-natural-compare "foo" "foo") ⇒ 0 (string-natural-compare "foo0" "foo1") ⇒ -1 (string-natural-compare "foo1" "foo0") ⇒ 1 (string-natural-compare "rfc822.txt" "rfc1.txt") ⇒ -1 (string-natural-compare "rfc1.txt" "rfc2086.txt") ⇒ -1 (string-natural-compare "rfc2086.txt" "rfc1.txt") ⇒ 1 (string-natural-compare "rfc822.txt" "rfc2086.txt") ⇒ -1 (string-natural-compare "a0" "a1") ⇒ -1 (string-natural-compare "a1" "a1a") ⇒ -1 (string-natural-compare "a1a" "a1b") ⇒ -1 (string-natural-compare "a1b" "a2") ⇒ -1 (string-natural-compare "a2" "a10") ⇒ -1 (string-natural-compare "a10" "a20") ⇒ -1 (string-natural-compare "a2" "a20") ⇒ -1 (string-natural-compare "x2-g8" "x2-y7") ⇒ -1 (string-natural-compare "1.001" "1.002") ⇒ -1 (string-natural-compare "1.002" "1.010") ⇒ -1 (string-natural-compare "1.010" "1.02") ⇒ 1 (string-natural-compare "1.02" "1.1") ⇒ -1 (string-natural-compare "1.1" "1.02") ⇒ 1 (string-natural-compare "1.02" "1.3") ⇒ -1
- library procedure: substring string start [end]
-
string must be a string, and start and end must be exact integers satisfying:
0 <= START <= END <= (string-length STRING)
The optional argument end defaults to
(string-length STRING)
.substring
returns a newly allocated string formed from the characters of STRING beginning with index START (inclusive) and ending with index END (exclusive).(substring "abcdef" 0 5) ⇒ "abcde" (substring "abcdef" 1 5) ⇒ "bcde"
- library procedure: string-shrink! string end
-
string must be a string, and end must be an exact integers satisfying:
0 <= END <= (string-length STRING)
string-shrink!
returns a newly allocated string formed from the characters of STRING beginning with index 0 (inclusive) and ending with index END (exclusive). As much as possiblestring-shrink!
changes the argument string. That is, as much as possible, and for the back-ends that enable it, string-shrink! operate a side effect on its argument.(let ((s (string #\a #\b #\c #\d #\e))) (set! s (string-shrink! s 3)) s) ⇒ "abc"
- library procedure: string-append string …
- library procedure: string->list string
- library procedure: list->string list
- library procedure: string-copy string
- bigloo procedure: string-fill! string char
Stores char in every element of the given string and returns an unspecified value.
- bigloo procedure: string-downcase string
Returns a newly allocated version of string where each upper case letter is replaced by its lower case equivalent.
- bigloo procedure: string-upcase string
Returns a newly allocated version of string where each lower case letter is replaced by its upper case equivalent.
- bigloo procedure: string-for-read string
Returns a copy of string with each special character replaced by an escape sequence.
- bigloo procedure: blit-string! string1 o1 string2 o2 len
Fill string string2 starting at position o2 with len characters taken out of string string1 from position o1.
(let ((s (make-string 20 #\-))) (blit-string! "toto" 0 s 16 4) s) ⇒ "----------------toto"
- bigloo procedure: string-replace string char1 char2
- bigloo procedure: string-replace! string char1 char2
Replace all the occurrence of char1 by char2 in string. The function
string-replace
returns a newly allocated string. The functionstring-replace!
modifies its first argument.
- bigloo procedure: string-split string
- bigloo procedure: string-split string delimiters
-
Parses string and returns a list of tokens ended by a character of the delimiters string. If delimiters is omitted, it defaults to a string containing a space, a tabulation and a newline characters.
(string-split "/usr/local/bin" "/") ⇒ ("usr" "local" "bin") (string-split "once upon a time") ⇒ ("once" "upon" "a" "time")
- bigloo procedure: string-cut string
- bigloo procedure: string-cut string delimiters
The function
string-cut
behaves asstring-split
but it introduces empty strings for consecutive occurrences of delimiters.(string-cut "/usr//local/bin" "/") ⇒ ("usr" "" "local" "bin") (string-cut "once upon a time") ⇒ ("once" "" "" "" "upon" "a" "time")
- SRFI-13 procedure: string-delete string char/charset/pred s [start end]
-
Filter the string string, retaining only those characters that are not equal to char, not present in charset, or not satisfying pred. This function returns a fresh string no larger than end - start.
- SRFI-13 procedure: string-prefix-length s1 s2 [start1 end1 start2 end2]
- SRFI-13 procedure: string-suffix-length s1 s2 [start1 end1 start2 end2]
- SRFI-13 procedure: string-prefix-length-ci s1 s2 [start1 end1 start2 end2]
- SRFI-13 procedure: string-suffix-length-ci s1 s2 [start1 end1 start2 end2]
Return the length of the longest common prefix/suffix of the two strings. For prefixes, this is equivalent to the "mismatch index" for the strings (modulo the starti index offsets).
The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.
- SRFI-13 procedure: string-prefix? s1 s2 [start1 end1 start2 end2]
- SRFI-13 procedure: string-suffix? s1 s2 [start1 end1 start2 end2]
- SRFI-13 procedure: string-prefix-ci? s1 s2 [start1 end1 start2 end2]
- SRFI-13 procedure: string-suffix-ci? s1 s2 [start1 end1 start2 end2]
-
Is s1 a prefix/suffix of s2?
The optional start/end indices restrict the comparison to the indicated substrings of s1 and s2.
- bigloo procedure: string-hex-intern string
- bigloo procedure: string-hex-intern! string
Converts an hexadecimal string of
n
characters into an actual string ofn/2
characters.(string-hex-intern "4a4b4c") ⇒ "JKL"
- bigloo procedure: string-hex-extern string
Converts a string into a hexadecimal representation.
(string-hex-extern "JKL") ⇒ "4a4b4c"
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 31, 2014 using texi2html 5.0.