|
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) (int)(string)->len, (cstr *)(string)->base |
| #define | HTILS_STR(base) string_from_cstr(arena, base) |
Typedefs | |
| typedef struct _string | string |
| a string. | |
Functions | |
| string * | string_new (arena_t *arena, const u64 len) |
| Creates a new string. | |
| string * | string_dup (arena_t *arena, const string *from) |
Duplicates from to a new string. | |
| string * | string_from_cstr (arena_t *arena, const cstr *base) |
| Create a string from a C-string. | |
| cstr * | string_to_cstr (const string *str) |
| Convert a string to a cstr. | |
| u64 | string_concat (arena_t *arena, string *dest, const string *src) |
| Concatenates two strings. | |
| 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 occurance 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 | ) | string_from_cstr(arena, base) |
| #define print_string ".*s" |
Helper macro for printing strings.
Helper macro that works with print_string.
Concatenates two strings.
By allocating a new string using arena_alloc() with the size of the 2 strings passed, and then copying them over, and then setting dest to be that new string.
| 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.
Concatenates len bytes of src to dest, by allocating a new string with the size of dest + len, and then copying dest, then len bytes of src to the new string, then sets dest to the new string.
| 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.
Concatenates a formatted cstr to a string, by first handling the formatting of the variadic args, then calculating the length of them, making a new string and then copying dest, and fmt to the new string, before setting 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 new string using arena_alloc(), with the given length, it's contents are null by default.
arena must be valid and cannot be null.len must be greater than 0.Splits a string by a delimiter.
Create a dynamic array of string in darray seperated 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.| 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. |