Comment

Comment by kazinator

> 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.

parent kazinator 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton