This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see StringSlicesCowan in WG2's repo for R7RS-large.

String­Slices­Cowan

cowan
2014-11-24 03:00:32
6history
source

String slice library

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.

Issues

  1. Allow negative indices in constructors?
  1. Titlecase doesn't really fit; keep it?
  1. Keep functional update?
  1. Keep string trees?
  1. Keep compatibility routines, possibly in a different package?

String constructors

(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 constructors

(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)

Predicates

(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)

Selection

(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)

Padding, trimming, and compressing

(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 ])

Prefixes and suffixes

(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]

Searching

(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]

The whole string slice or string

(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]

Folding and mapping

(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]

Parsing

(string-slice-split slice [char [ limit'' ] ])

(string-slice-split slice [char [ limit'' ] ])

Filtering and partitioning

(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)

Conversion

(string-slice->list slice)

(string-slice->vector slice)

string->list [R7RS-small] list->string [R7RS-small] vector->string [R7RS-small] string->vector [R7RS-small]

String cursors

string-cursor-start string-cursor-end string-cursor-ref string-cursor-next string-cursor-previous string-cursor-forward string-cursor-backward string-cursor-forward-until string-cursor-backward-until string-cursor=? string-cursor<? string-cursor>? string-cursor<=? string-cursor>=? string-cursor->index string-index->cursor string-cursors->string string-cursor-difference

Functional update

string-slice-set string-set string-slice-fill string-fill string-slice-replace string-replace string-slice-insert string-insert string-slice-delete string-delete

String trees

string-tree->string write-string-tree

Compatibility

string-slice-upcase string-slice-downcase string-slice-foldcase string-slice=? string-slice<? string-slice>? string-slice<=? string-slice>=? string-slice-ci=? string-slice-ci<? string-slice-ci>? string-slice-ci<=? string-slice-ci>=? string-slice-titlecase string-titlecase [SRFI 13]