summaryrefslogtreecommitdiff
path: root/src/parse.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-07-14 13:45:05 +0200
committerPatrick Steinhardt <ps@pks.im>2017-11-11 17:06:23 +0000
commit252f2eeee0ecc90e5ae21efeadaccc9da666b845 (patch)
tree9993e41928de4d293c2fff3d271ce81b83e6ccde /src/parse.c
parent65dcb6453457fee640fe62008f9a395de58fd39a (diff)
downloadlibgit2-252f2eeee0ecc90e5ae21efeadaccc9da666b845.tar.gz
parse: implement and use `git_parse_advance_digit`
The patch parsing code has multiple recurring patterns where we want to parse an actual number. Create a new function `git_parse_advance_digit` and use it to avoid code duplication.
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/parse.c b/src/parse.c
index f7365ef8d..57da1c3cf 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -79,3 +79,18 @@ int git_parse_advance_nl(git_parse_ctx *ctx)
git_parse_advance_line(ctx);
return 0;
}
+
+int git_parse_advance_digit(int64_t *out, git_parse_ctx *ctx, int base)
+{
+ const char *end;
+ int ret;
+
+ if (ctx->line_len < 1 || !git__isdigit(ctx->line[0]))
+ return -1;
+
+ if ((ret = git__strntol64(out, ctx->line, ctx->line_len, &end, base)) < 0)
+ return -1;
+
+ git_parse_advance_chars(ctx, (end - ctx->line));
+ return 0;
+}