summaryrefslogtreecommitdiff
path: root/src/parse.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-07-14 14:37:07 +0200
committerPatrick Steinhardt <ps@pks.im>2017-11-11 17:06:23 +0000
commite72cb769f6b8c11344463a9784fd4d32ded4a685 (patch)
treea7802281a702affe81998c0f31530777f854fdf9 /src/parse.c
parent252f2eeee0ecc90e5ae21efeadaccc9da666b845 (diff)
downloadlibgit2-e72cb769f6b8c11344463a9784fd4d32ded4a685.tar.gz
parse: implement `git_parse_peek`
Some code parts need to inspect the next few bytes without actually consuming it yet, for example to examine what content it has to expect next. Create a new function `git_parse_peek` which returns the next byte without modifying the parsing context and use it at multiple call sites.
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/parse.c b/src/parse.c
index 57da1c3cf..c1bd213ec 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -94,3 +94,25 @@ int git_parse_advance_digit(int64_t *out, git_parse_ctx *ctx, int base)
git_parse_advance_chars(ctx, (end - ctx->line));
return 0;
}
+
+int git_parse_peek(char *out, git_parse_ctx *ctx, int flags)
+{
+ size_t remain = ctx->line_len;
+ const char *ptr = ctx->line;
+
+ while (remain) {
+ char c = *ptr;
+
+ if ((flags & GIT_PARSE_PEEK_SKIP_WHITESPACE) &&
+ git__isspace(c)) {
+ remain--;
+ ptr++;
+ continue;
+ }
+
+ *out = c;
+ return 0;
+ }
+
+ return -1;
+}