Module coil-stdlib

text

Offsets are byte offsets, as everywhere in Coil. Functions that cut a string return a Result, because a cut inside a multi-byte character is an error. The compiler-provided string module has format and the UTF-8 conversions.

Part of coil-stdlib. spool projects get it automatically; with plain coil, pass --root ~/.coil/stdlib/src.

Import what you use (use path::* is not allowed):

use text::{Span, Pattern};

Types#

NameDescription
SpanA match: the byte offsets start..end of the matched text.

Traits#

NameDescription
PatternSomething a [Searchable] value can be searched for: a plain string (matched literally), or a type such as coil-regex’s Regex.
SearchablePattern search methods (contains, find, split, replace_all, …) on any [Show] type, which search its display form.

Functions#

NameDescription
byte_lenReturns the length of s in bytes; the same as s.len().
sliceReturns the part of s from byte offset start up to (not including) end.
trim_startReturns s without leading ASCII whitespace (space, tab, CR, LF).
trim_endReturns s without trailing ASCII whitespace (space, tab, CR, LF).
trimReturns s without leading and trailing ASCII whitespace (space, tab, CR, LF).
rfindReturns the byte offset of the last needle in hay, or -1.
split_atSplits s at byte offset at into the part before and the part from at on.
joinReturns the parts concatenated with sep between each pair.
repeatReturns s repeated n times; empty when n <= 0.
pad_leftReturns s with fill added in front until it is width bytes long.
pad_rightReturns s with fill added at the end until it is width bytes long.
linesSplits s into lines at each LF, dropping one CR before it (so CRLF works too).
concatReturns a followed by b; the same as a + b.
eqReturns true when a and b hold the same bytes; the same as a == b.
to_lowerReturns s with ASCII A-Z turned into a-z; other characters are unchanged.
to_upperReturns s with ASCII a-z turned into A-Z; other characters are unchanged.
↑ ↓ navigate ↵ open