summaryrefslogtreecommitdiff
path: root/source/kit/input_buffer.h
blob: 4320ee73b04e0d6bf8a73ed13d6c816c14e09b56 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef KIT_INPUT_BUFFER_H
#define KIT_INPUT_BUFFER_H

#include "string_builder.h"
#include "input_stream.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
  kit_is_handle_t   upstream;
  kit_str_builder_t data;
} kit_input_buffer_t;

typedef struct {
  s32                 status;
  i64                 offset;
  i64                 size;
  kit_input_buffer_t *buffer;
} kit_ib_token_t;

typedef b8 (*kit_ib_read_condition_fn)(kit_str_t data, void *context);

kit_input_buffer_t kit_ib_wrap(kit_is_handle_t  upstream,
                               kit_allocator_t *alloc);

void kit_ib_destroy(kit_input_buffer_t *buf);

kit_ib_token_t kit_ib_token(kit_input_buffer_t *buf);

kit_str_t kit_ib_str(kit_ib_token_t tok);

kit_ib_token_t kit_ib_read(kit_ib_token_t tok, i64 size);

kit_ib_token_t kit_ib_any(kit_ib_token_t tok, kit_str_t data);

kit_ib_token_t kit_ib_none(kit_ib_token_t tok, kit_str_t data);

kit_ib_token_t kit_ib_exact(kit_ib_token_t tok, kit_str_t data);

kit_ib_token_t kit_ib_until(kit_ib_token_t tok, kit_str_t data);

kit_ib_token_t kit_ib_while(kit_ib_token_t           buf,
                            kit_ib_read_condition_fn condition,
                            void                    *context);

#define KIT_IB_SKIP(buf_, proc_, ...)                      \
  do {                                                     \
    kit_ib_token_t temp_buf_ = (buf_);                     \
    (buf_)                   = proc_((buf_), __VA_ARGS__); \
  } while (0)

#ifdef __cplusplus
}
#endif

#define input_buffer_t kit_input_buffer_t
#define ib_token_t kit_ib_token_t
#define ib_read_condition_fn kit_ib_read_condition_fn
#define ib_wrap kit_ib_wrap
#define ib_destroy kit_ib_destroy
#define ib_token kit_ib_token
#define ib_str kit_ib_str
#define ib_read kit_ib_read
#define ib_any kit_ib_any
#define ib_none kit_ib_none
#define ib_exact kit_ib_exact
#define ib_until kit_ib_until
#define ib_while kit_ib_while
#define IB_SKIP KIT_IB_SKIP

#endif