This is a library for manipulating textual content based on string slices, which are references to part of a Scheme string, and string cursors, which are pointers into strings. It is not defined whether the string slice type is disjoint from strings, or whether string cursors are a disjoint type at all. String slices are immutable, and it is an error to mutate the underlying string.
In addition, string cursors may or may not be the same as character-based indexes into strings. For example, in an implementation whose internal representation of strings is UTF-8, string cursors may be pointers to individual bytes in the string. However, the operations provided here (with the exception of those in the Compatibility section) are entirely independent of the character repertoire supported by the implementation.
This proposal also contains a useful subset of SRFI 13, which manipulates strings directly with some allowances for shared substrings (which are both then and now provided only on Guile). The string operations of this proposal are defined in terms of the string slice operations. Unlike SRFI 13, it does not provide start and end arguments, as their functionality is subsumed by slices. In addition, the low-level procedures are not provided, nor are any mutation operations. Procedures with the same names and functions as SRFI-13 procedures are marked [SRFI 13]; note that they don't necessarily support all of the arguments of the SRFI 13 versions.
Procedures marked [R7RS-small] are available in the small language, and are not exported by implementations of this proposal. They are included only for completeness.
All predicates passed to procedures defined in this proposal may be called in any order and any number of times, except as otherwise noted.
(make-string k [ char ]) [R7RS-small]
(string char ...) [R7RS-small]
(string-unfold stop? mapper successor [ seed ])
(string-unfold-right stop? mapper successor [ seed ])
(char->string char)
(string-slice-whole string)
(string-slice string start end)
(string-subslice slice start end)
(string-slice/cursors string start-cursor end-cursor)
(string-subslice/cursors string start-cursor end-cursor)
(string-slice-transform proc slice arg ...)
(char->string-slice char)
(string-slice? obj)
(string? obj) [R7RS-small]
(string-slice-null? slice)
(string-null? string) [SRFI 13]
(string-slice-every pred slice)
(string-every pred string) [SRFI 13]
(string-slice-any pred slice)
(string-any pred string) [SRFI 13]
(string-slice-whole? slice)
(is-char? char)
(in-char-set? char-set)
(string-slice-ref slice k)
(string-ref string k) [R7RS-small]
(string-slice-take slice n)
(string-take string n) [SRFI 13]
(string-slice-take-right slice n)
(string-take-right string n) [SRFI 13]
(string-slice-drop slice n)
(string-drop string n) [SRFI 13]
(string-slice-drop-right slice n)
(string-drop-right string n) [SRFI 13]
(string-slice-split-at slice n)
(string-split-at string n) [SRFI 13]
(string-slice-replicate slice from to)
(string-replicate string from to)
(string-slice-pad slice len [ char ])
(string-pad string len [ char ]) [SRFI 13]
(string-slice-trim slice len [ char ])
(string-trim string len [ char ]) [SRFI 13]
(string-slice-trim-right slice len [ char ])
(string-trim-right string len [ char ]) [SRFI 13]
(string-slice-trim-both slice len [ char ])
(string-trim-both string len [ char ]) [SRFI 13]
(string-slice-compress slice [ char ])
(string-compress string [ char ])
(string-slice-prefix slice1 slice2)
(string-prefix string1 string2)
(string-slice-suffix slice1 slice2)
(string-suffix string1 string2) [SRFI 13]
(string-slice-prefix-length slice1 slice2)
(string-prefix-length string1 string2)
(string-slice-suffix-length slice1 slice2) [SRFI 13]
(string-suffix-length string1 string2)
(string-slice-prefix? slice1 slice2)
(string-prefix? string1 string2) [SRFI 13]
(string-slice-suffix? slice1 slice2)
(string-suffix? string1 string2) [SRFI 13]
(string-slice-count proc slice)
(string-count proc string) [SRFI 13]
(string-slice-take-while proc slice)
(string-take-while proc string) [SRFI 13]
(string-slice-drop-while proc slice)
(string-drop-while proc string) [SRFI 13]
(string-slice-break proc slice)
(string-break proc string) [SRFI 13]
(string-slice-drop proc slice)
(string-drop proc string) [SRFI 13]
(string-slice-contains slice1 slice2)
(string-contains string1 string2) [SRFI 13]
(string-slice-length slice)
(string-length string) [R7RS-small]
(string-slice-copy slice)
(string-copy string [ start [ end ] ]) [R7RS-small]
(string-slice-reverse slice)
(string-reverse slice) [SRFI 13]
(string-slice-append slice ...)
(string-append string ...) [R7RS-small]
(string-slice-concatenate list-of-slices)
(string-concatenate list-of-strings) [SRFI 13]
(string-slice-concatenate-reverse list-of-slices)
(string-concatenate-reverse list-of-strings) [SRFI 13]
(string-slice-map proc slice ...)
(string-map proc string ...) [R7RS-small]
(string-slice-for-each proc slice ...)
(string-for-each proc string ...) [R7RS-small]
(string-slice-fold proc nil slice)
(string-fold proc nil string) [R7RS-small]
(string-slice-fold-right proc nil slice)
(string-fold-right proc nil string) [R7RS-small]
(string-slice-split slice [char [ limit'' ] ])
(string-slice-split slice [char [ limit'' ] ])
(string-slice-filter proc slice) [SRFI 13]
(string-filter proc string)
(string-slice-remove proc slice)
(string-remove proc string)
(string-slice-partition proc slice)
(string-partition proc string)
(string-slice->list slice)
(string-slice->vector slice)
string->list [R7RS-small] list->string [R7RS-small] vector->string [R7RS-small] string->vector [R7RS-small]