pub unsafe extern "C" fn aws_byte_cursor_next_split(
input_str: *const aws_byte_cursor,
split_on: c_char,
substr: *mut aws_byte_cursor
) -> bool
Expand description
No copies, no buffer allocations. Iterates over input_str, and returns the next substring between split_on instances relative to previous substr. Behaves similar to strtok with substr being used as state for next split.
Returns true each time substr is set and false when there is no more splits (substr is set to empty in that case).
Example usage. struct aws_byte_cursor substr = {0}; while (aws_byte_cursor_next_split(&input_str, ‘;’, &substr)) { // …use substr… }
Note: It is the user’s responsibility zero-initialize substr before the first call.
Edge case rules are as follows: empty input will have single empty split. ex. “” splits into “” if input starts with split_on then first split is empty. ex “;A” splits into “”, “A” adjacent split tokens result in empty split. ex “A;;B” splits into “A”, “”, “B” If the input ends with split_on, last split is empty. ex. “A;” splits into “A”, “”
It is the user’s responsibility to make sure the input buffer stays in memory long enough to use the results.