blob: 5168c7fd9834153e9168a138a3149af14057df70 (
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
|
#include <stdbool.h>
#include "warp-buf.h"
void
warp_buf_clear(
warp_buf_t * const buf
) {
buf->len = 0;
buf->dst = 0;
}
bool
warp_buf_has_num(
const warp_buf_t * const buf
) {
return buf->len > 0;
}
void
warp_buf_push_num(
warp_buf_t * const buf,
const size_t num
) {
buf->dst = buf->dst * 10 + num;
buf->len++;
}
void
warp_buf_pop_num(
warp_buf_t * const buf
) {
if (buf->len > 0) {
buf->len--;
buf->dst /= 10;
}
}
bool
warp_buf_get(
const warp_buf_t * const buf,
size_t * const r
) {
if (!buf->len) {
return false;
}
if (r) {
*r = buf->dst;
}
return true;
}
|