]> git.ipfire.org Git - thirdparty/git.git/commit
t/helper/test-json-writer.c: avoid using `strtok()`
authorTaylor Blau <me@ttaylorr.com>
Mon, 24 Apr 2023 22:20:23 +0000 (18:20 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Apr 2023 23:01:28 +0000 (16:01 -0700)
commita2742f8c59dae6ef55895933e0950d61b6d03720
treeee75dbcaa19fed701e820fb0b9a59be716169a36
parentdeeabc1ff07fed102e90f9037aed749b16abd9a6
t/helper/test-json-writer.c: avoid using `strtok()`

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/helper/test-json-writer.c