Std.String

import Std.String

Source


Functions


reverse

reverse (var s: String): String can Fs

source


split

(split: fn String Char -> (fn Unit [String, Char] -> Unit can Emit String, Fs) is pure) (s: String) (c: Char)

Split a string at the given character. Emits substrings separated by the given character.

For example split "foo bar baz " will emit all of: [“foo”, “bar”, “”, “baz”, “"]

source


substr

substr (var s: String) (begin: Usz) (end: Usz): String

Returns a substring into the given string. The given begin..end range represents an end-exclusive byte range of the substring to create.

This function does not allocate - the resulting substring increments the reference count of the original string.

source


string_of

string_of (s: s) {_: Stream s Char e}: String can Panic, e

Collect each character from the given stream into a String

source


join

join (s: s) {_: Stream s String e}: String can e

Join each string from the stream into one string.

If a separator is desired between each string, use this in combination with intersperse, e.g. join <| intersperse my_stream (fn () -> "")

source


bytes

(bytes: fn String -> (fn Unit [String] -> Unit can Emit U8) is pure) (s: String)

Emits each byte in this string

source


chars

(chars: fn String -> (fn Unit [(fn Unit [fn Unit [String] -> Unit can Emit U8] -> Unit can Emit U8), (Stream (fn Unit [fn Unit [String] -> Unit can Emit U8] -> Unit can Emit U8) U8 pure), (fn U8 -> Char is pure)] -> Unit can Emit Char) is pure) (s: String)

Emits each character in this string

TODO: No utf-8 checking is done and this currently just emits each byte

source


starts_with

starts_with (s: ref String) (prefix: ref String): Bool

True if s begins with prefix.

source


ends_with

ends_with (s: ref String) (suffix: ref String): Bool

True if s ends with suffix.

source


contains

contains (s: ref String) (needle: ref String): Bool

True if needle appears anywhere in s. O(n*m) naive scan.

source


trim_start

trim_start (s: String): String can Fs

Return a substring with leading ASCII whitespace removed.

source


trim_end

trim_end (s: String): String can Fs

Return a substring with trailing ASCII whitespace removed.

source


trim

trim (s: String): String can Fs

Return a substring with both leading and trailing ASCII whitespace removed.

source


parse_i32

parse_i32 (s: String): I32 can Fail, Fs

Parse a base-10 I32 from a string.

Fails for empty strings, sign-only strings, non-digits, or overflow.

source


parse_i8

parse_i8 (s: String): I8 can Fail, Fs

source


parse_i16

parse_i16 (s: String): I16 can Fail, Fs

source


parse_i64

parse_i64 (s: String): I64 can Fail, Fs

source


parse_isz

parse_isz (s: String): Isz can Fail, Fs

source


parse_u8

parse_u8 (s: String): U8 can Fail, Fs

source


parse_u16

parse_u16 (s: String): U16 can Fail, Fs

source


parse_u32

parse_u32 (s: String): U32 can Fail, Fs

source


parse_u64

parse_u64 (s: String): U64 can Fail, Fs

source


parse_usz

parse_usz (s: String): Usz can Fail, Fs

source


parse_signed_int

parse_signed_int (s: String) {n: Num t} {_: CheckedNum t} {_: Cast I32 t e} {_: Copy t}: t can Fail, Fs, e

source


parse_unsigned_int

parse_unsigned_int (s: String) {n: Num t} {_: CheckedNum t} {_: Cast U8 t e} {_: Copy t}: t can Fail, Fs, e

source


from_c_string

from_c_string (cstr: C.String): String

Copy a null-terminated C string into a new string.

source


to_ascii_lowercase

to_ascii_lowercase (s: ref String): String

Returns the given string with each ASCII letter converted to lowercase. The original string is never mutated.

source


to_ascii_uppercase

to_ascii_uppercase (s: ref String): String

Returns the given string with each ASCII letter converted to uppercase. The original string is never mutated.

source


Implicits


Show Implicits

eq_string

impl eq_string: Eq String pure

source


try_cast_string_i8

impl try_cast_string_i8: TryCast String I8 Fs

source


try_cast_string_i16

impl try_cast_string_i16: TryCast String I16 Fs

source


try_cast_string_i32

impl try_cast_string_i32: TryCast String I32 Fs

source


try_cast_string_i64

impl try_cast_string_i64: TryCast String I64 Fs

source


try_cast_string_isz

impl try_cast_string_isz: TryCast String Isz Fs

source


try_cast_string_u8

impl try_cast_string_u8: TryCast String U8 Fs

source


try_cast_string_u16

impl try_cast_string_u16: TryCast String U16 Fs

source


try_cast_string_u32

impl try_cast_string_u32: TryCast String U32 Fs

source


try_cast_string_u64

impl try_cast_string_u64: TryCast String U64 Fs

source


try_cast_string_usz

impl try_cast_string_usz: TryCast String Usz Fs

source