15 KB_API
string string_copy_raw(
const char *raw,
allocator *alloc) {
38 usize length = array_size(views) - 1;
39 array_for_each(
const string_view, view, views) { length += view->length; }
56 .length = i == length ? length : 0,
81 array_for_each(
const string_view, view, views) { length += view->length; }
96 .length = i == length ? length : 0,
141 for (usize i = 0; i < lhs.
length; ++i) {
157 for (usize i = 0; i < n; ++i) {
169 .offset = src.
offset + offset,
177 .offset = view.
offset + start,
192 for (usize i = 0; i < view.
length; ++i) {
206 .offset = view.
offset + index + 1,
207 .is_valid = view.
is_valid && index != USIZE_MAX,
217 .is_valid = view.
is_valid && index != USIZE_MAX,
222 usize new_offset = src.
offset;
223 usize new_length = src.
length;
225 while (new_offset < src.
offset + src.
length && character_is_whitespace(src.
str.
data[new_offset])) {
229 while (new_length > 0 && character_is_whitespace(src.
str.
data[new_offset + new_length - 1])) {
236 .offset = new_offset,
242 KB_ASSERT(arr,
"provided array must be valid");
245 while (end != USIZE_MAX) {
247 if (!cur_view.
is_valid || !array_push_checked(arr, &cur_view)) {
256 if (!remaining_view.
is_valid || !array_push_checked(arr, &remaining_view)) {
void * allocator_allocate(allocator *alloc, usize size)
Allocate unaligned memory.
void allocator_free(allocator *alloc, void *mem)
Give back memory to the allocator.
void * memory_copy(void *dst, const void *src, usize size)
Copy memory.
Lightweight layer between platform and other engine components to enable tracing/monitoring.
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.
b8 string_view_split(const string_view view, const char sep, array_of(string_view) *arr)
Split a single string_view into multiple based on a separator.
string_view string_view_at_offset(const string_view src, usize offset)
Create a new string_view of an existing string_view.
b8 string_view_equal(const string_view lhs, const string_view rhs)
Check if the contents of two string views are equal.
void string_destroy(string *str)
Free data of the string.
usize string_view_index_of(const string_view view, const char c)
Get the first index of a letter in a string_view.
string string_from_raw_n(const char *raw, usize n)
Construct a string from n chars of raw character data.
b8 string_is_valid(const string str)
Check if string is valid.
string_view string_view_trim(const string_view src)
Create a new string_view which does not start or end in whitespace.
usize string_index_of(const string str, const char c)
Get the first index of a letter in a string.
string string_from_view(const string_view src, allocator *alloc)
Creates a new string from a string view.
const char * string_view_data(const string_view view)
Get raw pointer to beginning of the string_view data.
char string_view_char_at(const string_view view, usize index)
Get the letter at an specific index in a string_view.
string_view string_view_subview(const string_view view, usize start, usize length)
Create a new string_view of an existing string_view.
string_view string_view_from_string(const string str)
Create a new string view of a whole string.
b8 string_equal(const string lhs, const string rhs)
Check if the contents of two strings are equal.
string string_clone(const string str, allocator *alloc)
Clone a complete string.
string string_from_views(const array_of(string_view) views, allocator *alloc)
Creates a new single string based on all provided views.
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.
b8 string_n_equal(const string lhs, const string rhs, usize n)
Check if the contents of two strings are equal.
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.
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.
string string_from_raw(const char *raw)
Construct a string from a raw string.
Custom library for interactions with strings using string views.
#define KB_MIN(x, y)
Ternary to get the minimum of two numbers.
#define KB_NULL
Value of an invalid ptr (nullptr).
#define KB_ASSERT(expr,...)
Perform runtime assertion and log failures.
Central allocator structure.
Non owning views on actual strings.
string str
The string the view is defined on.
b8 is_valid
Indicates if the view is valid and can be used/accessed.
usize length
The length of the view.
usize offset
The offset into the string.
allocator * alloc
The allocator used for construction. KB_NULL if constructed from a raw literal.
char * data
The character sequence of the string.
usize length
The length of the string.