Utility functions for character arrays.
πΉ π 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 chars = @import("io").chars;
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.
var array = chars.initWithCapacity(u8, 100);
Then you can use it just like the example below with full flexibility.
// Append a slice.
try chars.appendSlice(u8, &array, "ello π¨βπ!", 0); // π "ello π¨βπ!"
// Append a character.
try chars.appendChar(u8, &array, 'H', 17); // π "Hello π¨βπ!"
// Get the length of the array.
_ = chars.countWritten(u8, &array); // π 18
// Get the visual length of the array.
_ = chars.countVisual(u8, &array); // π 8
// Find the position of a substring.
_ = chars.find(u8, array, "π¨βπ"); // π 6
// Check if the array includes a specific substring.
_ = chars.includes(u8, array, "π¨βπ"); // π true
// and much more . . !
Function | Description |
---|---|
initWithCapacity | Initializes an array of chars of a given size , filled with null chars. |
initWithSlice | Initializes an array of chars of a given size and value , terminated with a null char. |
initWithSliceAssumeCapacity | Initializes an array of chars of a given size and value . |
Function | Description |
---|---|
insertSlice | Inserts a slice into dest at the specified position by real position. |
insertChar | Inserts a char into dest at the specified position by real position. |
visualInsertSlice | Inserts a slice into dest at the specified visual position . |
visualInsertChar | Inserts a char into dest at the specified visual position . |
appendSlice | Appends a slice into dest . |
appendChar | Appends a char into dest . |
prependSlice | Prepends a slice into dest . |
prependChar | Prepends a char into dest . |
Function | Description |
---|---|
removeIndex | Removes a char from the dest . |
removeVisualIndex | Removes a char from the dest by the visual position . |
removeRange | Removes a range of chars from the dest . |
removeVisualRange | Removes a range of chars from the dest by the visual position . |
pop | Returns the length of the last grapheme cluster at the dest . |
shift | Removes the first grapheme cluster at the dest , returns the number of removed chars. |
Function | Description |
---|---|
find | Finds the position of the first occurrence of target . |
findVisual | Finds the visual position of the first occurrence of target . |
findLast | Finds the position of the last occurrence of target . |
findLastVisual | Finds the visual position of the last occurrence of target . |
includes | Returns true if dest contains target . |
startsWith | Returns true if dest starts with target . |
endsWith | Returns true if dest ends with target . |
Function | Description |
---|---|
toLower | Converts all (ASCII) letters to lowercase. |
toUpper | Converts all (ASCII) letters to uppercase. |
toTitle | Converts all (ASCII) letters to titlecase. |
reverse | Reverses the order of the chars. |
reverseUnicode | Reverses the order of the chars in the Self instance (considering Unicode). |
Function | Description |
---|---|
isChar | Returns true if the value is a valid char. |
isSlice | Returns true if the value is a valid array of chars. |
Function | Description |
---|---|
countWritten | Returns the total number of written chars, stopping at the first null char. |
countVisual | Returns the total number of visual chars. |
writtenSlice | Returns a slice containing only the written part. |
Function | Description |
---|---|
split | Splits the written portion of the string into substrings separated by the delimiter. |
splitAll | Splits the written portion of the string into all substrings separated by the delimiter. |
Function | Description |
---|---|
replaceAllChars | Replaces all occurrence of a character with another. |
replaceAllSlices | Replaces all occurrences of a slice with another. |
replaceRange | Replaces a range of chars with another. |
replaceVisualRange | Replaces a visual range of chars with another. |
Function | Description |
---|---|
equals | Returns true if the a is equal to b . |
isEmpty | Returns true if the value is empty. |
Prints the contents of the slice to the standard writer. |
|
printTo | Prints the contents of the slice to the given writer. |
printWithNewline | Prints the contents of the slice to the standard writer and adds a newline. |
Utility functions for Unicode codepoints and grapheme clusters.
Immutable fixed-size string type that supports unicode.
Managed dynamic-size string type that supports unicode.
Mutable fixed-size string type that supports unicode.
Unmanaged dynamic-size string type that supports unicode.