Strings
Module strings
import strings
| Module | strings |
| Source | strings/module-docs.zirr, strings/strings.zirr |
Text operations that count characters, not bytes.
strings works on Like — a prelude.String or a single prelude.Char — so a one-character value can be passed anywhere text is expected.
Positions here are character positions. count returns the number of UTF-8 code points, which is not the same as len(): len("café") is 5 bytes, count("café") is 4 characters. Indexing a String directly gives bytes; charAt gives characters.
Dependencies
Contents
- Unions —
Like - Functions —
charAt,concat,contains,count,firstIndexOf,from,hasPrefix,hasSuffix,isDigit,isEmpty,isLetter,isSpace,join,lastIndexOf,quote,range,repeat,replace,replaceFirst,replaceLast,slice,split,toLower,toUpper,trim,trimPrefix,trimSuffix,unquote
Unions
Like
`strings/strings.zirr:6`
union Like {
Char
String
}
A single character or a sequence of characters.
Cases
| Case | Interpretation |
|---|---|
Char |
A single character from a string. |
String |
A regular String. Can be indexed to get the Byte. Iterates over Char. |
Functions
charAt
`strings/strings.zirr:18`
extern fn charAt(v: Like, index: Int) -> Char
Returns the character at index (0-based, counting characters, not bytes).
concat
`strings/strings.zirr:100`
extern fn concat(parts: [Like]) -> String
Concatenates every part into a single String, in order.
contains
`strings/strings.zirr:53`
extern fn contains(v: Like, needle: Like) -> Bool
Returns whether needle occurs anywhere in v.
count
`strings/strings.zirr:15`
extern fn count(v: Like) -> Int
Returns the number of characters (runes) in v. Unlike len(), which counts bytes, this counts UTF-8 code points — len(“café”) is 5, count(“café”) is 4.
firstIndexOf
`strings/strings.zirr:65`
fn firstIndexOf(v: Like, needle: Like) -> Option
Returns the character index of needle’s first occurrence in v, or None if absent.
from
`strings/strings.zirr:12`
extern fn from(v: Like) -> String
Normalizes a Char or String to String.
hasPrefix
`strings/strings.zirr:56`
extern fn hasPrefix(v: Like, prefix: Like) -> Bool
Returns whether v starts with prefix.
hasSuffix
`strings/strings.zirr:59`
extern fn hasSuffix(v: Like, suffix: Like) -> Bool
Returns whether v ends with suffix.
isDigit
`strings/strings.zirr:42`
extern fn isDigit(v: Like) -> Bool
Returns whether v is not empty and every character is a decimal digit.
Unicode-aware — isDigit(‘٣’) is true, isDigit(“”) is false.
isEmpty
`strings/strings.zirr:36`
fn isEmpty(v: Like) -> Bool
Returns whether v has no characters.
isLetter
`strings/strings.zirr:46`
extern fn isLetter(v: Like) -> Bool
Returns whether v is not empty and every character is a letter.
Unicode-aware — isLetter(‘é’) is true, isLetter(“”) is false.
isSpace
`strings/strings.zirr:50`
extern fn isSpace(v: Like) -> Bool
Returns whether v is not empty and every character is whitespace.
Unicode-aware — a non-breaking space counts, isSpace(“”) is false.
join
`strings/strings.zirr:97`
extern fn join(parts: [Like], separator: Like) -> String
Joins parts into a single String, with separator between each.
lastIndexOf
`strings/strings.zirr:75`
fn lastIndexOf(v: Like, needle: Like) -> Option
Returns the character index of needle’s last occurrence in v, or None if absent.
quote
`strings/strings.zirr:121`
extern fn quote(v: Like) -> String
Returns v as a double-quoted string literal, escaping the characters that need it, so the result reads back as Zirric source. A Char is quoted as a String — quote(‘a’) is the same as quote(“a”).
range
`strings/strings.zirr:24`
fn range(v: Like, r: ranges.Like) -> String
Returns the characters of v selected by r.
repeat
`strings/strings.zirr:103`
extern fn repeat(v: Like, n: Int) -> String
Returns v repeated n times.
replace
`strings/strings.zirr:85`
extern fn replace(v: Like, target: Like, replacement: Like) -> String
Replaces every occurrence of target in v with replacement.
replaceFirst
`strings/strings.zirr:88`
extern fn replaceFirst(v: Like, target: Like, replacement: Like) -> String
Replaces only the first occurrence of target in v with replacement.
replaceLast
`strings/strings.zirr:91`
extern fn replaceLast(v: Like, target: Like, replacement: Like) -> String
Replaces only the last occurrence of target in v with replacement.
slice
`strings/strings.zirr:21`
extern fn slice(v: Like, start: Int, end: Int) -> String
Returns the characters of v from start (inclusive) to end (exclusive), counting characters, not bytes.
split
`strings/strings.zirr:94`
extern fn split(v: Like, separator: Like) -> [String]
Splits v on every occurrence of separator.
toLower
`strings/strings.zirr:109`
extern fn toLower(v: Like) -> Like
Returns v with every letter converted to lowercase. Preserves whether v was a Char or a String — toLower(‘A’) is ‘a’, toLower(“A”) is “a”.
toUpper
`strings/strings.zirr:106`
extern fn toUpper(v: Like) -> Like
Returns v with every letter converted to uppercase. Preserves whether v was a Char or a String — toUpper(‘a’) is ‘A’, toUpper(“a”) is “A”.
trim
`strings/strings.zirr:112`
extern fn trim(v: Like) -> String
Returns v with leading and trailing whitespace removed.
trimPrefix
`strings/strings.zirr:115`
extern fn trimPrefix(v: Like, prefix: Like) -> String
Returns v with a leading prefix removed, if present.
trimSuffix
`strings/strings.zirr:118`
extern fn trimSuffix(v: Like, suffix: Like) -> String
Returns v with a trailing suffix removed, if present.
unquote
`strings/strings.zirr:124`
extern fn unquote(v: Like) -> Result
Reads a quoted literal, returning Ok with the text it denotes and Err when v is not one. Both literal forms are accepted, “"hi"” and “‘a’”, and quote is inverted exactly.