]>
Commit | Line | Data |
---|---|---|
eae0bfdc PP |
1 | /* |
2 | * Copyright (C) the libgit2 contributors. All rights reserved. | |
3 | * | |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with | |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
6 | */ | |
7 | #ifndef INCLUDE_parse_h__ | |
8 | #define INCLUDE_parse_h__ | |
9 | ||
10 | #include "common.h" | |
11 | ||
12 | typedef struct { | |
13 | /* Original content buffer */ | |
14 | const char *content; | |
15 | size_t content_len; | |
16 | ||
17 | /* The remaining (unparsed) buffer */ | |
18 | const char *remain; | |
19 | size_t remain_len; | |
20 | ||
21 | const char *line; | |
22 | size_t line_len; | |
23 | size_t line_num; | |
24 | } git_parse_ctx; | |
25 | ||
26 | int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len); | |
27 | void git_parse_ctx_clear(git_parse_ctx *ctx); | |
28 | ||
29 | #define git_parse_err(...) \ | |
ac3d33df | 30 | ( git_error_set(GIT_ERROR_PATCH, __VA_ARGS__), -1 ) |
eae0bfdc PP |
31 | |
32 | #define git_parse_ctx_contains_s(ctx, str) \ | |
33 | git_parse_ctx_contains(ctx, str, sizeof(str) - 1) | |
34 | ||
35 | GIT_INLINE(bool) git_parse_ctx_contains( | |
36 | git_parse_ctx *ctx, const char *str, size_t len) | |
37 | { | |
38 | return (ctx->line_len >= len && memcmp(ctx->line, str, len) == 0); | |
39 | } | |
40 | ||
41 | void git_parse_advance_line(git_parse_ctx *ctx); | |
42 | void git_parse_advance_chars(git_parse_ctx *ctx, size_t char_cnt); | |
43 | int git_parse_advance_expected( | |
44 | git_parse_ctx *ctx, | |
45 | const char *expected, | |
46 | size_t expected_len); | |
47 | ||
48 | #define git_parse_advance_expected_str(ctx, str) \ | |
49 | git_parse_advance_expected(ctx, str, strlen(str)) | |
50 | ||
51 | int git_parse_advance_ws(git_parse_ctx *ctx); | |
52 | int git_parse_advance_nl(git_parse_ctx *ctx); | |
53 | int git_parse_advance_digit(int64_t *out, git_parse_ctx *ctx, int base); | |
54 | ||
55 | enum GIT_PARSE_PEEK_FLAGS { | |
56 | GIT_PARSE_PEEK_SKIP_WHITESPACE = (1 << 0) | |
57 | }; | |
58 | ||
59 | int git_parse_peek(char *out, git_parse_ctx *ctx, int flags); | |
60 | ||
61 | #endif |