diff --git a/README.md b/README.md index 7cfcb6d..a7090ac 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ It should be noted, that __strview.h__ and __strnum.h__ do not depend on __strbu   ## Advantages over SDS -* STR also supports static or heap allocated buffers. +* STR also supports static or stack allocated buffers. * STR supports more than one type of allocator at runtime. * STR provides number parsing, with error and range checking. diff --git a/docs/strview-api.md b/docs/strview-api.md index ed2de28..3eb58ff 100644 --- a/docs/strview-api.md +++ b/docs/strview-api.md @@ -58,15 +58,15 @@ Note that it is valid to have a strview_t of length 0. In this case *data should ## Splitting * [strview_t strview_sub(strview_t str, int begin, int end);](#strviewt-strviewsubstrviewt-str-int-begin-int-end) - * [strview_t strview_split_first_delimeter(strview_t* strview_ptr, strview_t delimiters);](#strviewt-strviewsplitfirstdelimeterstrviewt-strviewptr-strviewt-delimiters) - * [strview_t strview_split_last_delimeter(strview_t* strview_ptr, strview_t delimiters);](#strviewt-strviewsplitlastdelimeterstrviewt-strviewptr-strviewt-delimiters) - * [strview_t strview_split_first_delimiter_nocase(strview_t* strview_ptr, strview_t delimiters);](#strviewt-strviewsplitfirstdelimiternocasestrviewt-strviewptr-strviewt-delimiters) - * [strview_t strview_split_last_delimeter_nocase(strview_t* strview_ptr, strview_t delimiters);](#strviewt-strviewsplitlastdelimeternocasestrviewt-strviewptr-strviewt-delimiters) - * [strview_t strview_split_index(strview_t* strview_ptr, int index);](#strviewt-strviewsplitindexstrviewt-strviewptr-int-index) - * [strview_t strview_split_left(strview_t* strview_ptr, strview_t pos);](#strviewt-strviewsplitleftstrviewt-strviewptr-strviewt-pos) - * [strview_t strview_split_right(strview_t* strview_ptr, strview_t pos);](#strviewt-strviewsplitrightstrviewt-strviewptr-strviewt-pos) - * [char strview_pop_first_char(strview_t* strview_ptr);](#char-strviewpopfirstcharstrviewt-strviewptr) - * [strview_t strview_split_line(strview_t* strview_ptr, char* eol);](#strviewt-strviewsplitlinestrviewt-strviewptr-char-eol) + * [strview_t strview_split_first_delimeter(strview_t* src, strview_t delimiters);](#strviewt-strviewsplitfirstdelimeterstrviewt-src-strviewt-delimiters) + * [strview_t strview_split_last_delimeter(strview_t* src, strview_t delimiters);](#strviewt-strviewsplitlastdelimeterstrviewt-src-strviewt-delimiters) + * [strview_t strview_split_first_delimiter_nocase(strview_t* src, strview_t delimiters);](#strviewt-strviewsplitfirstdelimiternocasestrviewt-src-strviewt-delimiters) + * [strview_t strview_split_last_delimeter_nocase(strview_t* src, strview_t delimiters);](#strviewt-strviewsplitlastdelimeternocasestrviewt-src-strviewt-delimiters) + * [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) + * [char strview_pop_first_char(strview_t* src);](#char-strviewpopfirstcharstrviewt-src) + * [strview_t strview_split_line(strview_t* src, char* eol);](#strviewt-strviewsplitlinestrviewt-src-char-eol) @@ -164,7 +164,7 @@ 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_delimeter(strview_t* strview_ptr, strview_t delimiters);` +## `strview_t strview_split_first_delimeter(strview_t* src, strview_t delimiters);` Return a **strview_t** representing the contents of the source string up to, but not including, any of characters in **delimiters**. Additionally, the contents of the returned **strview_t**, and the delimiter character itself is removed (popped) from the input string. If no delimiter is found, the returned string is the entire source string, and the source string becomes invalid. @@ -177,19 +177,19 @@ Example usage: strview_t day = strview_split_first_delimeter(&date, cstr("/"));   -## `strview_t strview_split_last_delimeter(strview_t* strview_ptr, strview_t delimiters);` +## `strview_t strview_split_last_delimeter(strview_t* src, strview_t delimiters);` Same as **strview_split_first_delimeter()** but searches from the end of the string backwards.   -## `strview_t strview_split_first_delimiter_nocase(strview_t* strview_ptr, strview_t delimiters);` +## `strview_t strview_split_first_delimiter_nocase(strview_t* src, strview_t delimiters);` Same as **strview_split_first_delimeter()** but ignores the case of the delimiters   -## `strview_t strview_split_last_delimeter_nocase(strview_t* strview_ptr, strview_t delimiters);` +## `strview_t strview_split_last_delimeter_nocase(strview_t* src, strview_t delimiters);` Same as **strview_split_last_delimeter()** but ignores the case of the delimiters   -## `strview_t strview_split_index(strview_t* strview_ptr, int index);` +## `strview_t strview_split_index(strview_t* src, int index);` Split a strview_t at a specified index n. * For n >= 0 Return a strview_t representing the first n characters of the source string. @@ -215,16 +215,16 @@ Simply assign the source to your destination before splitting: first_word = strview_split_first_delimiter(&first_word, cstr(" ")); (full view remains unmodified)   -## `strview_t strview_split_left(strview_t* strview_ptr, strview_t pos);` -Given a view (pos) into strview_ptr, will return a strview_t containing the content to the left of strview_ptr. The returned view will be removed (popped) from strview_ptr. +## `strview_t strview_split_left(strview_t* src, strview_t pos);` +Given a view (pos) into src, will return a strview_t containing the content to the left of pos. The returned view will be removed (popped) from src.   -## `strview_t strview_split_right(strview_t* strview_ptr, strview_t pos);` -Given a view (pos) into strview_ptr, will return a strview_t containing the content to the right of strview_ptr. The returned view will be removed (popped) from strview_ptr. +## `strview_t strview_split_right(strview_t* src, strview_t pos);` +Given a view (pos) into src, will return a strview_t containing the content to the right of pos. The returned view will be removed (popped) from src.   -## `char strview_pop_first_char(strview_t* strview_ptr);` -Return the first char of *strview_ptr, and remove it from *strview_ptr. +## `char strview_pop_first_char(strview_t* src);` +Return the first char of *src, and remove it from *src. Returns 0 if there are no characters in str. If str is known to contain at least one character, it is the equivalent of: @@ -232,7 +232,7 @@ Returns 0 if there are no characters in str. Only it avoids dereferencing a NULL pointer in the case where strview_split_index() would return an invalid strview_t due to the string being empty.   -## `strview_t strview_split_line(strview_t* strview_ptr, char* eol);` +## `strview_t strview_split_line(strview_t* src, char* eol);` Returns a strview_t representing the first line within the source string, not including the eol terminator. The returned line and the terminator are removed (popped) from the source string. If a line terminator is not found, an invalid strview_t is returned and the source string is unmodified. diff --git a/examples/custom_allocator/build_date.inc b/examples/custom_allocator/build_date.inc index 277dc5f..40537e3 100644 --- a/examples/custom_allocator/build_date.inc +++ b/examples/custom_allocator/build_date.inc @@ -1 +1 @@ -"2023-03-12T06:10:38+00:00" +"2023-03-13T05:20:51+00:00" diff --git a/examples/custom_allocator/build_number.inc b/examples/custom_allocator/build_number.inc index b1bd38b..8351c19 100644 --- a/examples/custom_allocator/build_number.inc +++ b/examples/custom_allocator/build_number.inc @@ -1 +1 @@ -13 +14 diff --git a/examples/parse-uri/build_date.inc b/examples/parse-uri/build_date.inc index b1b25b5..b377a8f 100644 --- a/examples/parse-uri/build_date.inc +++ b/examples/parse-uri/build_date.inc @@ -1 +1 @@ -"2023-03-12T06:10:55+00:00" +"2023-03-13T05:21:15+00:00" diff --git a/examples/parse-uri/build_number.inc b/examples/parse-uri/build_number.inc index 98d9bcb..3c03207 100644 --- a/examples/parse-uri/build_number.inc +++ b/examples/parse-uri/build_number.inc @@ -1 +1 @@ -17 +18 diff --git a/examples/testnum/build_date.inc b/examples/testnum/build_date.inc index 5945e98..d37c3ea 100644 --- a/examples/testnum/build_date.inc +++ b/examples/testnum/build_date.inc @@ -1 +1 @@ -"2023-03-12T06:11:06+00:00" +"2023-03-13T05:21:29+00:00" diff --git a/examples/testnum/build_number.inc b/examples/testnum/build_number.inc index 8179054..f27ce70 100644 --- a/examples/testnum/build_number.inc +++ b/examples/testnum/build_number.inc @@ -1 +1 @@ -573 +574 diff --git a/strview.h b/strview.h index c7d9ddb..6d88499 100644 --- a/strview.h +++ b/strview.h @@ -102,18 +102,18 @@ /* Return a strview_t representing the contents of the source string up to, but not including, any of the delimiters. Additionally this text, and the delimeter itself is removed (popped) from the source string. If no delimeter is found, the returned string is the entire source string, and the source string becomes invalid */ - strview_t strview_split_first_delimeter(strview_t* strview_ptr, strview_t delimiters); + strview_t strview_split_first_delimeter(strview_t* src, strview_t delimiters); // Same as strview_split_first_delimeter, ignoring case on the delimiters - strview_t strview_split_first_delimiter_nocase(strview_t* strview_ptr, strview_t delimiters); + strview_t strview_split_first_delimiter_nocase(strview_t* src, strview_t delimiters); /* Return a strview_t representing the contents of the source string from (but not including) the last delimiter found. Additionally this text, and the delimeter itself is removed (popped) from the end of the source string. If no delimeter is found the returned string is the entire source string, and the source string becomes invalid */ - strview_t strview_split_last_delimeter(strview_t* strview_ptr, strview_t delimiters); + strview_t strview_split_last_delimeter(strview_t* src, strview_t delimiters); // Same as strview_split_last_delimeter, ignoring case on the delimiters - strview_t strview_split_last_delimeter_nocase(strview_t* strview_ptr, strview_t delimiters); + strview_t strview_split_last_delimeter_nocase(strview_t* src, strview_t delimiters); /* Split a strview_t at a specified index n. For n >= 0 @@ -126,30 +126,29 @@ Additionally the last -n characters are removed (popped) from the end of the source string. If -n is greater than the size of the source string ALL characters will be popped. */ - strview_t strview_split_index(strview_t* strview_ptr, int index); + strview_t strview_split_index(strview_t* src, int index); /* Split a strview_t at a position specified by pos - If pos references characters within *strview_ptr, return a strview_t representing all characters to the left of pos. - If pos references the upper limit of *strview_ptr, the entire *strview_ptr is returned. - If pos references the start of *strview_ptr, a valid strview_t of length 0 is returned. + If pos references characters within *src, return a strview_t representing all characters to the left of pos. + If pos references the upper limit of *src, the entire *src is returned. + If pos references the start of *src, a valid strview_t of length 0 is returned. - The returned characters are removed (popped) from *strview_ptr + The returned characters are removed (popped) from *src + + If src is NULL, *src is invalid, or pos is not a valid reference, an invalid string is returned and src is unmodified.*/ + strview_t strview_split_left(strview_t* src, strview_t pos); - If strview_ptr is NULL, *strview_ptr is invalid, or pos is not a valid reference, an invalid string is returned and strview_ptr is unmodified. -*/ - strview_t strview_split_left(strview_t* strview_ptr, strview_t pos); /* Split a strview_t at a position specified by pos - If pos references characters within *strview_ptr, return a strview_t representing all characters to the right of pos. - If the upper limit of pos matches the upper limit of *strview_ptr, a valid strview_t of length 0 is returned. + If pos references characters within *src, return a strview_t representing all characters to the right of pos. + If the upper limit of pos matches the upper limit of *src, a valid strview_t of length 0 is returned. - The returned characters are removed (popped) from *strview_ptr + The returned characters are removed (popped) from *src - If strview_ptr is NULL, *strview_ptr is invalid, or pos is not a valid reference, an invalid string is returned and strview_ptr is unmodified. -*/ - strview_t strview_split_right(strview_t* strview_ptr, strview_t pos); + If src is NULL, *src is invalid, or pos is not a valid reference, an invalid string is returned and src is unmodified.*/ + strview_t strview_split_right(strview_t* src, strview_t pos); /* Return the first char of str, and remove it from the str. Returns 0 if there are no characters in str. @@ -157,7 +156,7 @@ strview_split_index(&str, 1).data[0] Only it avoids dereferencing a NULL pointer in the case where strview_split_index() returns an invalid str. */ - char strview_pop_first_char(strview_t* strview_ptr); + char strview_pop_first_char(strview_t* src); /* @@ -174,7 +173,7 @@ This variable stores the state of the eol discriminator, regarding if a future CR or LF needs to be ignored. It's initial value should be 0. */ - strview_t strview_split_line(strview_t* strview_ptr, char* eol); + strview_t strview_split_line(strview_t* src, char* eol); #endif diff --git a/test/build_date.inc b/test/build_date.inc index d42ec18..5a96b97 100644 --- a/test/build_date.inc +++ b/test/build_date.inc @@ -1 +1 @@ -"2023-03-12T06:11:51+00:00" +"2023-03-13T05:21:48+00:00" diff --git a/test/build_number.inc b/test/build_number.inc index 4b1e299..103a99d 100644 --- a/test/build_number.inc +++ b/test/build_number.inc @@ -1 +1 @@ -603 +604