3 ms·
> Attempting to split a string using non-existent delimiter with str_pop_first_split() [returns an invalid string with .data == NULL]. But that seems like a va
by kazinator 4y ago
> Attempting to split a string using non-existent delimiter with str_pop_first_split() [returns an invalid string with .data == NULL].
But that seems like a valid case: e.g. these are comma-delimited lists of numbers:
"" // empty
"1" // one number
"20,30" // two numbers
the above remark in the documentation seems to be saying (perhaps falsely) that if we try to extract a token from the "1" string using "," as a delimiter, we get an invalid str_t rather than "1".
I don't see coverage for this in the tests. There is a test which uses "123/456/789", which extracts the first two splits, and then just verifies that "789" remains. What the programmer wants is to be able to write a loop which will extract "123", "456" and "789" and then* hit the terminating case where the invalid str_t is returned.
How many items are in "1,2,3," viewed as comma-separated: three or four?
It would also be a code improvement to replace umpteen repetitions of "(str_t){.data = NULL, .size = 0}" throughout the code with a macro.
- mickjc750 4y agoThat is a good point... Perhaps str_pop_first_split() should pop, even if no delimiters are found. I'll give this some thought. I'll put that macro in too. Thanks.
- mickjc750 4y agoThank you kazinator! I quickly realised you were right about this. It's now fixed. I may have posted this project a little early, but on the other hand it's great to get others input and read all this discussion.