/// Strings (`<>` concatenates; `show` renders values). /// The number of Unicode scalar values. @extern c "tl_string_length" pub fn length :: s: String -> Int /// `parts` with `separator` between them. Linear in the result's length: /// it is allocated once, so prefer joining a list of parts to repeated `<>`. @extern c "tl_string_join" pub fn join :: parts: List separator: String -> String /// All of `parts`, in order (`join(parts, "")`). pub fn concat :: parts: List -> String { join parts "" } /// `s`, `times` times over (`""` when `times` is 0 or less). Linear in /// the result's length: the copies are doubled, so it takes about /// log2(times) concatenations and as many stack frames. pub fn repeat :: s: String times: Int -> String { if times <= 0 { "" } else { let half = repeat s (times / 2) let doubled = half <> half if times % 2 == 0 { doubled } else { doubled <> s } } } /// Whether `s` begins with `prefix`. @extern c "tl_string_starts_with" pub fn starts_with :: s: String prefix: String -> Bool /// Whether `s` ends with `suffix`. @extern c "tl_string_ends_with" pub fn ends_with :: s: String suffix: String -> Bool /// Whether `needle` occurs in `s`. @extern c "tl_string_contains" pub fn contains :: s: String needle: String -> Bool /// The byte index (UTF-8) of the first occurrence of `needle` in `s`, or /// `None`; the empty needle is found at 0. A match always starts on a /// character boundary. @extern c "tl_string_find" pub fn find :: s: String needle: String -> Option /// The length of `s` in bytes (UTF-8). @extern c "tl_string_byte_length" pub fn byte_length :: s: String -> Int /// `s` with ASCII letters in lowercase. @extern c "tl_string_to_lower" pub fn to_lower :: s: String -> String /// Whether `a` and `b` differ only in the case of ASCII letters /// (`to_lower(a) == to_lower(b)`, without building either). @extern c "tl_string_eq_ignore_ascii_case" pub fn eq_ignore_ascii_case :: a: String b: String -> Bool /// `s` without leading and trailing whitespace. @extern c "tl_string_trim" pub fn trim :: s: String -> String /// The parts of `s` between occurrences of `separator`. pub fn split :: s: String separator: String -> List { split_raw s separator } @extern c "tl_string_split" fn split_raw :: s: String separator: String -> List /// The characters of `s` (Unicode scalar values) as single-character /// strings. @extern c "tl_string_chars" pub fn chars :: s: String -> List /// The characters from `start` up to `end` (excluded). Both are clamped /// to `0..length(s)`; the result is empty when `end <= start`. @extern c "tl_string_slice" pub fn slice :: s: String start: Int end: Int -> String /// The Int written in `s` (decimal, optional sign), or an `Error` /// naming the text that is not one. pub fn to_int :: s: String -> Result { let n = parse_int s if n.0 { Ok(n.1) } else { Error("not an integer: " <> debug s) } } @extern c "tl_string_parse_int" fn parse_int :: s: String -> (Bool, Int)