string
String utilities.
String stores UTF-8 bytes, but the operations in this module are byte-based. Lengths, indices, and slices refer to byte offsets, not Unicode characters.
Types
_None._
Functions
from_int(value: int, region: Region) -> String
Convert an integer to a string.
Parameters
value: int- Integer value.region: Region- Allocation region for the result.
Returns
- A newly allocated decimal string.
---
from_double(value: double, region: Region) -> String
Convert a double to a string.
Parameters
value: double- Double value.region: Region- Allocation region for the result.
Returns
- A newly allocated string representation of the double.
---
from_bool(value: bool, region: Region) -> String
Convert a boolean to a string.
Parameters
value: bool- Boolean value.region: Region- Allocation region for the result.
Returns
"true"or"false".
---
from_char(value: char, region: Region) -> String
Convert a character to a string.
Parameters
value: char- Character value.region: Region- Allocation region for the result.
Returns
- A newly allocated one-byte string.
---
concat(foreign left: String, foreign right: String, region: Region) -> String
Concatenate two strings.
Parameters
foreign left: String- Left string.foreign right: String- Right string.region: Region- Allocation region for the result.
Returns
- Concatenated string.
---
ends_with(foreign s: String, foreign suffix: String) -> bool
Return whether s ends with suffix.
Parameters
foreign s: String- Source string.foreign suffix: String- Suffix to check.
Returns
trueifsends withsuffix, otherwisefalse.
---
find(foreign s: String, foreign needle: String) -> int
Find the first occurrence of needle in s.
Parameters
foreign s: String- Source string.foreign needle: String- Substring to search for.
Returns
- First match byte index or
-1.
Notes
- Returns the start byte index of the first match, or
-1if no match exists.
---
join(foreign parts: Vec[String], foreign delim: String, r: Region) -> String
Join strings from parts with delim inserted between adjacent elements.
Parameters
foreign parts: Vec[String]- Input string parts.foreign delim: String- Delimiter string.r: Region- Allocation region for the joined string.
Returns
- A newly allocated joined string.
Notes
- If
partsis empty, the function returns an empty string.
---
replace(foreign s: String, foreign needle: String, foreign repl: String, region: Region) -> String
Replace all occurrences of needle in s with repl.
Parameters
foreign s: String- Source string.foreign needle: String- Substring to replace.foreign repl: String- Replacement substring.region: Region- Allocation region for the result.
Returns
- A newly allocated string with all matches replaced.
Notes
- If
needleis empty, the function returns a copy ofs.
---
copy(foreign s: String, region: Region) -> String
Copy a string into a different allocation region.
Parameters
foreign s: String- Source string.region: Region- Allocation region for the result.
Returns
- A newly allocated string in the destination region.
---
throws slice(foreign s: String, from: int, to: int, region: Region) -> String
Return a substring of s from byte index start (inclusive) to byte index end (exclusive).
Behavior
- Throws on failure.
Parameters
foreign s: String- Source string.from: int- Start byte index (inclusive).to: int- End byte index (exclusive).region: Region- Allocation region for the result.
Returns
- A newly allocated substring.
---
split(foreign s: String, foreign delim: String, r: Region) -> Vec[String]
Split a string by a delimiter.
Parameters
foreign s: String- Input string.foreign delim: String- Delimiter string.r: Region- Allocation region for the output vector.
Returns
- A vector of tokens.
---
starts_with(foreign s: String, foreign prefix: String) -> bool
Return whether s starts with prefix.
Parameters
foreign s: String- Source string.foreign prefix: String- Prefix to check.
Returns
trueifsstarts withprefix, otherwisefalse.
---
throws to_double(s: String) -> double
Convert a string to a double.
Behavior
- Throws on failure.
Parameters
s: String- Input string.
Returns
- Parsed double value.
---
throws to_int(s: String) -> int
Convert a string to an integer.
Behavior
- Throws on failure.
Parameters
s: String- Input string.
Returns
- Parsed integer value.
---
trim(foreign s: String, region: Region) -> String
Return a copy of s with leading and trailing whitespace removed.
Parameters
foreign s: String- Source string.region: Region- Allocation region for the result.
Returns
- Trimmed string.
Notes
- Whitespace is classified using
char::isspace. - Whitespace classification is byte-based.