|
htils 1
A small set of utilities for C programming.
|
Go to the source code of this file.
Data Structures | |
| struct | _string |
| a string. More... | |
Macros | |
| #define | print_string ".*s" |
| #define | print_string_arg(string) |
| #define | HTILS_STR(base) |
Typedefs | |
| typedef struct _string | string |
| a string. | |
| typedef string | string_slice |
| A non-owning view of a string. | |
Functions | |
| string * | string_new (arena_t *arena, const u64 len) |
| Creates a new string. | |
| string * | string_from_cstr (arena_t *arena, const cstr *base) |
| Create a string from a C-string. | |
| string_slice | string_slice_from_cstr (u8 *base, u64 len) |
| Create a string_slice from a C-string. | |
| string_slice | string_slice_from_string (string *str) |
| Create a string_slice from a string. | |
| cstr * | string_to_cstr (const string *str) |
| Convert a string to a cstr. | |
| string * | string_dup (arena_t *arena, const string *from) |
Duplicates from to a new string. | |
| u64 | string_concat (arena_t *arena, string *dest, const string *src) |
| Concatenates two string. | |
| u64 | string_concatb (arena_t *arena, string *dest, const string *src, const u64 len) |
Concatenate len bytes of src to dest. | |
| u64 | string_concatf (arena_t *arena, string *dest, const cstr *fmt,...) |
| Concatenates a formatted cstr to a string. | |
| b32 | stringcmp (const string *first, const string *second) |
| Compare two string. | |
| b32 | stringcmpb (const string *first, const string *second, const u64 len) |
| Compares len bytes of each string. | |
| u64 | string_split (string *src, u8 delim, string ***darray, arena_t *arena) |
| Splits a string by a delimiter. | |
| void | string_trim (string *str) |
| Trims whitespace from the start and end of a string. | |
| void | string_trim_left (string *str) |
| Trims whitespace from the start of a string. | |
| void | string_trim_right (string *str) |
| Trims whitespace from the end of a string. | |
| i64 | string_findc (string *haystack, u8 needle) |
| Finds the first occurence of a character in a string. | |
| i64 | string_find_sstr (string *haystack, string *needle) |
| Finds the first occurance of a string in a string. | |
| #define HTILS_STR | ( | base | ) |
| #define print_string ".*s" |
Helper macro for printing strings.
| #define print_string_arg | ( | string | ) |
Helper macro that works with print_string.
| typedef string string_slice |
Concatenates two string.
Allocates a buffer for the whole of dest plus src, copies both in, and updates dest in place to point at it. The previous buffer is left to the arena.
| arena | The arena to allocate the new string in. |
| dest | The string to set to the new string. |
| src | The string to concatenate to the dest string. |
arena, dest, and src must be valid and cannot be null.Concatenate len bytes of src to dest.
Like string_concat(), but appends only the first len bytes of src.
| arena | The arena to allocate the new string in. |
| dest | The string to set to the new string. |
| src | The string to concatenate to the dest string. |
| len | The length of the bytes to concatenate. |
arena, dest, and src must be valid and cannot be null.len must be greater than 0.Concatenates a formatted cstr to a string.
Formats fmt with the variadic arguments, then appends the result to dest.
| arena | The arena to allocate the new string in. |
| dest | The string to set to the new string. |
| fmt | The format cstr to concatenate to the dest string. |
| ... | The variadic args to format the string with. |
arena, dest, and fmt must be valid and cannot be null.Duplicates from to a new string.
Allocates a new string with string_new(), and copies the contents to the new string.
arena and from must be valid and cannot be null.Create a string from a C-string.
Since string is a wrapper around the C-string pretty much, It simply creates a new string with string_new(), and then copies the contents of the C-string to the new string calculating the string's length with strlen().
arena and base must be valid and cannot be null.Creates a new string.
Allocates a string header and its backing buffer with arena_alloc(). The contents are left uninitialized.
arena must be valid and cannot be null.len must be greater than 0.| string_slice string_slice_from_cstr | ( | u8 * | base, |
| u64 | len ) |
Create a string_slice from a C-string.
We're using string_slice as a term to represent a value instead of a pointer, to have less dependents on arena allocations.
| base | The C-string to create the string_slice from. |
| len | The length of the C-string. |
base must be valid and cannot be null.len must be greater than 0.| string_slice string_slice_from_string | ( | string * | str | ) |
Create a string_slice from a string.
We're using string_slice as a term to represent a value instead of a pointer, to have less dependents on arena allocations, this is basically the same as string_slice_from_cstr() but for passing a string pointer instead for simply convenience reasons.
| str | The string to create the string_slice from. |
str must be valid and cannot be null.Splits a string by a delimiter.
Create a dynamic array of string in darray separated by delim.
| src | The string to split. |
| delim | The delimiter to split by. |
| darray | The dynamic array to store the split strings in. |
| arena | The arena to allocate the dynamic array from. |
src, darray, and arena must be valid and cannot be null.delim must be greater than 0.Casts the base param of string and then null-terminates the end of the base, and then returns it.
str must be valid and cannot be null.str must not be empty.| str | The string to convert. |
| void string_trim | ( | string * | str | ) |
| void string_trim_left | ( | string * | str | ) |
| void string_trim_right | ( | string * | str | ) |
Compares len bytes of each string.
Compares len bytes of each string to check if they're equal.
| first | The first string to compare. |
| second | The second string to compare. |
| len | The length of the bytes to compare. |