Re: [PATCH v3 5/6] t/helper/test-json-writer.c: avoid using `strtok()`
- From
- Jeff Hostetler <git@jeffhostetler.com>
- Date
- Apr 25, 2023, 13:57 UTC
- Message-ID
- <e7dba6a6-b0dd-061d-ee94-06c66f955c0f@jeffhostetler.com>
- In-Reply-To
- <201fcac6c41a80df78e58edd0d4dfda5f3944b8a.1682374789.git.me@ttaylorr.com>
On 4/24/23 6:20 PM, Taylor Blau wrote:
Show 23 quoted lines
> Apply similar treatment as in the previous commit to remove usage of > `strtok()` from the "oidmap" test helper. > > Each of the different commands that the "json-writer" helper accepts > pops the next space-delimited token from the current line and interprets > it as a string, integer, or double (with the exception of the very first > token, which is the command itself). > > To accommodate this, split the line in place by the space character, and > pass the corresponding string_list to each of the specialized `get_s()`, > `get_i()`, and `get_d()` functions. > > `get_i()` and `get_d()` are thin wrappers around `get_s()` that convert > their result into the appropriate type by either calling `strtol()` or > `strtod()`, respectively. In `get_s()`, we mark the token as "consumed" > by incrementing the `consumed_nr` counter, indicating how many tokens we > have read up to that point. > > Because each of these functions needs the string-list parts, the number > of tokens consumed, and the line number, these three are wrapped up in > to a struct representing the line state. > > Signed-off-by: Taylor Blau <me@ttaylorr.com>
LGTM
Thanks, Jeff