c0
C0DATA — structured data using ASCII C0 control codes (C)
Loading...
Searching...
No Matches
c0.h File Reference
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  c0_bytes
 A zero-copy view into a buffer: not NUL-terminated. More...
struct  c0_error
 Error detail: the code, the byte offset it was found at, and a static message. More...
struct  c0_body
 A body: a document body or the inside of a nested level, as a range of the buffer. More...
struct  c0_ref
 A parsed reference (DESIGN.md "References"): a group name written plain, or a pattern, the level ENQ DLE … CAN that is one branch of the target with its values left out, reported as the body it is written as. More...
struct  c0_record
 A record: the bytes after its RS, trailing layout excluded. More...
struct  c0_unit_iter
 Cursor over the positional units of a record, or the items of a list. More...
struct  c0_unit
 A unit with its sub-units (DESIGN.md "Subordinates"): SUB before US makes the unit after a child of the unit before, ␞a␟b␚␟c is two units and b holds c; ␞a␚␟b␚␟c is a holding b and c; ␞a␚␟b␚␚␟c is a holding b holding c (the SUB run's length is the depth). More...
struct  c0_sub_iter
 Cursor over the direct sub-units of a unit (those one deeper than it), in written order; each comes with its own sub-units. More...
struct  c0_pair_iter
 Cursor over keyed units (a keyed record, or a document heading). More...
struct  c0_file
 A file within a body: its name and the range of its contents. More...
struct  c0_group
 A group: its depth (one plus the SUB prefix of its GS line: ␝a 1, ␚␝b 2; 0 for the unnamed group at the start of a file or level), name, and the range of its contents (header row and records; deeper subsections are separate groups). More...
struct  c0_file_iter
 Cursor over the files of a body as the result model has them. More...
struct  c0_group_iter
 Cursor over groups: every GS line at any depth, in order, plus the unnamed leading group of a file or level when it holds a header row or records. More...
struct  c0_record_iter
 Cursor over the live records of a group (header rows, notes, commits and dead records skipped). More...
struct  c0_document
 One document: an optional SYN heading, a body, an optional EOT. More...
struct  c0_doc_iter
 Cursor over the documents of a container (a file or message): each begins with SYN except possibly the first; EM ends the scan and starts the tail. More...
struct  c0_builder
 Writes C0DATA in canonical compact form into a growable buffer it owns; call c0_builder_free when done. More...
struct  c0_parse_state
 Parser state carried from one committed block to the next (every field is internal). More...
struct  c0_stream
 A scan of an append-only log. More...
struct  c0_block_iter
 Cursor over the committed blocks (previous commit to ETB, marker and payload excluded); *damaged is set for a block that is not well-formed in the context of the sound blocks before it. More...

Macros

#define C0_VERSION   "0.2.0"
#define C0_SOH   0x01
 Heading: a key for the value after it; SOH RS a header row.
#define C0_STX   0x02
 Start of text (a literal value).
#define C0_ETX   0x03
 End of text.
#define C0_EOT   0x04
 End of document.
#define C0_ENQ   0x05
 Reference: a group name, or a pattern (ENQ DLE … CAN).
#define C0_BEL   0x07
 Comment: a note, or marks the next element dead.
#define C0_DLE   0x10
 Recurse (opens a nested level) outside text; escape inside.
#define C0_SYN   0x16
 Start of document, then the heading.
#define C0_ETB   0x17
 Commit marker (stream mode).
#define C0_CAN   0x18
 Close a nested level.
#define C0_EM   0x19
 End of medium: a raw blob follows.
#define C0_SUB   0x1a
 Subordinate: the element after is a child of the element before (GS: subsection, US: sub-unit).
#define C0_FS   0x1c
 File separator.
#define C0_GS   0x1d
 Group separator.
#define C0_RS   0x1e
 Record separator.
#define C0_US   0x1f
 Unit separator.
#define C0_HT   0x09
#define C0_LF   0x0a
#define C0_CR   0x0d
#define C0_SP   0x20
#define C0_WARN_NO_SYN   0x01u
 Loud warnings a document reader raises (DESIGN.md "Warnings"), as bits.
#define C0_WARN_NO_EOT   0x02u
 no EOT and the shape is not stream
#define C0_WARN_UNKNOWN_KEY   0x04u
 a heading key the reader does not know
#define C0_WARN_DUPLICATE_KEY   0x08u
 a duplicate heading key (last wins)
#define C0_WARN_UNKNOWN_SHAPE   0x10u
 a shape other than diff or stream
#define C0_WARN_UNKNOWN_VERSION   0x20u
 a version other than 1

Enumerations

enum  c0_status {
  C0_OK = 0 , C0_ERR_SYNTAX , C0_ERR_UNASSIGNED , C0_ERR_UNEXPECTED_END ,
  C0_ERR_TOO_DEEP , C0_ERR_NOT_SCALAR , C0_ERR_NOT_LEVEL , C0_ERR_NOT_LIST ,
  C0_ERR_NOT_REFERENCE , C0_ERR_NEEDS_DECODE , C0_ERR_NOT_FOUND , C0_ERR_BAD_NAME ,
  C0_ERR_BAD_STATE , C0_ERR_OOM
}
 Status codes shared by every part of the library. More...
enum  c0_unit_kind { C0_UNIT_PLAIN = 0 , C0_UNIT_TEXT , C0_UNIT_LEVEL , C0_UNIT_REF }
 What a raw unit holds, by its first non-layout byte. More...
enum  c0_pretty_mode { C0_PRETTY_COMPACT = 0 , C0_PRETTY_ALIGNED , C0_PRETTY_SPACED }

Functions

int c0_is_assigned (uint8_t byte)
 Whether a byte is one of the sixteen assigned codes.
int c0_is_layout (uint8_t byte)
 Whether a byte is layout outside text (SP, HT, LF, CR).
int c0_is_text_escaped (uint8_t byte)
 Whether a byte is one of the seven codes that take a DLE inside text (STX ETX DLE ETB EOT SYN EM).
int c0_is_plain (const uint8_t *p, size_t len)
 Whether a value can be written plain: no byte below 0x20, no edge whitespace.
int c0_is_name (const uint8_t *p, size_t len)
 Whether bytes are a legal name (label, key, header name): same test as plain.
c0_bytes c0_bytes_of (const uint8_t *ptr, size_t len)
 A view over len bytes at ptr.
c0_bytes c0_trim (c0_bytes raw)
 Layout trimmed from both ends of a raw slice.
size_t c0_decode_text (const uint8_t *inside, size_t len, uint8_t *out)
 Decode the inside of a text (the bytes between STX and ETX): DLE escapes removed.
size_t c0_scan_layout (const uint8_t *buf, size_t pos, size_t stop)
 Skip layout bytes.
size_t c0_scan_plain (const uint8_t *buf, size_t pos, size_t stop)
 Skip a run of bytes >= 0x20 (a label, key, payload or plain value with its layout).
size_t c0_scan_text (const uint8_t *buf, size_t pos, size_t stop, c0_error *err)
 At an STX: the position after the matching ETX.
size_t c0_scan_level (const uint8_t *buf, size_t pos, size_t stop, c0_error *err)
 At a DLE: the position after the matching CAN.
size_t c0_scan_unit (const uint8_t *buf, size_t pos, size_t stop, c0_error *err)
 From just after a US (or a key's US): the end of the unit's value (its sub-units, SUB … US …, are not part of it).
size_t c0_scan_comment (const uint8_t *buf, size_t pos, size_t stop, c0_error *err)
 At a BEL: past the note, or past the whole dead element's own line.
size_t c0_scan_record_end (const uint8_t *buf, size_t pos, size_t stop, c0_error *err)
 From just after an RS: the end of the record (a sub-unit, a SUB run then US, stays inside; a SUB run before a line code ends it).
c0_status c0_validate (const uint8_t *buf, size_t len, c0_error *err)
 Check a whole buffer (one or more documents, an optional EM tail) against GRAMMAR.md.
int c0_canonical (const uint8_t *buf, size_t len)
 Whether bytes are a canonical span (GRAMMAR.md "Canonical constraints"): well-formed, no layout, one spelling per value, unique keys in each keyed record, no framing, no notes or dead elements.
c0_unit_kind c0_unit_type (c0_bytes raw)
c0_status c0_value (c0_bytes raw, uint8_t *scratch, c0_bytes *out)
 The logical value of a raw unit (as yielded by c0_next_unit, c0_next_pair, c0_record_field …): for a plain value the slice with edge layout removed; for text the inside with its escapes decoded; for a unit holding only a note or a dead level, the empty value.
c0_body c0_body_view (const uint8_t *buf, size_t len)
 A body over a whole buffer (a slice with no SYN: records, groups, files), unchecked: pair it with c0_validate, or use c0_body_read.
c0_status c0_body_read (const uint8_t *buf, size_t len, c0_body *out, c0_error *err)
 Parse a slice as a body (no SYN, heading or EOT): the grammar is applied to all of it; C0_OK and *out on success, else the first error.
c0_status c0_unit_level (c0_bytes raw, c0_body *out)
 A raw unit as a nested level: the body between its DLE and CAN.
c0_status c0_unit_ref (c0_bytes raw, c0_ref *out)
 A raw unit as a reference.
size_t c0_ref_path (const c0_ref *r, c0_bytes *steps, size_t max)
 The steps of a reference in walking order: the group name alone, or the pattern's file, group names, record id, field name and the inner pattern's steps (a keyed step contributes its key).
int c0_ref_group (const c0_ref *r, c0_bytes *name)
 Whether the reference names a group as a whole (a plain name, or a pattern that is a bare group line); *name gets the group's name.
int c0_record_keyed (c0_record r)
 Whether the record is keyed (it holds a keyed unit, live or dead).
c0_unit_iter c0_record_units (c0_record r)
 The record's positional units.
int c0_next_unit (c0_unit_iter *it, c0_bytes *raw)
int c0_next_unit_with_subs (c0_unit_iter *it, c0_unit *out)
 The next positional unit with its sub-units (the walk of c0_next_unit).
c0_status c0_record_unit (c0_record r, size_t n, c0_unit *out)
 Unit n (0-based) with its sub-units, or C0_ERR_NOT_FOUND.
c0_sub_iter c0_unit_subs (c0_unit u)
int c0_next_sub (c0_sub_iter *it, c0_unit *out)
size_t c0_unit_sub_count (c0_unit u)
 Number of direct sub-units.
size_t c0_record_count (c0_record r)
 Number of positional units.
c0_status c0_record_field (c0_record r, size_t n, c0_bytes *raw)
 Raw unit n (0-based), or C0_ERR_NOT_FOUND.
c0_pair_iter c0_record_pairs (c0_record r)
 Keyed units in written order, duplicates included, dead units skipped.
int c0_next_pair (c0_pair_iter *it, c0_bytes *key, c0_bytes *raw)
int c0_next_pair_with_subs (c0_pair_iter *it, c0_bytes *key, c0_unit *out)
 The same, the value as a unit with its sub-units.
c0_status c0_record_get (c0_record r, const uint8_t *key, size_t klen, c0_bytes *raw)
 Raw value for a key (last wins), or C0_ERR_NOT_FOUND.
c0_status c0_record_get_str (c0_record r, const char *key, c0_bytes *raw)
c0_status c0_record_unit_get (c0_record r, const uint8_t *key, size_t klen, c0_unit *out)
 The unit under a key with its sub-units (last wins), or C0_ERR_NOT_FOUND.
c0_status c0_record_unit_get_str (c0_record r, const char *key, c0_unit *out)
c0_status c0_unit_list (c0_bytes raw, c0_unit_iter *items)
 A raw unit as a flat list: a level holding at most one positional record.
c0_bytes c0_file_name (c0_file f)
c0_bytes c0_group_name (c0_group g)
c0_file_iter c0_body_files (c0_body b)
int c0_next_file (c0_file_iter *it, c0_file *out)
c0_group_iter c0_file_groups (c0_file f)
 Groups of one file.
c0_group_iter c0_body_groups (c0_body b)
 Groups of every file of a body, in order (FS lines are skipped).
int c0_next_group (c0_group_iter *it, c0_group *out)
c0_status c0_body_find_group (c0_body b, const uint8_t *name, size_t nlen, c0_group *out)
 First group with the given name in the body (any file), or C0_ERR_NOT_FOUND.
c0_status c0_body_find_group_str (c0_body b, const char *name, c0_group *out)
int c0_body_bare (c0_body b)
 Whether the body is a bare record stream: one unnamed file, at most the unnamed group.
int c0_group_header (c0_group g, c0_record *out)
 The group's header row as a record (its units are the header names).
c0_record_iter c0_group_records (c0_group g)
c0_record_iter c0_body_records (c0_body b)
 Records of a bare body (the unnamed group's).
int c0_next_record (c0_record_iter *it, c0_record *out)
c0_status c0_group_column (c0_group g, const uint8_t *name, size_t nlen, size_t *index)
 Index of a header name in the group's header row, or C0_ERR_NOT_FOUND.
c0_status c0_document_read (const uint8_t *buf, size_t len, size_t start, c0_document *out, c0_error *err)
 Read the document starting at start (after any layout), applying the whole grammar to it: C0_OK, or the first error.
c0_pair_iter c0_document_heading (const c0_document *d)
 The heading's keyed units, in written order (dead units skipped).
c0_status c0_heading_get (const c0_document *d, const uint8_t *key, size_t klen, c0_bytes *raw)
 Raw heading value for a key (last wins), or C0_ERR_NOT_FOUND.
c0_status c0_heading_get_str (const c0_document *d, const char *key, c0_bytes *raw)
c0_bytes c0_heading_shape (const c0_document *d)
 The shape value (decoded, must be plain), or an empty slice when absent.
int c0_heading_version (const c0_document *d)
 The version value as an integer; 1 when absent or not a number.
c0_status c0_heading_blob (const c0_document *d, c0_body *out)
 The blob table (a level) as a body, or C0_ERR_NOT_FOUND / C0_ERR_NOT_LEVEL.
c0_doc_iter c0_documents (const uint8_t *buf, size_t len)
int c0_next_document (c0_doc_iter *it, c0_document *out)
c0_bytes c0_doc_iter_tail (const c0_doc_iter *it)
 After the cursor is exhausted: the raw bytes after EM (empty without EM).
c0_status c0_container_tail (const uint8_t *buf, size_t len, c0_bytes *tail, int *has_em, c0_error *err)
 Scan the whole container: *tail gets the raw region after EM (empty when there is none, *has_em says which).
c0_status c0_blob (const uint8_t *buf, size_t len, const uint8_t *name, size_t nlen, c0_bytes *out, c0_error *err)
 The bytes of a named blob from the tail, located by the first document's blob table (columns matched by header name).
c0_status c0_blob_str (const uint8_t *buf, size_t len, const char *name, c0_bytes *out, c0_error *err)
void c0_builder_init (c0_builder *b)
void c0_builder_free (c0_builder *b)
c0_status c0_builder_status (const c0_builder *b)
c0_bytes c0_builder_bytes (const c0_builder *b)
void c0_builder_fs (c0_builder *b, const uint8_t *name, size_t nlen)
 FS name; ends any open record.
void c0_builder_gs (c0_builder *b)
 GS alone: an empty-named group (␝␝b is group "" then group b).
void c0_builder_gs_name (c0_builder *b, const uint8_t *name, size_t nlen)
 GS name; ends any open record.
void c0_builder_rs (c0_builder *b)
 RS: open a record.
void c0_builder_rs_value (c0_builder *b, const uint8_t *value, size_t vlen)
 RS and the record's first value.
void c0_builder_us (c0_builder *b)
 US alone (an empty unit, or before DLE / ENQ).
void c0_builder_us_value (c0_builder *b, const uint8_t *value, size_t vlen)
 US and the value that follows it.
void c0_builder_sub (c0_builder *b)
 SUB: the element after the next separator is subordinate to the one before (before GS depth, before US a sub-unit).
void c0_builder_soh (c0_builder *b)
 SOH alone: before RS, a header row.
void c0_builder_soh_name (c0_builder *b, const uint8_t *name, size_t nlen)
 SOH key.
void c0_builder_dle (c0_builder *b)
 DLE: open a level (saves the record state).
void c0_builder_can (c0_builder *b)
 CAN: close the innermost level; C0_ERR_BAD_STATE if none is open.
void c0_builder_bel (c0_builder *b)
 BEL alone: the element that follows is dead.
void c0_builder_bel_text (c0_builder *b, const uint8_t *text, size_t tlen)
 BEL and a note; empty text is C0_ERR_BAD_STATE.
void c0_builder_enq (c0_builder *b, const uint8_t *name, size_t nlen)
 ENQ name: a group reference.
void c0_builder_enq_dle (c0_builder *b)
 ENQ DLE: a pattern; write its lines, then c0_builder_can.
void c0_builder_syn (c0_builder *b)
 SYN; soh_name + us_value pairs that follow are the heading.
void c0_builder_eot (c0_builder *b)
 EOT.
void c0_builder_etb (c0_builder *b)
 ETB alone.
void c0_builder_etb_payload (c0_builder *b, const uint8_t *payload, size_t plen)
 ETB and a plain payload.
void c0_builder_em (c0_builder *b, const uint8_t *tail, size_t tlen)
 EM and the raw tail; nothing may follow.
void c0_builder_fs_str (c0_builder *b, const char *name)
void c0_builder_gs_str (c0_builder *b, const char *name)
void c0_builder_rs_str (c0_builder *b, const char *value)
void c0_builder_us_str (c0_builder *b, const char *value)
void c0_builder_soh_str (c0_builder *b, const char *name)
void c0_builder_bel_str (c0_builder *b, const char *text)
void c0_builder_enq_str (c0_builder *b, const char *name)
void c0_builder_etb_str (c0_builder *b, const char *payload)
void c0_builder_em_str (c0_builder *b, const char *tail)
void c0_build_syn (c0_builder *b)
 SYN; keyed units until the next element are the heading.
void c0_build_eot (c0_builder *b)
 EOT.
void c0_build_etb (c0_builder *b, const uint8_t *payload, size_t plen)
 ETB and an optional plain payload (NULL for none).
void c0_build_em (c0_builder *b, const uint8_t *tail, size_t tlen)
 EM and the raw tail; nothing may follow.
void c0_build_file (c0_builder *b, const uint8_t *name, size_t nlen)
 FS name.
void c0_build_group (c0_builder *b, const uint8_t *name, size_t nlen)
 GS name.
void c0_build_section (c0_builder *b, const uint8_t *name, size_t nlen, size_t depth)
 SUB×(depth−1) GS name: a group at depth (1 is a plain GS line).
void c0_build_header (c0_builder *b, const c0_bytes *names, size_t count)
 SOH RS name US name …
void c0_build_record (c0_builder *b, const c0_bytes *fields, size_t count)
 RS and count units; count 0 opens an empty record.
void c0_build_field (c0_builder *b, const uint8_t *value, size_t vlen)
 next unit of the open record (opens one if none)
void c0_build_sub_unit (c0_builder *b, const uint8_t *value, size_t vlen, size_t depth)
 SUB×depth US value: a sub-unit of the unit just written (depth 2: of the sub-unit before); not a unit of the record.
void c0_build_map (c0_builder *b, const c0_bytes *keys, const c0_bytes *values, size_t count)
 RS and keyed units in the order given.
void c0_build_key (c0_builder *b, const uint8_t *key, size_t klen, const uint8_t *value, size_t vlen)
 SOH key US value, in the open record or the heading.
void c0_build_level_open (c0_builder *b)
 DLE: a nested level as the next unit; inside, the builder is at the top of a fresh body.
void c0_build_key_level_open (c0_builder *b, const uint8_t *key, size_t klen)
 SOH key US DLE.
void c0_build_level_close (c0_builder *b)
 CAN.
void c0_build_list (c0_builder *b, const c0_bytes *items, size_t count)
 a flat list as the next unit: DLE RS item US item … CAN, or DLE CAN
void c0_build_ref (c0_builder *b, const uint8_t *name, size_t nlen)
 ENQ name as the next unit: a group reference.
void c0_build_ref_open (c0_builder *b)
 ENQ DLE as the next unit: a pattern; write its lines, then c0_build_level_close.
void c0_build_ref_record (c0_builder *b, const uint8_t *group, size_t glen, const uint8_t *record, size_t rlen, const uint8_t *field, size_t flen)
 ␅␐␝group␞record[␟field]␘ as the next unit (field NULL to omit)
void c0_build_note (c0_builder *b, const uint8_t *text, size_t tlen)
 BEL and the note (plain, or text when it must be).
void c0_build_block (c0_builder *b, const uint8_t *text, size_t tlen)
 a paragraph: a record of one unit
void c0_build_item (c0_builder *b, const uint8_t *text, size_t tlen)
 a list item: the next unit
void c0_build_etb_str (c0_builder *b, const char *payload)
void c0_build_file_str (c0_builder *b, const char *name)
void c0_build_group_str (c0_builder *b, const char *name)
void c0_build_section_str (c0_builder *b, const char *name, size_t depth)
void c0_build_header_str (c0_builder *b, const char *const *names, size_t count)
void c0_build_record_str (c0_builder *b, const char *const *fields, size_t count)
void c0_build_field_str (c0_builder *b, const char *value)
void c0_build_sub_unit_str (c0_builder *b, const char *value, size_t depth)
void c0_build_map_str (c0_builder *b, const char *const *keys, const char *const *values, size_t count)
void c0_build_key_str (c0_builder *b, const char *key, const char *value)
void c0_build_key_level_open_str (c0_builder *b, const char *key)
void c0_build_list_str (c0_builder *b, const char *const *items, size_t count)
void c0_build_ref_str (c0_builder *b, const char *name)
void c0_build_ref_record_str (c0_builder *b, const char *group, const char *record, const char *field)
void c0_build_note_str (c0_builder *b, const char *text)
void c0_build_block_str (c0_builder *b, const char *text)
void c0_build_item_str (c0_builder *b, const char *text)
c0_stream c0_stream_read (const uint8_t *buf, size_t len)
c0_bytes c0_stream_committed (const c0_stream *s)
c0_bytes c0_stream_tail (const c0_stream *s)
c0_block_iter c0_stream_blocks (const c0_stream *s)
int c0_next_block (c0_block_iter *it, c0_bytes *out, int *damaged)
size_t c0_stream_undamaged (const c0_stream *s, uint8_t *out)
 Copy the undamaged committed blocks, without their ETB markers and payloads, into out (room for committed_end bytes suffices), continuing past every damaged block.
size_t c0_stream_before_damage (const c0_stream *s, uint8_t *out)
 The same, stopping at the first damaged block: the default reading, which delivers the records before the damage; resume_offset says where to go on.
size_t c0_stream_last_commit_end (const uint8_t *buf, size_t len)
 Position just past the last commit, found by a backward scan (a shortcut for well-formed input; c0_stream_read is authoritative).
char * c0_pretty_format (const uint8_t *buf, size_t len, const char *indent, c0_pretty_mode mode, size_t *outlen, c0_error *err)
 Format compact bytes as pretty form: a malloc'd, NUL-terminated UTF-8 string the caller frees; *outlen (if not NULL) gets its length.
uint8_t * c0_pretty_parse (const char *str, size_t len, size_t *outlen)
 Parse pretty form back to compact bytes: glyphs become codes; outside text whitespace touching a glyph or a line edge is dropped.

Macro Definition Documentation

◆ C0_BEL

#define C0_BEL   0x07

Comment: a note, or marks the next element dead.

◆ C0_CAN

#define C0_CAN   0x18

Close a nested level.

◆ C0_CR

#define C0_CR   0x0d

◆ C0_DLE

#define C0_DLE   0x10

Recurse (opens a nested level) outside text; escape inside.

◆ C0_EM

#define C0_EM   0x19

End of medium: a raw blob follows.

◆ C0_ENQ

#define C0_ENQ   0x05

Reference: a group name, or a pattern (ENQ DLE … CAN).

◆ C0_EOT

#define C0_EOT   0x04

End of document.

◆ C0_ETB

#define C0_ETB   0x17

Commit marker (stream mode).

◆ C0_ETX

#define C0_ETX   0x03

End of text.

◆ C0_FS

#define C0_FS   0x1c

File separator.

◆ C0_GS

#define C0_GS   0x1d

Group separator.

◆ C0_HT

#define C0_HT   0x09

◆ C0_LF

#define C0_LF   0x0a

◆ C0_RS

#define C0_RS   0x1e

Record separator.

◆ C0_SOH

#define C0_SOH   0x01

Heading: a key for the value after it; SOH RS a header row.

◆ C0_SP

#define C0_SP   0x20

◆ C0_STX

#define C0_STX   0x02

Start of text (a literal value).

◆ C0_SUB

#define C0_SUB   0x1a

Subordinate: the element after is a child of the element before (GS: subsection, US: sub-unit).

◆ C0_SYN

#define C0_SYN   0x16

Start of document, then the heading.

◆ C0_US

#define C0_US   0x1f

Unit separator.

◆ C0_VERSION

#define C0_VERSION   "0.2.0"

◆ C0_WARN_DUPLICATE_KEY

#define C0_WARN_DUPLICATE_KEY   0x08u

a duplicate heading key (last wins)

◆ C0_WARN_NO_EOT

#define C0_WARN_NO_EOT   0x02u

no EOT and the shape is not stream

◆ C0_WARN_NO_SYN

#define C0_WARN_NO_SYN   0x01u

Loud warnings a document reader raises (DESIGN.md "Warnings"), as bits.

no SYN at the start

◆ C0_WARN_UNKNOWN_KEY

#define C0_WARN_UNKNOWN_KEY   0x04u

a heading key the reader does not know

◆ C0_WARN_UNKNOWN_SHAPE

#define C0_WARN_UNKNOWN_SHAPE   0x10u

a shape other than diff or stream

◆ C0_WARN_UNKNOWN_VERSION

#define C0_WARN_UNKNOWN_VERSION   0x20u

a version other than 1

Enumeration Type Documentation

◆ c0_pretty_mode

Enumerator
C0_PRETTY_COMPACT 

one element per line, no padding

C0_PRETTY_ALIGNED 

table columns aligned

C0_PRETTY_SPACED 

aligned, plus a space after each prefix and around ␟

◆ c0_status

enum c0_status

Status codes shared by every part of the library.

Enumerator
C0_OK 
C0_ERR_SYNTAX 

malformed input (see c0_error.msg / .pos)

C0_ERR_UNASSIGNED 

an unassigned control code outside text

C0_ERR_UNEXPECTED_END 

input ended inside text, a level, or after DLE/BEL

C0_ERR_TOO_DEEP 

nesting deeper than the parser's limit

C0_ERR_NOT_SCALAR 

c0_value on a level or reference

C0_ERR_NOT_LEVEL 

c0_unit_level on a unit that is not DLE … CAN

C0_ERR_NOT_LIST 

c0_unit_list on a level that is not a list

C0_ERR_NOT_REFERENCE 

c0_unit_ref on a unit that is not ENQ …

C0_ERR_NEEDS_DECODE 

c0_value without scratch on text with escapes

C0_ERR_NOT_FOUND 

no such group / key / field / blob

C0_ERR_BAD_NAME 

builder: a name with a control byte or edge space

C0_ERR_BAD_STATE 

builder: e.g.

a level closed that was never opened

C0_ERR_OOM 

allocation failed

◆ c0_unit_kind

What a raw unit holds, by its first non-layout byte.

Enumerator
C0_UNIT_PLAIN 

a plain value, the empty value, or a unit holding only a note

C0_UNIT_TEXT 

STX … ETX.

C0_UNIT_LEVEL 

DLE … CAN.

C0_UNIT_REF 

ENQ name, or ENQ DLE … CAN (a pattern).

Function Documentation

◆ c0_blob()

c0_status c0_blob ( const uint8_t * buf,
size_t len,
const uint8_t * name,
size_t nlen,
c0_bytes * out,
c0_error * err )

The bytes of a named blob from the tail, located by the first document's blob table (columns matched by header name).

C0_ERR_NOT_FOUND when there is no table, no such row, or no EM.

◆ c0_blob_str()

c0_status c0_blob_str ( const uint8_t * buf,
size_t len,
const char * name,
c0_bytes * out,
c0_error * err )

◆ c0_body_bare()

int c0_body_bare ( c0_body b)

Whether the body is a bare record stream: one unnamed file, at most the unnamed group.

◆ c0_body_files()

c0_file_iter c0_body_files ( c0_body b)

◆ c0_body_find_group()

c0_status c0_body_find_group ( c0_body b,
const uint8_t * name,
size_t nlen,
c0_group * out )

First group with the given name in the body (any file), or C0_ERR_NOT_FOUND.

◆ c0_body_find_group_str()

c0_status c0_body_find_group_str ( c0_body b,
const char * name,
c0_group * out )

◆ c0_body_groups()

c0_group_iter c0_body_groups ( c0_body b)

Groups of every file of a body, in order (FS lines are skipped).

◆ c0_body_read()

c0_status c0_body_read ( const uint8_t * buf,
size_t len,
c0_body * out,
c0_error * err )

Parse a slice as a body (no SYN, heading or EOT): the grammar is applied to all of it; C0_OK and *out on success, else the first error.

◆ c0_body_records()

c0_record_iter c0_body_records ( c0_body b)

Records of a bare body (the unnamed group's).

◆ c0_body_view()

c0_body c0_body_view ( const uint8_t * buf,
size_t len )

A body over a whole buffer (a slice with no SYN: records, groups, files), unchecked: pair it with c0_validate, or use c0_body_read.

◆ c0_build_block()

void c0_build_block ( c0_builder * b,
const uint8_t * text,
size_t tlen )

a paragraph: a record of one unit

◆ c0_build_block_str()

void c0_build_block_str ( c0_builder * b,
const char * text )

◆ c0_build_em()

void c0_build_em ( c0_builder * b,
const uint8_t * tail,
size_t tlen )

EM and the raw tail; nothing may follow.

◆ c0_build_eot()

void c0_build_eot ( c0_builder * b)

EOT.

◆ c0_build_etb()

void c0_build_etb ( c0_builder * b,
const uint8_t * payload,
size_t plen )

ETB and an optional plain payload (NULL for none).

◆ c0_build_etb_str()

void c0_build_etb_str ( c0_builder * b,
const char * payload )

◆ c0_build_field()

void c0_build_field ( c0_builder * b,
const uint8_t * value,
size_t vlen )

next unit of the open record (opens one if none)

◆ c0_build_field_str()

void c0_build_field_str ( c0_builder * b,
const char * value )

◆ c0_build_file()

void c0_build_file ( c0_builder * b,
const uint8_t * name,
size_t nlen )

FS name.

◆ c0_build_file_str()

void c0_build_file_str ( c0_builder * b,
const char * name )

◆ c0_build_group()

void c0_build_group ( c0_builder * b,
const uint8_t * name,
size_t nlen )

GS name.

◆ c0_build_group_str()

void c0_build_group_str ( c0_builder * b,
const char * name )

◆ c0_build_header()

void c0_build_header ( c0_builder * b,
const c0_bytes * names,
size_t count )

SOH RS name US name …

◆ c0_build_header_str()

void c0_build_header_str ( c0_builder * b,
const char *const * names,
size_t count )

◆ c0_build_item()

void c0_build_item ( c0_builder * b,
const uint8_t * text,
size_t tlen )

a list item: the next unit

◆ c0_build_item_str()

void c0_build_item_str ( c0_builder * b,
const char * text )

◆ c0_build_key()

void c0_build_key ( c0_builder * b,
const uint8_t * key,
size_t klen,
const uint8_t * value,
size_t vlen )

SOH key US value, in the open record or the heading.

◆ c0_build_key_level_open()

void c0_build_key_level_open ( c0_builder * b,
const uint8_t * key,
size_t klen )

SOH key US DLE.

◆ c0_build_key_level_open_str()

void c0_build_key_level_open_str ( c0_builder * b,
const char * key )

◆ c0_build_key_str()

void c0_build_key_str ( c0_builder * b,
const char * key,
const char * value )

◆ c0_build_level_close()

void c0_build_level_close ( c0_builder * b)

CAN.

◆ c0_build_level_open()

void c0_build_level_open ( c0_builder * b)

DLE: a nested level as the next unit; inside, the builder is at the top of a fresh body.

◆ c0_build_list()

void c0_build_list ( c0_builder * b,
const c0_bytes * items,
size_t count )

a flat list as the next unit: DLE RS item US item … CAN, or DLE CAN

◆ c0_build_list_str()

void c0_build_list_str ( c0_builder * b,
const char *const * items,
size_t count )

◆ c0_build_map()

void c0_build_map ( c0_builder * b,
const c0_bytes * keys,
const c0_bytes * values,
size_t count )

RS and keyed units in the order given.

◆ c0_build_map_str()

void c0_build_map_str ( c0_builder * b,
const char *const * keys,
const char *const * values,
size_t count )

◆ c0_build_note()

void c0_build_note ( c0_builder * b,
const uint8_t * text,
size_t tlen )

BEL and the note (plain, or text when it must be).

◆ c0_build_note_str()

void c0_build_note_str ( c0_builder * b,
const char * text )

◆ c0_build_record()

void c0_build_record ( c0_builder * b,
const c0_bytes * fields,
size_t count )

RS and count units; count 0 opens an empty record.

◆ c0_build_record_str()

void c0_build_record_str ( c0_builder * b,
const char *const * fields,
size_t count )

◆ c0_build_ref()

void c0_build_ref ( c0_builder * b,
const uint8_t * name,
size_t nlen )

ENQ name as the next unit: a group reference.

◆ c0_build_ref_open()

void c0_build_ref_open ( c0_builder * b)

ENQ DLE as the next unit: a pattern; write its lines, then c0_build_level_close.

◆ c0_build_ref_record()

void c0_build_ref_record ( c0_builder * b,
const uint8_t * group,
size_t glen,
const uint8_t * record,
size_t rlen,
const uint8_t * field,
size_t flen )

␅␐␝group␞record[␟field]␘ as the next unit (field NULL to omit)

◆ c0_build_ref_record_str()

void c0_build_ref_record_str ( c0_builder * b,
const char * group,
const char * record,
const char * field )

◆ c0_build_ref_str()

void c0_build_ref_str ( c0_builder * b,
const char * name )

◆ c0_build_section()

void c0_build_section ( c0_builder * b,
const uint8_t * name,
size_t nlen,
size_t depth )

SUB×(depth−1) GS name: a group at depth (1 is a plain GS line).

◆ c0_build_section_str()

void c0_build_section_str ( c0_builder * b,
const char * name,
size_t depth )

◆ c0_build_sub_unit()

void c0_build_sub_unit ( c0_builder * b,
const uint8_t * value,
size_t vlen,
size_t depth )

SUB×depth US value: a sub-unit of the unit just written (depth 2: of the sub-unit before); not a unit of the record.

◆ c0_build_sub_unit_str()

void c0_build_sub_unit_str ( c0_builder * b,
const char * value,
size_t depth )

◆ c0_build_syn()

void c0_build_syn ( c0_builder * b)

SYN; keyed units until the next element are the heading.

◆ c0_builder_bel()

void c0_builder_bel ( c0_builder * b)

BEL alone: the element that follows is dead.

◆ c0_builder_bel_str()

void c0_builder_bel_str ( c0_builder * b,
const char * text )

◆ c0_builder_bel_text()

void c0_builder_bel_text ( c0_builder * b,
const uint8_t * text,
size_t tlen )

BEL and a note; empty text is C0_ERR_BAD_STATE.

◆ c0_builder_bytes()

c0_bytes c0_builder_bytes ( const c0_builder * b)

◆ c0_builder_can()

void c0_builder_can ( c0_builder * b)

CAN: close the innermost level; C0_ERR_BAD_STATE if none is open.

◆ c0_builder_dle()

void c0_builder_dle ( c0_builder * b)

DLE: open a level (saves the record state).

◆ c0_builder_em()

void c0_builder_em ( c0_builder * b,
const uint8_t * tail,
size_t tlen )

EM and the raw tail; nothing may follow.

◆ c0_builder_em_str()

void c0_builder_em_str ( c0_builder * b,
const char * tail )

◆ c0_builder_enq()

void c0_builder_enq ( c0_builder * b,
const uint8_t * name,
size_t nlen )

ENQ name: a group reference.

◆ c0_builder_enq_dle()

void c0_builder_enq_dle ( c0_builder * b)

ENQ DLE: a pattern; write its lines, then c0_builder_can.

◆ c0_builder_enq_str()

void c0_builder_enq_str ( c0_builder * b,
const char * name )

◆ c0_builder_eot()

void c0_builder_eot ( c0_builder * b)

EOT.

◆ c0_builder_etb()

void c0_builder_etb ( c0_builder * b)

ETB alone.

◆ c0_builder_etb_payload()

void c0_builder_etb_payload ( c0_builder * b,
const uint8_t * payload,
size_t plen )

ETB and a plain payload.

◆ c0_builder_etb_str()

void c0_builder_etb_str ( c0_builder * b,
const char * payload )

◆ c0_builder_free()

void c0_builder_free ( c0_builder * b)

◆ c0_builder_fs()

void c0_builder_fs ( c0_builder * b,
const uint8_t * name,
size_t nlen )

FS name; ends any open record.

◆ c0_builder_fs_str()

void c0_builder_fs_str ( c0_builder * b,
const char * name )

◆ c0_builder_gs()

void c0_builder_gs ( c0_builder * b)

GS alone: an empty-named group (␝␝b is group "" then group b).

◆ c0_builder_gs_name()

void c0_builder_gs_name ( c0_builder * b,
const uint8_t * name,
size_t nlen )

GS name; ends any open record.

◆ c0_builder_gs_str()

void c0_builder_gs_str ( c0_builder * b,
const char * name )

◆ c0_builder_init()

void c0_builder_init ( c0_builder * b)

◆ c0_builder_rs()

void c0_builder_rs ( c0_builder * b)

RS: open a record.

◆ c0_builder_rs_str()

void c0_builder_rs_str ( c0_builder * b,
const char * value )

◆ c0_builder_rs_value()

void c0_builder_rs_value ( c0_builder * b,
const uint8_t * value,
size_t vlen )

RS and the record's first value.

◆ c0_builder_soh()

void c0_builder_soh ( c0_builder * b)

SOH alone: before RS, a header row.

◆ c0_builder_soh_name()

void c0_builder_soh_name ( c0_builder * b,
const uint8_t * name,
size_t nlen )

SOH key.

◆ c0_builder_soh_str()

void c0_builder_soh_str ( c0_builder * b,
const char * name )

◆ c0_builder_status()

c0_status c0_builder_status ( const c0_builder * b)

◆ c0_builder_sub()

void c0_builder_sub ( c0_builder * b)

SUB: the element after the next separator is subordinate to the one before (before GS depth, before US a sub-unit).

◆ c0_builder_syn()

void c0_builder_syn ( c0_builder * b)

SYN; soh_name + us_value pairs that follow are the heading.

◆ c0_builder_us()

void c0_builder_us ( c0_builder * b)

US alone (an empty unit, or before DLE / ENQ).

◆ c0_builder_us_str()

void c0_builder_us_str ( c0_builder * b,
const char * value )

◆ c0_builder_us_value()

void c0_builder_us_value ( c0_builder * b,
const uint8_t * value,
size_t vlen )

US and the value that follows it.

◆ c0_bytes_of()

c0_bytes c0_bytes_of ( const uint8_t * ptr,
size_t len )

A view over len bytes at ptr.

◆ c0_canonical()

int c0_canonical ( const uint8_t * buf,
size_t len )

Whether bytes are a canonical span (GRAMMAR.md "Canonical constraints"): well-formed, no layout, one spelling per value, unique keys in each keyed record, no framing, no notes or dead elements.

A SUB prefix is structure and is kept.

◆ c0_container_tail()

c0_status c0_container_tail ( const uint8_t * buf,
size_t len,
c0_bytes * tail,
int * has_em,
c0_error * err )

Scan the whole container: *tail gets the raw region after EM (empty when there is none, *has_em says which).

Returns the first error met.

◆ c0_decode_text()

size_t c0_decode_text ( const uint8_t * inside,
size_t len,
uint8_t * out )

Decode the inside of a text (the bytes between STX and ETX): DLE escapes removed.

out needs room for len bytes (decoding never grows). Returns the logical length.

◆ c0_doc_iter_tail()

c0_bytes c0_doc_iter_tail ( const c0_doc_iter * it)

After the cursor is exhausted: the raw bytes after EM (empty without EM).

◆ c0_document_heading()

c0_pair_iter c0_document_heading ( const c0_document * d)

The heading's keyed units, in written order (dead units skipped).

◆ c0_document_read()

c0_status c0_document_read ( const uint8_t * buf,
size_t len,
size_t start,
c0_document * out,
c0_error * err )

Read the document starting at start (after any layout), applying the whole grammar to it: C0_OK, or the first error.

◆ c0_documents()

c0_doc_iter c0_documents ( const uint8_t * buf,
size_t len )

◆ c0_file_groups()

c0_group_iter c0_file_groups ( c0_file f)

Groups of one file.

◆ c0_file_name()

c0_bytes c0_file_name ( c0_file f)

◆ c0_group_column()

c0_status c0_group_column ( c0_group g,
const uint8_t * name,
size_t nlen,
size_t * index )

Index of a header name in the group's header row, or C0_ERR_NOT_FOUND.

◆ c0_group_header()

int c0_group_header ( c0_group g,
c0_record * out )

The group's header row as a record (its units are the header names).

Returns 0 when the group has none.

◆ c0_group_name()

c0_bytes c0_group_name ( c0_group g)

◆ c0_group_records()

c0_record_iter c0_group_records ( c0_group g)

◆ c0_heading_blob()

c0_status c0_heading_blob ( const c0_document * d,
c0_body * out )

The blob table (a level) as a body, or C0_ERR_NOT_FOUND / C0_ERR_NOT_LEVEL.

◆ c0_heading_get()

c0_status c0_heading_get ( const c0_document * d,
const uint8_t * key,
size_t klen,
c0_bytes * raw )

Raw heading value for a key (last wins), or C0_ERR_NOT_FOUND.

◆ c0_heading_get_str()

c0_status c0_heading_get_str ( const c0_document * d,
const char * key,
c0_bytes * raw )

◆ c0_heading_shape()

c0_bytes c0_heading_shape ( const c0_document * d)

The shape value (decoded, must be plain), or an empty slice when absent.

◆ c0_heading_version()

int c0_heading_version ( const c0_document * d)

The version value as an integer; 1 when absent or not a number.

◆ c0_is_assigned()

int c0_is_assigned ( uint8_t byte)

Whether a byte is one of the sixteen assigned codes.

◆ c0_is_layout()

int c0_is_layout ( uint8_t byte)

Whether a byte is layout outside text (SP, HT, LF, CR).

◆ c0_is_name()

int c0_is_name ( const uint8_t * p,
size_t len )

Whether bytes are a legal name (label, key, header name): same test as plain.

◆ c0_is_plain()

int c0_is_plain ( const uint8_t * p,
size_t len )

Whether a value can be written plain: no byte below 0x20, no edge whitespace.

◆ c0_is_text_escaped()

int c0_is_text_escaped ( uint8_t byte)

Whether a byte is one of the seven codes that take a DLE inside text (STX ETX DLE ETB EOT SYN EM).

◆ c0_next_block()

int c0_next_block ( c0_block_iter * it,
c0_bytes * out,
int * damaged )

◆ c0_next_document()

int c0_next_document ( c0_doc_iter * it,
c0_document * out )

◆ c0_next_file()

int c0_next_file ( c0_file_iter * it,
c0_file * out )

◆ c0_next_group()

int c0_next_group ( c0_group_iter * it,
c0_group * out )

◆ c0_next_pair()

int c0_next_pair ( c0_pair_iter * it,
c0_bytes * key,
c0_bytes * raw )

◆ c0_next_pair_with_subs()

int c0_next_pair_with_subs ( c0_pair_iter * it,
c0_bytes * key,
c0_unit * out )

The same, the value as a unit with its sub-units.

◆ c0_next_record()

int c0_next_record ( c0_record_iter * it,
c0_record * out )

◆ c0_next_sub()

int c0_next_sub ( c0_sub_iter * it,
c0_unit * out )

◆ c0_next_unit()

int c0_next_unit ( c0_unit_iter * it,
c0_bytes * raw )

◆ c0_next_unit_with_subs()

int c0_next_unit_with_subs ( c0_unit_iter * it,
c0_unit * out )

The next positional unit with its sub-units (the walk of c0_next_unit).

◆ c0_pretty_format()

char * c0_pretty_format ( const uint8_t * buf,
size_t len,
const char * indent,
c0_pretty_mode mode,
size_t * outlen,
c0_error * err )

Format compact bytes as pretty form: a malloc'd, NUL-terminated UTF-8 string the caller frees; *outlen (if not NULL) gets its length.

indent defaults to two spaces when NULL. NULL on error: C0_ERR_OOM, a syntax error, or C0_ERR_SYNTAX with msg "glyph in data" when a value holds a Control Picture character and cannot be shown unambiguously.

◆ c0_pretty_parse()

uint8_t * c0_pretty_parse ( const char * str,
size_t len,
size_t * outlen )

Parse pretty form back to compact bytes: glyphs become codes; outside text whitespace touching a glyph or a line edge is dropped.

Returns a malloc'd buffer the caller frees (NULL on allocation failure); *outlen gets the length.

◆ c0_record_count()

size_t c0_record_count ( c0_record r)

Number of positional units.

◆ c0_record_field()

c0_status c0_record_field ( c0_record r,
size_t n,
c0_bytes * raw )

Raw unit n (0-based), or C0_ERR_NOT_FOUND.

◆ c0_record_get()

c0_status c0_record_get ( c0_record r,
const uint8_t * key,
size_t klen,
c0_bytes * raw )

Raw value for a key (last wins), or C0_ERR_NOT_FOUND.

◆ c0_record_get_str()

c0_status c0_record_get_str ( c0_record r,
const char * key,
c0_bytes * raw )

◆ c0_record_keyed()

int c0_record_keyed ( c0_record r)

Whether the record is keyed (it holds a keyed unit, live or dead).

◆ c0_record_pairs()

c0_pair_iter c0_record_pairs ( c0_record r)

Keyed units in written order, duplicates included, dead units skipped.

key is the name; raw the unit's raw value (its sub-units excluded).

◆ c0_record_unit()

c0_status c0_record_unit ( c0_record r,
size_t n,
c0_unit * out )

Unit n (0-based) with its sub-units, or C0_ERR_NOT_FOUND.

◆ c0_record_unit_get()

c0_status c0_record_unit_get ( c0_record r,
const uint8_t * key,
size_t klen,
c0_unit * out )

The unit under a key with its sub-units (last wins), or C0_ERR_NOT_FOUND.

◆ c0_record_unit_get_str()

c0_status c0_record_unit_get_str ( c0_record r,
const char * key,
c0_unit * out )

◆ c0_record_units()

c0_unit_iter c0_record_units ( c0_record r)

The record's positional units.

Each raw is the unit's value bytes with its layout (its sub-units excluded); pass it to c0_value / c0_unit_level / c0_unit_ref. An empty record yields one empty unit. A keyed record yields nothing. A sub-unit is not a unit: ␞a␟b␚␟c yields a and b.

◆ c0_ref_group()

int c0_ref_group ( const c0_ref * r,
c0_bytes * name )

Whether the reference names a group as a whole (a plain name, or a pattern that is a bare group line); *name gets the group's name.

◆ c0_ref_path()

size_t c0_ref_path ( const c0_ref * r,
c0_bytes * steps,
size_t max )

The steps of a reference in walking order: the group name alone, or the pattern's file, group names, record id, field name and the inner pattern's steps (a keyed step contributes its key).

Fills up to max steps and returns the total count.

◆ c0_scan_comment()

size_t c0_scan_comment ( const uint8_t * buf,
size_t pos,
size_t stop,
c0_error * err )

At a BEL: past the note, or past the whole dead element's own line.

◆ c0_scan_layout()

size_t c0_scan_layout ( const uint8_t * buf,
size_t pos,
size_t stop )

Skip layout bytes.

◆ c0_scan_level()

size_t c0_scan_level ( const uint8_t * buf,
size_t pos,
size_t stop,
c0_error * err )

At a DLE: the position after the matching CAN.

◆ c0_scan_plain()

size_t c0_scan_plain ( const uint8_t * buf,
size_t pos,
size_t stop )

Skip a run of bytes >= 0x20 (a label, key, payload or plain value with its layout).

◆ c0_scan_record_end()

size_t c0_scan_record_end ( const uint8_t * buf,
size_t pos,
size_t stop,
c0_error * err )

From just after an RS: the end of the record (a sub-unit, a SUB run then US, stays inside; a SUB run before a line code ends it).

◆ c0_scan_text()

size_t c0_scan_text ( const uint8_t * buf,
size_t pos,
size_t stop,
c0_error * err )

At an STX: the position after the matching ETX.

◆ c0_scan_unit()

size_t c0_scan_unit ( const uint8_t * buf,
size_t pos,
size_t stop,
c0_error * err )

From just after a US (or a key's US): the end of the unit's value (its sub-units, SUB … US …, are not part of it).

◆ c0_stream_before_damage()

size_t c0_stream_before_damage ( const c0_stream * s,
uint8_t * out )

The same, stopping at the first damaged block: the default reading, which delivers the records before the damage; resume_offset says where to go on.

Returns the length.

◆ c0_stream_blocks()

c0_block_iter c0_stream_blocks ( const c0_stream * s)

◆ c0_stream_committed()

c0_bytes c0_stream_committed ( const c0_stream * s)

◆ c0_stream_last_commit_end()

size_t c0_stream_last_commit_end ( const uint8_t * buf,
size_t len )

Position just past the last commit, found by a backward scan (a shortcut for well-formed input; c0_stream_read is authoritative).

◆ c0_stream_read()

c0_stream c0_stream_read ( const uint8_t * buf,
size_t len )

◆ c0_stream_tail()

c0_bytes c0_stream_tail ( const c0_stream * s)

◆ c0_stream_undamaged()

size_t c0_stream_undamaged ( const c0_stream * s,
uint8_t * out )

Copy the undamaged committed blocks, without their ETB markers and payloads, into out (room for committed_end bytes suffices), continuing past every damaged block.

Returns the length. Read the result with c0_document_read / c0_documents to get the records.

◆ c0_trim()

c0_bytes c0_trim ( c0_bytes raw)

Layout trimmed from both ends of a raw slice.

◆ c0_unit_level()

c0_status c0_unit_level ( c0_bytes raw,
c0_body * out )

A raw unit as a nested level: the body between its DLE and CAN.

◆ c0_unit_list()

c0_status c0_unit_list ( c0_bytes raw,
c0_unit_iter * items )

A raw unit as a flat list: a level holding at most one positional record.

On C0_OK items iterates the items (none for the empty level). A level with several records, a keyed record, groups or files is C0_ERR_NOT_LIST.

◆ c0_unit_ref()

c0_status c0_unit_ref ( c0_bytes raw,
c0_ref * out )

A raw unit as a reference.

Checks the form only; a pattern is checked against the pattern rules (one branch, names only, no values).

◆ c0_unit_sub_count()

size_t c0_unit_sub_count ( c0_unit u)

Number of direct sub-units.

◆ c0_unit_subs()

c0_sub_iter c0_unit_subs ( c0_unit u)

◆ c0_unit_type()

c0_unit_kind c0_unit_type ( c0_bytes raw)

◆ c0_validate()

c0_status c0_validate ( const uint8_t * buf,
size_t len,
c0_error * err )

Check a whole buffer (one or more documents, an optional EM tail) against GRAMMAR.md.

Returns C0_OK or the first error (detail in *err when given).

◆ c0_value()

c0_status c0_value ( c0_bytes raw,
uint8_t * scratch,
c0_bytes * out )

The logical value of a raw unit (as yielded by c0_next_unit, c0_next_pair, c0_record_field …): for a plain value the slice with edge layout removed; for text the inside with its escapes decoded; for a unit holding only a note or a dead level, the empty value.

*out points into the buffer when no decoding is needed; when the text holds DLE escapes it is decoded into scratch (room for raw.len bytes always suffices) and *out points there. With a NULL scratch such a unit answers C0_ERR_NEEDS_DECODE. A level or reference answers C0_ERR_NOT_SCALAR; malformed input C0_ERR_SYNTAX.