String
A heap-allocated UTF-8 string.
Module: Std
Struct
rux
struct String {
data: *char8;
length: uint;
}A String owns a buffer of length bytes pointed to by data. The fields are implementation detail — use Data and Length to read them. Most methods that transform a string allocate a new buffer and return a new String, leaving the original untouched; the *InPlace variants mutate the receiver instead.
Methods
Construction
| Method | Description |
|---|---|
New | Creates an empty string. |
From | Creates a string by copying a literal, slice, or raw buffer. |
Clone | Returns an independent copy. |
Operators
| Method | Description |
|---|---|
+ | Concatenates two strings. |
Accessors
| Method | Description |
|---|---|
Data | Pointer to the underlying byte buffer. |
Length | Length in bytes. |
IsEmpty | Whether the string has zero length. |
Transformations
Each returns a new String, leaving the receiver unchanged.
| Method | Description |
|---|---|
ToUpper | Copy with ASCII letters uppercased. |
ToLower | Copy with ASCII letters lowercased. |
Capitalize | Copy with the first character uppercased. |
TitleCase | Copy with the first letter of each word uppercased. |
Trim | Copy with surrounding whitespace removed. |
Repeat | Copy of the string repeated N times. |
In-place transformations
These mutate the receiver's existing buffer instead of allocating a new one.
| Method | Description |
|---|---|
ToUpperInPlace | Uppercase ASCII letters in place. |
ToLowerInPlace | Lowercase ASCII letters in place. |
CapitalizeInPlace | Capitalize in place. |
TitleCaseInPlace | Title-case in place. |
TrimInPlace | Trim whitespace in place. |
Queries
| Method | Description |
|---|---|
StartsWith | Whether the string begins with a prefix. |
EndsWith | Whether the string ends with a suffix. |
Split | Split into segments on a delimiter. |
Display
| Method | Description |
|---|---|
ToString | Returns the string itself (Display). |
String implements the Display interface, so it can be passed to Print, PrintLine, and Format.
StringArray
The value returned by Split.
rux
struct StringArray {
data: *String;
length: uint;
}A contiguous array of length String values. Index it like a slice to read each segment.
Example
rux
import Std::Io::*;
import Std::String;
func Main() -> int {
let title = String::From(" the rux language ").Trim().TitleCase();
PrintLine(title); // "The Rux Language"
let parts = String::From("a,b,c").Split(c8',');
for i in 0..parts.length {
PrintLine(parts.data[i]); // a / b / c
}
return 0;
}