cmark
My personal build of CMark ✏️
chunk.h (1816B)
1 #ifndef CMARK_CHUNK_H 2 #define CMARK_CHUNK_H 3 4 #include <string.h> 5 #include <stdlib.h> 6 #include <assert.h> 7 #include "cmark.h" 8 #include "buffer.h" 9 #include "cmark_ctype.h" 10 11 #define CMARK_CHUNK_EMPTY \ 12 { NULL, 0 } 13 14 typedef struct { 15 const unsigned char *data; 16 bufsize_t len; 17 } cmark_chunk; 18 19 // NOLINTNEXTLINE(clang-diagnostic-unused-function) 20 static CMARK_INLINE void cmark_chunk_free(cmark_chunk *c) { 21 c->data = NULL; 22 c->len = 0; 23 } 24 25 static CMARK_INLINE void cmark_chunk_ltrim(cmark_chunk *c) { 26 while (c->len && cmark_isspace(c->data[0])) { 27 c->data++; 28 c->len--; 29 } 30 } 31 32 static CMARK_INLINE void cmark_chunk_rtrim(cmark_chunk *c) { 33 while (c->len > 0) { 34 if (!cmark_isspace(c->data[c->len - 1])) 35 break; 36 37 c->len--; 38 } 39 } 40 41 // NOLINTNEXTLINE(clang-diagnostic-unused-function) 42 static CMARK_INLINE void cmark_chunk_trim(cmark_chunk *c) { 43 cmark_chunk_ltrim(c); 44 cmark_chunk_rtrim(c); 45 } 46 47 // NOLINTNEXTLINE(clang-diagnostic-unused-function) 48 static CMARK_INLINE bufsize_t cmark_chunk_strchr(cmark_chunk *ch, int c, 49 bufsize_t offset) { 50 const unsigned char *p = 51 (unsigned char *)memchr(ch->data + offset, c, ch->len - offset); 52 return p ? (bufsize_t)(p - ch->data) : ch->len; 53 } 54 55 // NOLINTNEXTLINE(clang-diagnostic-unused-function) 56 static CMARK_INLINE cmark_chunk cmark_chunk_literal(const char *data) { 57 bufsize_t len = data ? (bufsize_t)strlen(data) : 0; 58 cmark_chunk c = {(unsigned char *)data, len}; 59 return c; 60 } 61 62 // NOLINTNEXTLINE(clang-diagnostic-unused-function) 63 static CMARK_INLINE cmark_chunk cmark_chunk_dup(const cmark_chunk *ch, 64 bufsize_t pos, bufsize_t len) { 65 cmark_chunk c = {ch->data + pos, len}; 66 return c; 67 } 68 69 #endif