std/core/sslice▲toc

Efficient views on strings.

.

type sslicestd/core/sslice/sslice: V

A sslicestd/core/sslice/sslice: V represents a sub-slice of string and has a specific start position and character count. It is used instead of string indices to make the actual internal representation of strings abstract (like UTF-8 or UTF-16). String slices are returned by functions that find sub strings or patterns in in strings. Use string to create a fresh substring from a slice.

The start and len fields of a slice are in terms of bytes. Slices should only be interacted with safe methods defined in core that take care to not cut strings in the middle of a utf codepoint.

Inequality based on contents of the slice O(n+m) where n and m are the lengths of the two strings.

Inequality of slices at the same offset and length on the same string. (The strings do not have to be referentially identical though).

Equality based on contents of the slice O(n+m) where n and m are the lengths of the two strings.

Equality of slices at the same offset and length on an equal string (The strings do not have to be referentially identical though).

O(count). Advance the start position of a string slice by count characters up to the end of the string. A negative count advances the start position backwards upto the first position in a string. Maintains the character count of the original slice upto the end of the string. For example:

O(1). Return the string slice from the end of slicestd/core/sslice/slice: (s : string) -> sslice argument to the end of the string.

O(1). Return the string slice from the start of a string up to the start of slicestd/core/sslice/slice: (s : string) -> sslice argument.

Return the common prefix of two strings (upto upto characters (default is minimum length of the two strings)).

O(n). Return the number of characters in a string slice.

Gets a slice that drops the first n characters, shrinking the length of the slice by n accordingly. If the slice does not have n characters, then the slice is shrunk to an empty slice.

If maintaining the length of the slice is important, use advancestd/core/sslice/advance: (slice : sslice, count : int) -> sslice instead.

O(count). Extend a string slice by count characters up to the end of the string. A negative count shrinks the slice up to the empty slice. For example:

O(n). The first n (default = 1) characters in a string.
fun foreach( slice : sslicestd/core/sslice/sslice: V, action : (c : charstd/core/types/char: V) -> e () ) : e ()

Apply a function for each character in a string slice.

Apply a function for each character in a string slice. If action returns Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>, the function returns immediately with that result.

O(n). The last n (default = 1) characters in a string.

O(1). The entire string as a slice.

O(n). Copy the slicestd/core/sslice/slice: (s : string) -> sslice argument into a fresh string. Takes O(1) time if the slice covers the entire string.

Gets up to (end-start) characters from the slice beginning from start. If either start or end is negative, returns the original slice.

Gets a slice that only includes up to n characters from the start of the slice.

Truncates a slice to length 0.

fun pred/count( s : stringstd/core/types/string: V, pred : (charstd/core/types/char: V) -> e boolstd/core/types/bool: V ) : e intstd/core/types/int: V

Count the number of times a predicate is true for each character in a string.

fun string/foreach( s : stringstd/core/types/string: V, action : (c : charstd/core/types/char: V) -> e () ) : e ()

Invoke a function for each character in a string.

fun string/foreach-while( s : stringstd/core/types/string: V, action : (c : charstd/core/types/char: V) -> e maybestd/core/types/maybe: V -> V<a> ) : e maybestd/core/types/maybe: V -> V<a>

Invoke a function for each character in a string. If action returns Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>, the function returns immediately with that result.

fun string/truncate( s : stringstd/core/types/string: V, count : intstd/core/types/int: V ) : stringstd/core/types/string: V

Truncate a string to count characters.

fun capitalize( s : stringstd/core/types/string: V ) : stringstd/core/types/string: V

Convert the first character of a string to uppercase.

fun ends-with( s : stringstd/core/types/string: V, post : stringstd/core/types/string: V ) : maybestd/core/types/maybe: V -> V<sslicestd/core/sslice/sslice: V>

Does string s end with post? If so, returns a slice of s from the start up to the post string at the end.

fun find( s : stringstd/core/types/string: V, sub : stringstd/core/types/string: V ) : maybestd/core/types/maybe: V -> V<sslicestd/core/sslice/sslice: V>

O(n). If it occurs, return the position of substring sub in s, tupled with the position just following the substring sub.

fun find-last( s : stringstd/core/types/string: V, sub : stringstd/core/types/string: V ) : maybestd/core/types/maybe: V -> V<sslicestd/core/sslice/sslice: V>

Return the last index of substring sub in s if it occurs.

fun head-char( s : stringstd/core/types/string: V ) : maybestd/core/types/maybe: V -> V<charstd/core/types/char: V>

Return the first character of a string (or Nothingstd/core/types/Nothing: forall<a> maybe<a> for the empty string).

fun starts-with( s : stringstd/core/types/string: V, pre : stringstd/core/types/string: V ) : maybestd/core/types/maybe: V -> V<sslicestd/core/sslice/sslice: V>

Is pre a prefix of s? If so, returns a slice of s following pre up to the end of s.

fun tail( s : stringstd/core/types/string: V ) : stringstd/core/types/string: V

Return the tail of a string (or the empty string).

fun trim-left( s : stringstd/core/types/string: V, sub : stringstd/core/types/string: V ) : stringstd/core/types/string: V

Trim off a substring sub while s starts with that string.

fun trim-right( s : stringstd/core/types/string: V, sub : stringstd/core/types/string: V ) : stringstd/core/types/string: V

Trim off a substring sub while s ends with that string.

private import std/core/typesstd/core/types, std/core/undivstd/core/undiv, std/core/unsafestd/core/unsafe, std/core/hndstd/core/hnd, std/core/intstd/core/int, std/core/stringstd/core/string