diff --git a/docs/strbuf-api.md b/docs/strbuf-api.md index bff8ae6..19a68de 100644 --- a/docs/strbuf-api.md +++ b/docs/strbuf-api.md @@ -81,7 +81,7 @@ As mybuffer is a pointer, members of the strbuf_t may be accessed using the arro typedef struct strbuf_allocator_t { void* app_data; - void* (*allocator)(struct strbuf_allocator_t* this_allocator, void* ptr_to_free, size_t size, const char* caller_filename, int caller_line); + void* (*allocator)(struct strbuf_allocator_t* this_allocator, void* ptr_to_free, size_t size); } strbuf_allocator_t; ## Explanation: @@ -90,7 +90,7 @@ As mybuffer is a pointer, members of the strbuf_t may be accessed using the arro   - void* (*allocator)(struct strbuf_allocator_t* this_allocator, void* ptr_to_free, size_t size, const char* caller_filename, int caller_line); + void* (*allocator)(struct strbuf_allocator_t* this_allocator, void* ptr_to_free, size_t size); A pointer to the allocator function. @@ -100,8 +100,6 @@ The parameters to this function are: struct strbuf_allocator_t* this_allocator <-- A pointer to the strbuf_allocator_t which may be used to access ->app_data. void* ptr_to_free <-- Memory address to free OR reallocate. size_t size <-- Size of allocation, or new size of the reallocation, or 0 if memory is to be freed. - const char* caller_filename <-- usually /path/strbuf.c, this is to support allocators which track caller ID. - int caller_line <-- The line within strbuf.c which called the allocator, this is also to support allocators which track caller ID.   # Allocator example @@ -110,9 +108,9 @@ Even though stdlib's realloc can be used as the default allocator in the case wh   This also available in [/examples/custom_allocator](/examples/custom_allocator/heap-buf.c) - static void* allocator(struct strbuf_allocator_t* this_allocator, void* ptr_to_free, size_t size, const char* caller_filename, int caller_line) + static void* allocator(struct strbuf_allocator_t* this_allocator, void* ptr_to_free, size_t size) { - (void)this_allocator; (void)caller_filename; (void)caller_line; + (void)this_allocator; void* result; result = realloc(ptr_to_free, size); assert(size==0 || result); // You need to catch a failed allocation here. @@ -230,32 +228,32 @@ Example use: The non-variadic version of _strbuf_cat.   -## `strview_t strbuf_append(strbuf_t** buf_ptr, strview_t str);` - Append strview_t to buffer. strview_t may be owned by the output buffer itself. +## `strview_t strbuf_append(strbuf_t** buf_ptr, str);` + Append to the buffer. **str** may either be a C string or a strview_t.   ## `strview_t strbuf_append_char(strbuf_t** buf_ptr, char c);` Append a single character to the buffer.   -## `strview_t strbuf_prepend(strbuf_t** buf_ptr, strview_t str);` - Prepend strview_t to buffer. strview_t may be owned by the output buffer itself. +## `strview_t strbuf_prepend(strbuf_t** buf_ptr, str);` + Prepend to buffer. **str** may either be a C string or a strview_t.   -## `strview_t strbuf_strip(strbuf_t** buf_ptr, strview_t stripchars);` - Strip buffer contents of all characters in strview_t. +## `strview_t strbuf_strip(strbuf_t** buf_ptr, stripchars);` + Strip buffer contents of characters in stripchars, which may either be a C string or s strview_t.   -## `strview_t strbuf_insert_at_index(strbuf_t** buf_ptr, int index, strview_t str);` - Insert strview_t to buffer at index. strview_t may be owned by the output buffer itself. The index accepts python-style negative values to index the end of the string backwards. +## `strview_t strbuf_insert_at_index(strbuf_t** buf_ptr, int index, str);` + Insert into buffer at index. str may be a C string or a strview_t. The index accepts python-style negative values to index the end of the string backwards.   -## `strview_t strbuf_insert_before(strbuf_t** buf_ptr, strview_t dst, strview_t src);` - Insert src into the buffer at the location referenced by dst. dst must reference data contained within the destination buffer. +## `strview_t strbuf_insert_before(strbuf_t** buf_ptr, strview_t dst, src);` + Insert src into the buffer at the location referenced by dst. dst must reference data contained within the destination buffer. src may be a C string or a strview_t   -## `strview_t strbuf_insert_after(strbuf_t** buf_ptr, strview_t dst, strview_t src);` - Insert src after the end of dst in the buffer. dst must reference data contained within the buffer. +## `strview_t strbuf_insert_after(strbuf_t** buf_ptr, strview_t dst, src);` + Insert src after the end of dst in the buffer. dst must reference data contained within the buffer. src may be a C string or a strview_t     diff --git a/docs/strview-api.md b/docs/strview-api.md index e0b46cc..47dd7b6 100644 --- a/docs/strview-api.md +++ b/docs/strview-api.md @@ -35,33 +35,33 @@ Note that it is valid to have a strview_t of length 0. In this case *data should   ## Comparison - * [bool strview_is_match(strview_t str1, strview_t str2);](#bool-strviewismatchstrviewt-str1-strviewt-str2) - * [bool strview_is_match_nocase(strview_t str1, strview_t str2);](#bool-strviewismatchnocasestrviewt-str1-strviewt-str2) + * [bool strview_is_match(strview_t str1, str2);](#bool-strviewismatchstrviewt-str1-strviewt-str2) + * [bool strview_is_match_nocase(strview_t str1, str2);](#bool-strviewismatchnocasestrviewt-str1-strviewt-str2) * [int strview_compare(strview_t str1, strview_t str2);](#int-strview_compare) - * [bool strview_starts_with(strview_t str1, strview_t str2);](#bool-strviewstartswithstrviewt-str1-strviewt-str2) - * [bool strview_starts_with_nocase(strview_t str1, strview_t str2);](#bool-strviewstartswithnocasestrviewt-str1-strviewt-str2) + * [bool strview_starts_with(strview_t str1, str2);](#bool-strviewstartswithstrviewt-str1-strviewt-str2) + * [bool strview_starts_with_nocase(strview_t str1, str2);](#bool-strviewstartswithnocasestrviewt-str1-strviewt-str2)   ## Trimming - * [strview_t strview_trim(strview_t str, strview_t chars_to_trim);](#strviewt-strviewtrimstrviewt-str-strviewt-charstotrim) - * [strview_t strview_trim_start(strview_t str, strview_t chars_to_trim);](#strviewt-strviewtrimstartstrviewt-str-strviewt-charstotrim) - * [strview_t strview_trim_end(strview_t str, strview_t chars_to_trim);](#strviewt-strviewtrimendstrviewt-str-strviewt-charstotrim) + * [strview_t strview_trim(strview_t str, chars_to_trim);](#strviewt-strviewtrimstrviewt-str-strviewt-charstotrim) + * [strview_t strview_trim_start(strview_t str, chars_to_trim);](#strviewt-strviewtrimstartstrviewt-str-strviewt-charstotrim) + * [strview_t strview_trim_end(strview_t str, chars_to_trim);](#strviewt-strviewtrimendstrviewt-str-strviewt-charstotrim)   ## Searching - * [strview_t strview_find_first(strview_t haystack, strview_t needle);](#strviewt-strviewfindfirststrviewt-haystack-strviewt-needle) - * [strview_t strview_find_last(strview_t haystack, strview_t needle);](#strviewt-strviewfindlaststrviewt-haystack-strviewt-needle) + * [strview_t strview_find_first(strview_t haystack, needle);](#strviewt-strviewfindfirststrviewt-haystack-strviewt-needle) + * [strview_t strview_find_last(strview_t haystack, needle);](#strviewt-strviewfindlaststrviewt-haystack-strviewt-needle)   ## Splitting * [strview_t strview_sub(strview_t str, int begin, int end);](#strviewt-strviewsubstrviewt-str-int-begin-int-end) - * [strview_t strview_split_first_delim(strview_t* src, strview_t delims);](#strviewt-strviewsplitfirstdelimstrviewt-src-strviewt-delims) - * [strview_t strview_split_last_delim(strview_t* src, strview_t delims);](#strviewt-strviewsplitlastdelimstrviewt-src-strviewt-delims) - * [strview_t strview_split_first_delim_nocase(strview_t* src, strview_t delims);](#strviewt-strviewsplitfirstdelimnocasestrviewt-src-strviewt-delims) - * [strview_t strview_split_last_delim_nocase(strview_t* src, strview_t delims);](#strviewt-strviewsplitlastdelimnocasestrviewt-src-strviewt-delims) + * [strview_t strview_split_first_delim(strview_t* src, delims);](#strviewt-strviewsplitfirstdelimstrviewt-src-strviewt-delims) + * [strview_t strview_split_last_delim(strview_t* src, delims);](#strviewt-strviewsplitlastdelimstrviewt-src-strviewt-delims) + * [strview_t strview_split_first_delim_nocase(strview_t* src, delims);](#strviewt-strviewsplitfirstdelimnocasestrviewt-src-strviewt-delims) + * [strview_t strview_split_last_delim_nocase(strview_t* src, delims);](#strviewt-strviewsplitlastdelimnocasestrviewt-src-strviewt-delims) * [strview_t strview_split_index(strview_t* src, int index);](#strviewt-strviewsplitindexstrviewt-src-int-index) * [strview_t strview_split_left(strview_t* src, strview_t pos);](#strviewt-strviewsplitleftstrviewt-src-strviewt-pos) * [strview_t strview_split_right(strview_t* src, strview_t pos);](#strviewt-strviewsplitrightstrviewt-src-strviewt-pos) @@ -95,11 +95,11 @@ Note that it is valid to have a strview_t of length 0. In this case *data should # Comparison   -## `bool strview_is_match(strview_t str1, strview_t str2);` - Return true if the strings match. Also returns true if BOTH strings are invalid. +## `bool strview_is_match(strview_t str1, str2);` + Return true if the strings match. Also returns true if BOTH strings are invalid. **str2** may be a C string or a strview_t.   -## `bool strview_is_match_nocase(strview_t str1, strview_t str2);` +## `bool strview_is_match_nocase(strview_t str1, str2);` Same as **strview_is_match()** ignoring case.   @@ -139,18 +139,19 @@ Note that it is valid to have a strview_t of length 0. In this case *data should # Searching   -## `strview_t strview_find_first(strview_t haystack, strview_t needle);` +## `strview_t strview_find_first(strview_t haystack, needle);` Return the **strview_t** for the first occurrence of needle in haystack. If the needle is not found, strview_find_first() returns an invalid strview_t. If the needle is found, the returned strview_t will match the contents of needle, only it will reference data within the haystack. This can then be used as a position reference for further parsing with strview.h functions, or modification with strbuf.h functions. + **needle** may be a C string or a strview_t. Some special cases to consider: * If **needle** is valid, and of length 0, it will always be found at the start of the string. * If **needle** is invalid, or if **haystack** is invalid, it will not be found.   -## `strview_t strview_find_last(strview_t haystack, strview_t needle);` +## `strview_t strview_find_last(strview_t haystack, needle);` Similar to strview_find_first(), but returns the LAST occurrence of **needle** in **haystack**. Some special cases to consider: @@ -168,28 +169,29 @@ Some special cases to consider: The indexes are clipped to the strings length, so INT_MAX may be safely used to index the end of the string. If the requested range is entirely outside of the input string, then an invalid **strview_t** is returned.   -## `strview_t strview_split_first_delim(strview_t* src, strview_t delims);` +## `strview_t strview_split_first_delim(strview_t* src, delims);` Return a **strview_t** representing the contents of the source string up to, but not including, any of characters in **delims**. Additionally, the contents of the returned **strview_t**, and the delim character itself is removed (popped) from the input string. If no delim is found, the returned string is the entire source string, and the source string becomes invalid. + **delim** may be a C string or a strview_t. Example usage: strview_t date = cstr("2022/10/03"); - strview_t year = strview_split_first_delim(&date, cstr("/")); - strview_t month = strview_split_first_delim(&date, cstr("/")); - strview_t day = strview_split_first_delim(&date, cstr("/")); + strview_t year = strview_split_first_delim(&date, "/"); + strview_t month = strview_split_first_delim(&date, "/"); + strview_t day = strview_split_first_delim(&date, "/");   -## `strview_t strview_split_last_delim(strview_t* src, strview_t delims);` +## `strview_t strview_split_last_delim(strview_t* src, delims);` Same as **strview_split_first_delim()** but searches from the end of the string backwards.   -## `strview_t strview_split_first_delim_nocase(strview_t* src, strview_t delims);` +## `strview_t strview_split_first_delim_nocase(strview_t* src, delims);` Same as **strview_split_first_delim()** but ignores the case of the delims   -## `strview_t strview_split_last_delim_nocase(strview_t* src, strview_t delims);` +## `strview_t strview_split_last_delim_nocase(strview_t* src, delims);` Same as **strview_split_last_delim()** but ignores the case of the delims