Module
pooka/string
src/pooka/string.pookaText has letters, bytes and occasionally a combining mark travelling alone.
Represent UTF-8 strings and expose code-point operations. Length, slicing and to_list count Unicode code points, not bytes or grapheme clusters. Slice offsets are clamped through list operations; use byte-oriented APIs when encoding layout matters.
import pooka/string
assert string.slice("🐇oak", 1, 2) == "oa"
API reference
length(text: String) -> Int
fn(String) -> IntCount Unicode code points, including combining marks as their own points.
import pooka/string
assert string.length("🐇oak") == 4
is_empty(text: String) -> Bool
fn(String) -> BoolAsk whether the string contains no bytes and no code points.
import pooka/string
assert string.is_empty("")
concat(left: String, right: String) -> String
fn(String, String) -> StringAppend the second UTF-8 string to the first.
import pooka/string
assert string.concat("oak", "leaf") == "oakleaf"
join(parts: List(String), separator: String) -> String
fn(List(String), String) -> StringPlace the separator between strings, without adding one at either end.
import pooka/string
assert string.join(["oak", "pine"], ", ") == "oak, pine"
split(text: String, separator: String) -> List(String)
fn(String, String) -> List(String)Split on a separator; an empty separator yields individual Unicode code points.
import pooka/string
assert string.split("oak:pine", ":") == ["oak", "pine"]
contains(text: String, needle: String) -> Bool
fn(String, String) -> BoolTest for a substring. Every string contains the empty string.
import pooka/string
assert string.contains("oakleaf", "leaf")
starts_with(text: String, prefix: String) -> Bool
fn(String, String) -> BoolCheck the beginning of the string without changing it.
import pooka/string
assert string.starts_with("oakleaf", "oak")
ends_with(text: String, suffix: String) -> Bool
fn(String, String) -> BoolCheck the end of the string without changing it.
import pooka/string
assert string.ends_with("oakleaf", "leaf")
replace(text: String, old: String, replacement: String) -> String
fn(String, String, String) -> StringReplace all nonoverlapping occurrences. An empty search string leaves the text unchanged.
import pooka/string
assert string.replace("oak oak", "oak", "pine") == "pine pine"
trim(text: String) -> String
fn(String) -> StringRemove supported Unicode whitespace from both ends.
import pooka/string
assert string.trim(" oak ") == "oak"
trim_start(text: String) -> String
fn(String) -> StringRemove supported Unicode whitespace from the beginning only.
import pooka/string
assert string.trim_start(" oak ") == "oak "
trim_end(text: String) -> String
fn(String) -> StringRemove supported Unicode whitespace from the end only.
import pooka/string
assert string.trim_end(" oak ") == " oak"
uppercase(text: String) -> String
fn(String) -> StringApply the runtime's Unicode uppercase conversion.
import pooka/string
assert string.uppercase("oak") == "OAK"
lowercase(text: String) -> String
fn(String) -> StringApply the runtime's Unicode lowercase conversion.
import pooka/string
assert string.lowercase("OAK") == "oak"
slice(text: String, start: Int, count: Int) -> String
fn(String, Int, Int) -> StringTake count code points after dropping start code points. Nonpositive bounds follow list drop/take semantics.
import pooka/string
assert string.slice("🐇oak", 1, 2) == "oa"
repeat(text: String, count: Int) -> String
fn(String, Int) -> StringJoin count copies of the text. A nonpositive count produces an empty string.
import pooka/string
assert string.repeat("ha", 3) == "hahaha"
to_list(text: String) -> List(Int)
fn(String) -> List(Int)Expose the Unicode scalar values as integer code points.
import pooka/string
assert string.to_list("A") == [65]