File: parse.h

package info (click to toggle)
libgit2 0.27.7%2Bdfsg.1-0.2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 31,400 kB
  • sloc: ansic: 157,824; sh: 406; python: 182; php: 65; makefile: 61
file content (61 lines) | stat: -rw-r--r-- 1,635 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright (C) the libgit2 contributors. All rights reserved.
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
#ifndef INCLUDE_parse_h__
#define INCLUDE_parse_h__

#include "common.h"

typedef struct {
	/* Original content buffer */
	const char *content;
	size_t content_len;

	/* The remaining (unparsed) buffer */
	const char *remain;
	size_t remain_len;

	const char *line;
	size_t line_len;
	size_t line_num;
} git_parse_ctx;

int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len);
void git_parse_ctx_clear(git_parse_ctx *ctx);

#define git_parse_err(...) \
	( giterr_set(GITERR_PATCH, __VA_ARGS__), -1 )

#define git_parse_ctx_contains_s(ctx, str) \
	git_parse_ctx_contains(ctx, str, sizeof(str) - 1)

GIT_INLINE(bool) git_parse_ctx_contains(
	git_parse_ctx *ctx, const char *str, size_t len)
{
	return (ctx->line_len >= len && memcmp(ctx->line, str, len) == 0);
}

void git_parse_advance_line(git_parse_ctx *ctx);
void git_parse_advance_chars(git_parse_ctx *ctx, size_t char_cnt);
int git_parse_advance_expected(
	git_parse_ctx *ctx,
	const char *expected,
	size_t expected_len);

#define git_parse_advance_expected_str(ctx, str) \
	git_parse_advance_expected(ctx, str, strlen(str))

int git_parse_advance_ws(git_parse_ctx *ctx);
int git_parse_advance_nl(git_parse_ctx *ctx);
int git_parse_advance_digit(int64_t *out, git_parse_ctx *ctx, int base);

enum GIT_PARSE_PEEK_FLAGS {
	GIT_PARSE_PEEK_SKIP_WHITESPACE = (1 << 0)
};

int git_parse_peek(char *out, git_parse_ctx *ctx, int flags);

#endif