SagaSaga
Standard Library

Std.String

Unicode string operations: slicing, searching, casing, and more.

Functions

length

fun length : (s: String) -> Int

Returns the number of grapheme clusters in the string.

is_empty

fun is_empty : String -> Bool

Returns True if the string is empty.

graphemes

fun graphemes : (s: String) -> List String

Splits a string into its individual grapheme clusters.

trim

fun trim : (s: String) -> String

Removes leading and trailing whitespace.

to_lower

fun to_lower : (s: String) -> String

Converts all characters to lowercase.

to_upper

fun to_upper : (s: String) -> String

Converts all characters to uppercase.

reverse

fun reverse : (s: String) -> String

Reverses the string.

slice

fun slice : (start: Int) -> (len: Int) -> (s: String) -> String

Extracts a substring starting at the given index for the given length.

find

fun find : (sub: String) -> (s: String) -> Maybe String

Finds the first occurrence of a substring, returning it and the rest.

strip_prefix

fun strip_prefix : (prefix: String) -> (s: String) -> Maybe String

Strips a prefix from the string, returning the rest or Nothing.

contains

fun contains : (sub: String) -> (s: String) -> Bool

Returns True if the string contains the substring.

starts_with

fun starts_with : (prefix: String) -> (s: String) -> Bool

Returns True if the string starts with the given prefix.

ends_with

fun ends_with : (suffix: String) -> (s: String) -> Bool

Returns True if the string ends with the given suffix.

split

fun split : (sep: String) -> (s: String) -> List String

Splits a string by a separator into a list of parts.

replace

fun replace : (pattern: String) -> (replacement: String) -> (s: String) -> String

Replaces the first occurrence of a pattern with a replacement.

replace_all

fun replace_all : (pattern: String) -> (replacement: String) -> (s: String) -> String

Replaces all occurrences of a pattern with a replacement.

join

fun join : (sep: String) -> (parts: List String) -> String

Joins a list of strings with a separator.

is_alpha

fun is_alpha : (s: String) -> Bool

Returns True if all characters are alphabetic (a-z, A-Z).

is_digit

fun is_digit : (s: String) -> Bool

Returns True if all characters are digits (0-9).

is_alphanumeric

fun is_alphanumeric : (s: String) -> Bool

Returns True if all characters are alphanumeric (a-z, A-Z, 0-9).

is_upper

fun is_upper : (s: String) -> Bool

Returns True if all characters are uppercase (A-Z).

is_lower

fun is_lower : (s: String) -> Bool

Returns True if all characters are lowercase (a-z).

is_whitespace

fun is_whitespace : (s: String) -> Bool

Returns True if all characters are whitespace.

byte_size

fun byte_size : String -> Int

Returns the length of the raw bytes of the string.

repeat

fun repeat : (n: Int) -> (s: String) -> String

Repeats a string n times.

pad_left

fun pad_left : (width: Int) -> (fill: String) -> (s: String) -> String

Pads a string on the left to the given width using the fill string.

pad_right

fun pad_right : (width: Int) -> (fill: String) -> (s: String) -> String

Pads a string on the right to the given width using the fill string.