|
htils 1
A small set of utilities for C programming.
|
Go to the source code of this file.
Typedefs | |
| typedef h2o_iovec_t | h2o_string |
Functions | |
| h2o_string * | h2o_string_new (h2o_mem_pool_t *pool, const u64 len) |
| Creates a new h2o_string. | |
| h2o_string * | h2o_string_from_string (h2o_mem_pool_t *pool, const string *str) |
| Converts a string to a h2o_string. | |
| h2o_string * | h2o_string_dup (h2o_mem_pool_t *pool, const h2o_string *str) |
Duplicates from to a new h2o_string. | |
| h2o_string * | h2o_string_from_cstr (h2o_mem_pool_t *pool, const cstr *str) |
| Create a h2o_string from a C-string. | |
| cstr * | h2o_string_to_cstr (const h2o_string *str) |
| Convert a h2o_string to a C-string. | |
| u64 | h2o_string_concat (h2o_mem_pool_t *pool, h2o_string *dest, const h2o_string *src) |
| Concatenates the first h2o_string to the second. | |
| u64 | h2o_string_concatb (h2o_mem_pool_t *pool, h2o_string *dest, const h2o_string *src, const u64 len) |
Concatenates len bytes of src to dest. | |
| u64 | h2o_string_concatf (h2o_mem_pool_t *pool, h2o_string *dest, const cstr *fmt,...) |
| Concatenates a formatted C-string to a h2o_string. | |
| b32 | h2o_stringcmp (const h2o_string *first, const h2o_string *second) |
| Compare two h2o_string. | |
| b32 | h2o_stringcmpb (const h2o_string *first, const h2o_string *second, const u64 len) |
Compare len bytes of each h2o_string. | |
| u64 | h2o_string_split (h2o_string *src, char delim, h2o_string ***h2o_darray, h2o_mem_pool_t *pool) |
| Splits a h2o_string by a delimiter. | |
| void | h2o_string_trim (h2o_string *str) |
| Trims whitespace from the start and end of a h2o_string. | |
| void | h2o_string_trim_left (h2o_string *str) |
| Trims whitespace from the start of a h2o_string. | |
| void | h2o_string_trim_right (h2o_string *str) |
| Trims whitespace from the end of a h2o_string. | |
| i64 | h2o_string_findc (h2o_string *haystack, char needle) |
| Finds the first occurance of a character in a h2o_string. | |
| i64 | h2o_string_find_sstr (h2o_string *haystack, h2o_string *needle) |
| Finds the first occurance of a h2o_string in a h2o_string. | |
| typedef h2o_iovec_t h2o_string |
A collection of functions to bridge the gap between htils strings and h2o mem pools. Type-alias for h2o_iovec_t.
| u64 h2o_string_concat | ( | h2o_mem_pool_t * | pool, |
| h2o_string * | dest, | ||
| const h2o_string * | src | ||
| ) |
Concatenates the first h2o_string to the second.
By allocating a new h2o_string, with the size of both dest and src, then copying them over to dest.
| pool | The memory pool to allocate the new string in. |
| dest | The h2o_string to set to the new string. |
| src | The h2o_string to concatenate to the dest string. |
pool, dest, and src must be valid and cannot be null.| u64 h2o_string_concatb | ( | h2o_mem_pool_t * | pool, |
| h2o_string * | dest, | ||
| const h2o_string * | src, | ||
| const u64 | len | ||
| ) |
Concatenates len bytes of src to dest.
Concatenates len bytes of src to dest, by allocating a new h2o_string, with the size of dest + len, then copying dest, then len bytes of src to the new h2o_string, then sets dest to the new h2o_string.
| pool | The memory pool to allocate the new string in. |
| dest | The h2o_string to set to the new string. |
| src | The h2o_string to concatenate to the dest string. |
| len | The length of the bytes to concatenate. |
pool, dest, and src must be valid and cannot be null.len must be greater than 0.| u64 h2o_string_concatf | ( | h2o_mem_pool_t * | pool, |
| h2o_string * | dest, | ||
| const cstr * | fmt, | ||
| ... | |||
| ) |
Concatenates a formatted C-string to a h2o_string.
Concatenates a formatted C-string to a h2o_string, by first capturing the format with the args, and then copying them over to a new h2o_string, and then setting @dest to it.
| pool | The memory pool to allocate the new string in. |
| dest | The h2o_string to set to the new string. |
| fmt | The format C-string to concatenate to the dest string. |
| ... | The variadic args to format the h2o_string with. |
pool, dest, and fmt must be valid and cannot be null.| h2o_string * h2o_string_dup | ( | h2o_mem_pool_t * | pool, |
| const h2o_string * | str | ||
| ) |
Duplicates from to a new h2o_string.
Allocates a new string with h2o_string_new(), and copies the contents to the new string.
| pool | The memory pool to allocate the string from. |
| from | The h2o_string to duplicate. |
pool and from must be valid and cannot be null.| i64 h2o_string_find_sstr | ( | h2o_string * | haystack, |
| h2o_string * | needle | ||
| ) |
Finds the first occurance of a h2o_string in a h2o_string.
Uses looping to find the first occurance of a h2o_string in a h2o_string.
| haystack | the h2o_string to search in. |
| needle | the h2o_string to search for. |
haystack and needle must be valid and cannot be null.| i64 h2o_string_findc | ( | h2o_string * | haystack, |
| char | needle | ||
| ) |
Finds the first occurance of a character in a h2o_string.
Uses looping to find the first occurance of a character in a h2o_string.
| haystack | the h2o_string to search in. |
| needle | The character to search for. |
haystack must be valid and cannot be null.needle must be greater than 0.| h2o_string * h2o_string_from_cstr | ( | h2o_mem_pool_t * | pool, |
| const cstr * | str | ||
| ) |
Create a h2o_string from a C-string.
Since h2o_string is a wrapper around the C-string pretty much, It simply creates a new h2o_string with h2o_string_new(), and then copies the contents of the C-string to the new string calculating the string's length with strlen().
| pool | The memory pool to allocate the string from. |
| base | The C-string to create the h2o_string from. |
pool and base must be valid and cannot be null.| h2o_string * h2o_string_from_string | ( | h2o_mem_pool_t * | pool, |
| const string * | str | ||
| ) |
Converts a string to a h2o_string.
By simply making a new h2o_string and copying over the string data.
| pool | The memory pool to allocate the string from. |
| str | The string to convert. |
pool, and str must be valid and not null.| h2o_string * h2o_string_new | ( | h2o_mem_pool_t * | pool, |
| const u64 | len | ||
| ) |
Creates a new h2o_string.
Allocates a new h2o_string with the given length, it's contents are null by default.
| pool | The memory pool to allocate from. |
| len | The length for the string. |
pool must be valid and cannot be null.len must be greater than 0.| u64 h2o_string_split | ( | h2o_string * | src, |
| char | delim, | ||
| h2o_string *** | h2o_darray, | ||
| h2o_mem_pool_t * | pool | ||
| ) |
Splits a h2o_string by a delimiter.
Creates a dynamic array of h2o_string in darray seperated by the delimiter provided in delim.
| src | The h2o_string to split. |
| delim | The delimiter to split by. |
| darray | The dynamic array to store the split strings in. |
| pool | The memory pool to allocate the dynamic array from. |
src, darray, and pool must be valid and cannot be null.delim must be greater than 0.| cstr * h2o_string_to_cstr | ( | const h2o_string * | str | ) |
Convert a h2o_string to a C-string.
Gets the base param of h2o_string and then null-terminates the end of the base, and then returns it.
| str | The h2o_string to convert. |
str must be valid and cannot be null.return A pointer to the C-string.
| void h2o_string_trim | ( | h2o_string * | str | ) |
Trims whitespace from the start and end of a h2o_string.
Checks for whitespaces and new-lines and trims them away using pointer arithmetic.
| str | the h2o_string to trim. |
str must be valid and cannot be null. | void h2o_string_trim_left | ( | h2o_string * | str | ) |
Trims whitespace from the start of a h2o_string.
Checks for whitespaces and new-lines and trims them away using pointer arithmetic.
| str | the h2o_string to trim. |
str must be valid and cannot be null. | void h2o_string_trim_right | ( | h2o_string * | str | ) |
Trims whitespace from the end of a h2o_string.
Checks for whitespaces and new-lines and trims them away using pointer arithmetic.
| str | the h2o_string to trim. |
str must be valid and cannot be null. | b32 h2o_stringcmp | ( | const h2o_string * | first, |
| const h2o_string * | second | ||
| ) |
Compare two h2o_string.
Compare the length and the base of 2 h2o_string to check if they're equal using h3o_memis().
| first | The first h2o_string to compare. |
| second | The second h2o_string to compare. |
first and second must be valid and cannot be null.| b32 h2o_stringcmpb | ( | const h2o_string * | first, |
| const h2o_string * | second, | ||
| const u64 | len | ||
| ) |
Compare len bytes of each h2o_string.
By using memcmp, compare len bytes of each h2o_string to check if they're equal.
| first | The first h2o_string to compare. |
| second | The second h2o_string to compare. |
| len | The length of the bytes to compare. |
first and second must be valid and cannot be null.len must be greater than 0.