kiba-engine
|
Custom library for interactions with strings using string views. More...
Go to the source code of this file.
Data Structures | |
struct | string |
Structure for a string. More... | |
struct | string_view |
Non owning views on actual strings. More... | |
Typedefs | |
typedef struct string | string |
Structure for a string. More... | |
typedef struct string_view | string_view |
Non owning views on actual strings. More... | |
Functions | |
KB_API string | string_from_raw (const char *raw) |
Construct a string from a raw string. More... | |
KB_API string | string_copy_raw (const char *raw, allocator *alloc) |
KB_API string | string_from_raw_n (const char *raw, usize n) |
Construct a string from n chars of raw character data. More... | |
KB_API string | string_join_views (const array_of(string_view) views, const char sep, allocator *alloc) |
Creates a new single string based on all provided views separated by a separator. More... | |
KB_API string | string_from_view (const string_view view, allocator *alloc) |
Creates a new string from a string view. More... | |
KB_API string | string_from_views (const array_of(string_view) views, allocator *alloc) |
Creates a new single string based on all provided views. More... | |
KB_API void | string_destroy (string *str) |
Free data of the string. More... | |
KB_API b8 | string_is_valid (const string str) |
Check if string is valid. More... | |
KB_API usize | string_index_of (const string str, const char c) |
Get the first index of a letter in a string. More... | |
KB_API string | string_clone (const string str, allocator *alloc) |
Clone a complete string. More... | |
KB_API b8 | string_equal (const string lhs, const string rhs) |
Check if the contents of two strings are equal. More... | |
KB_API b8 | string_n_equal (const string lhs, const string rhs, usize n) |
Check if the contents of two strings are equal. More... | |
KB_API string_view | string_view_from_string (const string str) |
Create a new string view of a whole string. More... | |
KB_API const char * | string_view_data (const string_view view) |
Get raw pointer to beginning of the string_view data. More... | |
KB_API b8 | string_view_equal (const string_view lhs, const string_view rhs) |
Check if the contents of two string views are equal. More... | |
KB_API b8 | string_view_n_equal (const string_view lhs, const string_view rhs, usize n) |
Check if the contents of two string views are equal. More... | |
KB_API string_view | string_view_at_offset (const string_view view, usize offset) |
Create a new string_view of an existing string_view. More... | |
KB_API string_view | string_view_subview (const string_view view, usize start, usize length) |
Create a new string_view of an existing string_view. More... | |
KB_API char | string_view_char_at (const string_view view, usize index) |
Get the letter at an specific index in a string_view. More... | |
KB_API usize | string_view_index_of (const string_view view, const char c) |
Get the first index of a letter in a string_view. More... | |
KB_API string_view | string_view_after_next_char (const string_view view, const char c) |
Create a new string_view of an existing string_view after a certain character. More... | |
KB_API string_view | string_view_until_next_char (const string_view view, const char c) |
Create a new string_view of an existing string_view until a certain character. More... | |
KB_API string_view | string_view_trim (const string_view view) |
Create a new string_view which does not start or end in whitespace. More... | |
KB_API b8 | string_view_split (const string_view view, const char c, array_of(string_view) *arr) |
Split a single string_view into multiple based on a separator. More... | |
Custom library for interactions with strings using string views.
Definition in file string.h.
Structure for a string.
Indicate ownership and allows the creation of string_view.
typedef struct string_view string_view |
Non owning views on actual strings.
Serves as a view on string data without having to copy.
KB_API void string_destroy | ( | string * | str | ) |
Check if the contents of two strings are equal.
If the length does not match they are automatically not equal.
lhs | the left hand side of the comparison |
rhs | the right hand side of the comparison |
Definition at line 118 of file string.c.
KB_API string string_from_raw | ( | const char * | raw | ) |
Construct a string from a raw string.
Will call strlen to determine the length of the data. So the caller must ensure the string-data is NULL-terminated.
raw | the raw string |
Definition at line 13 of file string.c.
KB_API string string_from_raw_n | ( | const char * | raw, |
usize | n | ||
) |
Construct a string from n chars of raw character data.
The resulting string will not own the data so it does not try to clean it. The caller must ensure that the provided n does not exceed the character data buffer.
raw | pointer to the beginning of the character data |
n | the number of bytes to expose in the string |
KB_API string string_from_view | ( | const string_view | view, |
allocator * | alloc | ||
) |
Creates a new string from a string view.
Will allocate a new owning string and copy the data from the string_view.
view | the string view to copy the data from |
alloc | the allocator to use for the new string's data |
Definition at line 61 of file string.c.
KB_API string string_from_views | ( | const array_of(string_view) | views, |
allocator * | alloc | ||
) |
Creates a new single string based on all provided views.
Will allocate a new owning string and copy all the data from the string views.
views | an array of views to join |
alloc | the allocator to use for allocating the new string's data |
Definition at line 77 of file string.c.
KB_API usize string_index_of | ( | const string | str, |
const char | c | ||
) |
KB_API b8 string_is_valid | ( | const string | str | ) |
KB_API string string_join_views | ( | const array_of(string_view) | views, |
const char | sep, | ||
allocator * | alloc | ||
) |
Creates a new single string based on all provided views separated by a separator.
Will allocate a new owning string and copy all the data from the string views.
views | an array of views to join |
sep | the separator to place between the views' data |
alloc | the allocator to use for allocating the new string's data |
Definition at line 35 of file string.c.
Check if the contents of two strings are equal.
If one of the strings does not have at least the requested length they are automatically not equal.
lhs | the left hand side of the comparison |
rhs | the right hand side of the comparison |
n | the length up to which should be compared |
Definition at line 122 of file string.c.
KB_API string_view string_view_after_next_char | ( | const string_view | view, |
const char | c | ||
) |
Create a new string_view of an existing string_view after a certain character.
The resulting string_view starts after the first occurance of the specified letter and have the remaining length to the end of the base string_view.
view | the view to base the new view on |
c | the character to start after |
Definition at line 201 of file string.c.
KB_API string_view string_view_at_offset | ( | const string_view | view, |
usize | offset | ||
) |
Create a new string_view of an existing string_view.
The resulting string_view will be at the specified offset and have the remaining length to the end of the base string_view.
view | the view to base the new view on |
offset | the offset into the base string view |
KB_API char string_view_char_at | ( | const string_view | view, |
usize | index | ||
) |
Get the letter at an specific index in a string_view.
view | the string_view to index into |
index | the index to look at |
KB_API const char* string_view_data | ( | const string_view | view | ) |
Get raw pointer to beginning of the string_view data.
Returns pointer into the underlying string at the offset of the view.
view | the view to get the data from |
KB_API b8 string_view_equal | ( | const string_view | lhs, |
const string_view | rhs | ||
) |
Check if the contents of two string views are equal.
If the length does not match they are automatically not equal.
lhs | the left hand side of the comparison |
rhs | the right hand side of the comparison |
KB_API string_view string_view_from_string | ( | const string | str | ) |
Create a new string view of a whole string.
The resulting string_view will be at offset 0 and have the same length as the string it is defined on.
str | the string to define the view on |
KB_API usize string_view_index_of | ( | const string_view | view, |
const char | c | ||
) |
Get the first index of a letter in a string_view.
view | the string_view to search through |
c | the character to look for |
KB_API b8 string_view_n_equal | ( | const string_view | lhs, |
const string_view | rhs, | ||
usize | n | ||
) |
Check if the contents of two string views are equal.
If one of the string views does not have at least the requested length they are automatically not equal.
lhs | the left hand side of the comparison |
rhs | the right hand side of the comparison |
n | the length up to which should be compared |
KB_API b8 string_view_split | ( | const string_view | view, |
const char | c, | ||
array_of(string_view) * | arr | ||
) |
Split a single string_view into multiple based on a separator.
The resulting string_views will be added to the array.
view | the string_view to split |
c | the character to split on |
arr | the array to add the string_views to |
Definition at line 241 of file string.c.
KB_API string_view string_view_subview | ( | const string_view | view, |
usize | start, | ||
usize | length | ||
) |
Create a new string_view of an existing string_view.
The resulting string_view will be at the specified offset and have the specified length.
view | the view to base the new view on |
start | the offset into the base string view |
length | the desired length of the new view |
KB_API string_view string_view_trim | ( | const string_view | view | ) |
Create a new string_view which does not start or end in whitespace.
view | the base string view to trim |
KB_API string_view string_view_until_next_char | ( | const string_view | view, |
const char | c | ||
) |
Create a new string_view of an existing string_view until a certain character.
The resulting string_view starts at the beginning of the base view and ends before the first occurance of the specified character.
view | the view to base the new view on |
c | the character to end before |
Definition at line 211 of file string.c.