|
htils 1
A small set of utilities for C programming.
|
#include <ctype.h>#include <stdarg.h>#include <string.h>#include <h2o/memory.h>#include <htils/assert.h>#include <htils/basictypes.h>#include <h2otils/darray.h>#include <h2otils/string.h>Functions | |
| static b32 | is_whitespace (u8 c) |
| h2o_string * | h2o_string_new (h2o_mem_pool_t *pool, const u64 len) |
| Creates a new h2o_string. | |
| h2o_string * | h2o_string_from_cstr (h2o_mem_pool_t *pool, const cstr *base) |
| Creates a new h2o_string from a C-string. | |
| h2o_string * | h2o_string_from_string (h2o_mem_pool_t *pool, const string *str) |
| Converts a string to a h2o_string. | |
| h2o_string_slice | h2o_string_slice_from_cstr (const cstr *base, u64 len) |
| Create a h2o_string_slice from a C-string. | |
| h2o_string_slice | h2o_string_slice_from_h2o_string (const h2o_string *str) |
| Create a h2o_string_slice from a h2o_string. | |
| h2o_string_slice | h2o_string_slice_from_string (const string *str) |
| Create a h2o_string_slice from a string. | |
| h2o_string_slice | h2o_string_slice_slice (h2o_string_slice slice, u64 start, u64 end) |
| Slice a part of a h2o_string_slice. | |
| h2o_string_slice | h2o_string_slice_slice_len (h2o_string_slice slice, u64 start, u64 len) |
Slice a part of a h2o_string_slice to be len. | |
| cstr * | h2o_string_to_cstr (const h2o_string *str) |
| Convert a h2o_string to a C-string. | |
| h2o_string * | h2o_string_dup (h2o_mem_pool_t *pool, const h2o_string *from) |
Duplicates from to a new h2o_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. | |
| static void | to_lower (h2o_string_slice str) |
| b32 | h2o_stringcmp_case (const h2o_string *first, const h2o_string *second) |
| Compare each h2o_string, ignoring case. | |
| b32 | h2o_stringcmpb_case (const h2o_string *first, const h2o_string *second, const u64 len) |
Compare len bytes of each h2o_string, ignoring case. | |
| u64 | h2o_string_split (h2o_string *src, cstr 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. | |
| i64 | h2o_string_slice_findc (h2o_string_slice haystack, char needle) |
| i64 | h2o_string_slice_find_slice (h2o_string_slice haystack, h2o_string_slice needle) |
| i64 | h2o_string_slice_findc_from (h2o_string_slice haystack, u64 start, char needle) |
| 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 * | base | ||
| ) |
Creates a new h2o_string from a C-string.
Allocates a new h2o_string with h2o_string_new(), calculates the length with strlen(), and then copies the contents of the C-string to the new string.
| pool | The memory pool to allocate 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.| i64 h2o_string_slice_find_slice | ( | h2o_string_slice | haystack, |
| h2o_string_slice | needle | ||
| ) |
| i64 h2o_string_slice_findc | ( | h2o_string_slice | haystack, |
| char | needle | ||
| ) |
| i64 h2o_string_slice_findc_from | ( | h2o_string_slice | haystack, |
| u64 | start, | ||
| char | needle | ||
| ) |
| h2o_string_slice h2o_string_slice_from_cstr | ( | const cstr * | base, |
| u64 | len | ||
| ) |
Create a h2o_string_slice from a C-string.
We're using h2o_string_slice as a term to represent a value instead of a pointer, which helps with manpulation without allocations.
| base | The C-string to create the h2o_string_slice from. |
| len | The length of the C-string. |
base must be valid and cannot be null.len must be greater than 0.
| h2o_string_slice h2o_string_slice_from_h2o_string | ( | const h2o_string * | str | ) |
Create a h2o_string_slice from a h2o_string.
We're using h2o_string_slice as a term to represent a value instead of a pointer, which helps with manpulation without allocations.
| str | The h2o_string to create the h2o_string_slice from. |
str must be valid and cannot be null.| h2o_string_slice h2o_string_slice_from_string | ( | const string * | str | ) |
Create a h2o_string_slice from a string.
We're using h2o_string_slice as a term to represent a value instead of a pointer, which helps with manpulation without allocations.
| str | The string to create the h2o_string_slice from. |
str must be valid and cannot be null.| h2o_string_slice h2o_string_slice_slice | ( | h2o_string_slice | slice, |
| u64 | start, | ||
| u64 | end | ||
| ) |
Slice a part of a h2o_string_slice.
Slices a part of a h2o_string_slice, by offsetting base and setting a new length.
| slice | The h2o_string_slice to slice. |
| start | The start offset to slice from. |
| end | The end offset to slice to. |
slice must be valid and cannot be null.start must be less than or equal to end.end must be less than or equal to slice.len.| h2o_string_slice h2o_string_slice_slice_len | ( | h2o_string_slice | slice, |
| u64 | start, | ||
| u64 | len | ||
| ) |
Slice a part of a h2o_string_slice to be len.
Slices a part of a h2o_string_slice, by offsetting base so that it's + start and setting the length to len.
| slice | The h2o_string_slice to slice. |
| start | The start offset to slice from. |
| len | The length of the slice. |
slice must be valid and cannot be null.start must be less than or equal to slice.len.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_stringcmp_case | ( | const h2o_string * | first, |
| const h2o_string * | second | ||
| ) |
Compare each h2o_string, ignoring case.
By using memcmp, compare each h2o_string to check if they're equal, ignoring case.
| 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.| b32 h2o_stringcmpb_case | ( | const h2o_string * | first, |
| const h2o_string * | second, | ||
| const u64 | len | ||
| ) |
Compare len bytes of each h2o_string, ignoring case.
By using memcmp, compare len bytes of each h2o_string to check if they're equal, ignoring case.
| 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.
|
inlinestatic |