Immutable fixed-size string type that supports unicode.
πΉ π Quick Start β A quick guide to get you started with the library.
πΉ π API Reference β Detailed documentation of available functions.
If you have not already added the library to your project, please review the installation guide for more information.
const Viewer = @import("io").Viewer;
Now letβs create our container, but before that we need to define the data type used to store the values, for example:
If you are going to deal with (
utf8
,utf16
, ..) encoding, you can use (u8
,u16
, ..) as the data type.
const view = try Viewer(u8).init("Hello π¨βπ!");
Then you can use it just like the example below with full flexibility.
// Get the length of the viewer.
_ = view.len(); // π 18
// Get the visual length of the viewer.
_ = view.vlen(); // π 8
// Get a byte at a specific index.
_ = view.charAt(0); // π 'H'
// Get a character at a specific visual position.
_ = view.atVisual(6); // π "π¨βπ"
// Find the position of a substring.
_ = view.find("π¨βπ"); // π 6
// Check if the viewer includes a specific substring.
_ = view.includes("π¨βπ"); // π true
// and much more . . !
Field | Type | Description |
---|---|---|
m_src |
[]const u8 |
The immutable unicode encoded chars. |
m_len |
usize |
The number of written chars. |
Function | Description |
---|---|
init | Initializes a Viewer instance with anytype. |
initEmpty | Initializes a new empty Viewer instance. |
initWithChar | Initializes a new Viewer instance with the specified initial char . |
initWithSlice | Initializes a new Viewer instance with the specified initial chars . |
initWithSelf | Initializes a new Viewer instance with the specified initial Viewer . |
Function | Description |
---|---|
size | Returns the number of chars that can be written. |
len | Returns the total number of written chars. |
vlen | Returns the total number of visual characters. |
src | Returns a slice containing only the written part. |
sub | Returns a sub-slice of the Viewer . |
charAt | Returns a character at the specified index. |
atVisual | Returns a character at the specified visual position. |
iterator | Creates an iterator for traversing the Unicode chars. |
Function | Description |
---|---|
find | Finds the position of the first occurrence of the target slice. |
findVisual | Finds the visual position of the first occurrence of the target slice. |
findLast | Finds the position of the last occurrence of the target slice. |
findLastVisual | Finds the visual position of the last occurrence of the target slice. |
includes | Returns true if the Viewer instance contains the target slice. |
startsWith | Returns true if the Viewer instance starts with the target slice. |
endsWith | Returns true if the Viewer instance ends with the target slice. |
Function | Description |
---|---|
isEqual | Returns true if the Viewer instance equals the given target slice. |
isEmpty | Returns true if the Viewer instance is empty. |
Function | Description |
---|---|
split | Splits the written portion into substrings separated by the specified delimiters. |
splitAll | Splits the written portion into all substrings separated by the specified delimiters. |
splitToSelf | Splits the written portion into substrings separated by the specified delimiters, returning the substring at the specified index as a new Viewer instance. |
splitAllToSelf | Splits the written portion into all substrings separated by the specified delimiters, returning an array of new Viewer instances. |
Function | Description |
---|---|
clone | Returns a deep copy of the Viewer instance. |
clear | Clears the contents of the Viewer . |
Prints the contents of the Viewer instance to the standard writer. |
|
printTo | Prints the contents of the Viewer instance to the given writer. |
printWithNewline | Prints the contents of the Viewer instance to the standard writer and adds a newline. |
Utility functions for Unicode codepoints and grapheme clusters.
Utility functions for char arrays.
Managed dynamic-size string type that supports unicode.
Mutable fixed-size string type that supports unicode.
Unmanaged dynamic-size string type that supports unicode.