diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-01-24 21:35:03 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-01-24 21:39:07 -0800 |
commit | 829b089c80895d9a78938c5bc7747aea1cd48eb6 (patch) | |
tree | 53bd534741a90c547c5d87039efa5ee625da8081 /src/chunk.h | |
parent | 5ef31853d5161d4b5a2dfc0df94e6eaaeb3215d0 (diff) |
Removed implementation-specific material from repository.
The C and JS implementations are being split off into
different repositories.
This repository will just have the spec itself.
Diffstat (limited to 'src/chunk.h')
-rw-r--r-- | src/chunk.h | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/src/chunk.h b/src/chunk.h deleted file mode 100644 index 54c4b16..0000000 --- a/src/chunk.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef CMARK_CHUNK_H -#define CMARK_CHUNK_H - -#include <string.h> -#include <stdlib.h> -#include <assert.h> -#include "cmark_ctype.h" -#include "buffer.h" - -typedef struct { - unsigned char *data; - int len; - int alloc; // also implies a NULL-terminated string -} cmark_chunk; - -static inline void cmark_chunk_free(cmark_chunk *c) -{ - if (c->alloc) - free(c->data); - - c->data = NULL; - c->alloc = 0; - c->len = 0; -} - -static inline void cmark_chunk_ltrim(cmark_chunk *c) -{ - assert(!c->alloc); - - while (c->len && cmark_isspace(c->data[0])) { - c->data++; - c->len--; - } -} - -static inline void cmark_chunk_rtrim(cmark_chunk *c) -{ - while (c->len > 0) { - if (!cmark_isspace(c->data[c->len - 1])) - break; - - c->len--; - } -} - -static inline void cmark_chunk_trim(cmark_chunk *c) -{ - cmark_chunk_ltrim(c); - cmark_chunk_rtrim(c); -} - -static inline int cmark_chunk_strchr(cmark_chunk *ch, int c, int offset) -{ - const unsigned char *p = (unsigned char *)memchr(ch->data + offset, c, ch->len - offset); - return p ? (int)(p - ch->data) : ch->len; -} - -static inline const char *cmark_chunk_to_cstr(cmark_chunk *c) -{ - unsigned char *str; - - if (c->alloc) { - return (char *)c->data; - } - str = (unsigned char *)malloc(c->len + 1); - if(str != NULL) { - memcpy(str, c->data, c->len); - str[c->len] = 0; - } - c->data = str; - c->alloc = 1; - - return (char *)str; -} - -static inline void cmark_chunk_set_cstr(cmark_chunk *c, const char *str) -{ - if (c->alloc) { - free(c->data); - } - c->len = strlen(str); - c->data = (unsigned char *)malloc(c->len + 1); - c->alloc = 1; - memcpy(c->data, str, c->len + 1); -} - -static inline cmark_chunk cmark_chunk_literal(const char *data) -{ - cmark_chunk c = {(unsigned char *)data, data ? strlen(data) : 0, 0}; - return c; -} - -static inline cmark_chunk cmark_chunk_dup(const cmark_chunk *ch, int pos, int len) -{ - cmark_chunk c = {ch->data + pos, len, 0}; - return c; -} - -static inline cmark_chunk cmark_chunk_buf_detach(cmark_strbuf *buf) -{ - cmark_chunk c; - - c.len = buf->size; - c.data = cmark_strbuf_detach(buf); - c.alloc = 1; - - return c; -} - -#endif |