Skip to content

Commit

Permalink
minor renaming and doc fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mickjc750 committed Mar 13, 2023
1 parent 0921f32 commit 1041bfe
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
42 changes: 21 additions & 21 deletions docs/strview-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -215,24 +215,24 @@ 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:

strview_split_index(&str, 1).data[0]
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.
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_allocator/build_date.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"2023-03-12T06:10:38+00:00"
"2023-03-13T05:20:51+00:00"
2 changes: 1 addition & 1 deletion examples/custom_allocator/build_number.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13
14
2 changes: 1 addition & 1 deletion examples/parse-uri/build_date.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"2023-03-12T06:10:55+00:00"
"2023-03-13T05:21:15+00:00"
2 changes: 1 addition & 1 deletion examples/parse-uri/build_number.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17
18
2 changes: 1 addition & 1 deletion examples/testnum/build_date.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"2023-03-12T06:11:06+00:00"
"2023-03-13T05:21:29+00:00"
2 changes: 1 addition & 1 deletion examples/testnum/build_number.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
573
574
39 changes: 19 additions & 20 deletions strview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -126,38 +126,37 @@
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.
If str is known to contain at least one character, it is the equivalent of:
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);


/*
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/build_date.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"2023-03-12T06:11:51+00:00"
"2023-03-13T05:21:48+00:00"
2 changes: 1 addition & 1 deletion test/build_number.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
603
604

0 comments on commit 1041bfe

Please sign in to comment.