cmark

My personal build of CMark ✏️

buffer.h (2395B)

 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
13 extern "C" {
14 #endif
15 
16 typedef int32_t bufsize_t;
17 
18 typedef struct {
19   cmark_mem *mem;
20   unsigned char *ptr;
21   bufsize_t asize, size;
22 } cmark_strbuf;
23 
24 extern 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  */
35 void 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  */
41 void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size);
42 
43 void cmark_strbuf_free(cmark_strbuf *buf);
44 void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b);
45 
46 bufsize_t cmark_strbuf_len(const cmark_strbuf *buf);
47 
48 int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b);
49 
50 unsigned char *cmark_strbuf_detach(cmark_strbuf *buf);
51 void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize,
52                             const cmark_strbuf *buf);
53 
54 /*
55 static 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 
62 void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data,
63                       bufsize_t len);
64 void cmark_strbuf_sets(cmark_strbuf *buf, const char *string);
65 void cmark_strbuf_putc(cmark_strbuf *buf, int c);
66 void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data,
67                       bufsize_t len);
68 void cmark_strbuf_puts(cmark_strbuf *buf, const char *string);
69 void cmark_strbuf_clear(cmark_strbuf *buf);
70 
71 bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos);
72 bufsize_t cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, bufsize_t pos);
73 void cmark_strbuf_drop(cmark_strbuf *buf, bufsize_t n);
74 void cmark_strbuf_truncate(cmark_strbuf *buf, bufsize_t len);
75 void cmark_strbuf_rtrim(cmark_strbuf *buf);
76 void cmark_strbuf_trim(cmark_strbuf *buf);
77 void cmark_strbuf_normalize_whitespace(cmark_strbuf *s);
78 void cmark_strbuf_unescape(cmark_strbuf *s);
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif