1#ifndef CMARK_BUFFER_H
2#define CMARK_BUFFER_H
3
4#include <stddef.h>
5#include <stdarg.h>
6#include <string.h>
7#include <limits.h>
8#include <stdint.h>
9#include "config.h"
10#include "cmark.h"
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16typedef int32_t bufsize_t;
17
18typedef struct {
19 cmark_mem *mem;
20 unsigned char *ptr;
21 bufsize_t asize, size;
22} cmark_strbuf;
23
24extern unsigned char cmark_strbuf__initbuf[];
25
26#define CMARK_BUF_INIT(mem) \
27 { mem, cmark_strbuf__initbuf, 0, 0 }
28
29/**
30 * Initialize a cmark_strbuf structure.
31 *
32 * For the cases where CMARK_BUF_INIT cannot be used to do static
33 * initialization.
34 */
35void cmark_strbuf_init(cmark_mem *mem, cmark_strbuf *buf,
36 bufsize_t initial_size);
37
38/**
39 * Grow the buffer to hold at least `target_size` bytes.
40 */
41void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size);
42
43void cmark_strbuf_free(cmark_strbuf *buf);
44void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b);
45
46bufsize_t cmark_strbuf_len(const cmark_strbuf *buf);
47
48int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b);
49
50unsigned char *cmark_strbuf_detach(cmark_strbuf *buf);
51void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize,
52 const cmark_strbuf *buf);
53
54/*
55static CMARK_INLINE const char *cmark_strbuf_cstr(const cmark_strbuf *buf) {
56 return (char *)buf->ptr;
57}
58*/
59
60#define cmark_strbuf_at(buf, n) ((buf)->ptr[n])
61
62void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data,
63 bufsize_t len);
64void cmark_strbuf_sets(cmark_strbuf *buf, const char *string);
65void cmark_strbuf_putc(cmark_strbuf *buf, int c);
66void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data,
67 bufsize_t len);
68void cmark_strbuf_puts(cmark_strbuf *buf, const char *string);
69void cmark_strbuf_clear(cmark_strbuf *buf);
70
71bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos);
72bufsize_t cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, bufsize_t pos);
73void cmark_strbuf_drop(cmark_strbuf *buf, bufsize_t n);
74void cmark_strbuf_truncate(cmark_strbuf *buf, bufsize_t len);
75void cmark_strbuf_rtrim(cmark_strbuf *buf);
76void cmark_strbuf_trim(cmark_strbuf *buf);
77void cmark_strbuf_normalize_whitespace(cmark_strbuf *s);
78void cmark_strbuf_unescape(cmark_strbuf *s);
79
80#ifdef __cplusplus
81}
82#endif
83
84#endif
85