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#
| Name | Description |
|---|---|
Span | A match: the byte offsets start..end of the matched text. |
Traits#
| Name | Description |
|---|---|
Pattern | Something a [Searchable] value can be searched for: a plain string (matched literally), or a type such as coil-regex’s Regex. |
Searchable | Pattern search methods (contains, find, split, replace_all, …) on any [Show] type, which search its display form. |
Functions#
| Name | Description |
|---|---|
byte_len | Returns the length of s in bytes; the same as s.len(). |
slice | Returns the part of s from byte offset start up to (not including) end. |
trim_start | Returns s without leading ASCII whitespace (space, tab, CR, LF). |
trim_end | Returns s without trailing ASCII whitespace (space, tab, CR, LF). |
trim | Returns s without leading and trailing ASCII whitespace (space, tab, CR, LF). |
rfind | Returns the byte offset of the last needle in hay, or -1. |
split_at | Splits s at byte offset at into the part before and the part from at on. |
join | Returns the parts concatenated with sep between each pair. |
repeat | Returns s repeated n times; empty when n <= 0. |
pad_left | Returns s with fill added in front until it is width bytes long. |
pad_right | Returns s with fill added at the end until it is width bytes long. |
lines | Splits s into lines at each LF, dropping one CR before it (so CRLF works too). |
concat | Returns a followed by b; the same as a + b. |
eq | Returns true when a and b hold the same bytes; the same as a == b. |
to_lower | Returns s with ASCII A-Z turned into a-z; other characters are unchanged. |
to_upper | Returns s with ASCII a-z turned into A-Z; other characters are unchanged. |