YATL
Loading...
Searching...
No Matches
yatl.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <stdbool.h>
13#include <stddef.h>
14#include <stdint.h>
15#include <stdio.h>
16
49
54#define YATL_LINE_SIZE 96
55
60#define YATL_CURSOR_SIZE 96
61
66#define YATL_SPAN_SIZE 160
67
72#define YATL_DOC_SIZE 64
73
81typedef struct YATL_Line {
82 _Alignas(max_align_t) unsigned char _opaque[YATL_LINE_SIZE];
84
94typedef struct YATL_Cursor {
95 _Alignas(max_align_t) unsigned char _opaque[YATL_CURSOR_SIZE];
97
109typedef struct YATL_Span {
110 _Alignas(max_align_t) unsigned char _opaque[YATL_SPAN_SIZE];
112
122typedef struct YATL_Doc {
123 _Alignas(max_align_t) unsigned char _opaque[YATL_DOC_SIZE];
125
136
141#define YATL_ENABLE_LOGGING
142
143#ifdef YATL_ENABLE_LOGGING
144#ifndef LOG_LEVEL
145#define LOG_LEVEL YATL_LOG_DEBUG
146#endif
147#endif
148
155static inline const char *log_level_str(YATL_log_level_t level) {
156 switch (level) {
157 case YATL_LOG_DEBUG:
158 return "DEBUG";
159 case YATL_LOG_INFO:
160 return "INFO";
161 case YATL_LOG_WARN:
162 return "WARN";
163 case YATL_LOG_ERROR:
164 return "ERROR";
165 default:
166 return "UNKNOWN";
167 }
168}
169
177#ifdef YATL_ENABLE_LOGGING
178#define YATL_LOG(level, fmt, ...) \
179 do { \
180 if ((level) >= LOG_LEVEL) { \
181 fprintf(stderr, "[%s] %s:%d (%s): " fmt "\n", log_level_str(level), \
182 __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
183 } \
184 } while (0)
185#else
186#define YATL_LOG(level, fmt, ...) \
187 do { \
188 } while (0)
189#endif
190
212
226
243
258
268
281
296YATL_Result_t YATL_doc_load(YATL_Doc_t *doc, const char *path);
297
313YATL_Result_t YATL_doc_loads(YATL_Doc_t *doc, const char *str, size_t len);
314
328YATL_Result_t YATL_doc_save(YATL_Doc_t *doc, const char *path);
329
343
359
374
401 YATL_Cursor_t *cursor, YATL_Span_t *out_span);
402
421YATL_Result_t YATL_span_find_name(const YATL_Span_t *in_span, const char *name,
422 YATL_Span_t *out_span);
423
452 const char *name,
453 const YATL_Cursor_t *in_cursor,
454 YATL_Cursor_t *out_cursor,
455 YATL_Span_t *out_span);
456
484 YATL_Cursor_t *cursor, const char **out_text,
485 size_t *out_len);
486
503
515
535 YATL_Span_t *key, YATL_Span_t *val);
536
546
565YATL_Result_t YATL_span_text(const YATL_Span_t *in_span, const char **out_text,
566 size_t *out_len);
567
593YATL_Result_t YATL_span_get_string(const YATL_Span_t *in_span, const char *key,
594 const char **out_text, size_t *out_len);
595
628 const size_t *lengths, size_t line_count);
643
645 size_t length);
YATL_Doc_t YATL_doc_create(void)
Create an initialized document.
YATL_Result_t YATL_doc_load(YATL_Doc_t *doc, const char *path)
Load a TOML document from a file.
YATL_Result_t YATL_doc_clear_boneyard(YATL_Doc_t *doc)
Clear the document boneyard.
YATL_Result_t YATL_doc_save(YATL_Doc_t *doc, const char *path)
Save a document to a file.
void YATL_doc_free(YATL_Doc_t *doc)
Free document resources.
YATL_Result_t YATL_doc_loads(YATL_Doc_t *doc, const char *str, size_t len)
Load a TOML document from a string.
YATL_Result_t
Result/error codes returned by YATL functions.
Definition yatl.h:231
YATL_SpanType_t
Span type enumeration.
Definition yatl.h:201
YATL_ValueType_t
Value type enumeration.
Definition yatl.h:219
@ YATL_ERR_NOT_FOUND
Definition yatl.h:236
@ YATL_OK
Definition yatl.h:233
@ YATL_ERR_SYNTAX
Definition yatl.h:235
@ YATL_ERR_NOMEM
Definition yatl.h:239
@ YATL_DONE
Definition yatl.h:232
@ YATL_ERR_IO
Definition yatl.h:234
@ YATL_ERR_TYPE
Definition yatl.h:237
@ YATL_ERR_BUFFERi
Definition yatl.h:238
@ YATL_ERR_INVALID_ARG
Definition yatl.h:240
@ YATL_S_NODE_ARRAY
Definition yatl.h:204
@ YATL_S_NODE_ARRAY_TABLE
Definition yatl.h:205
@ YATL_S_LEAF_COMMENT
Definition yatl.h:208
@ YATL_S_NONE
Definition yatl.h:202
@ YATL_S_SLICE_KEY
Definition yatl.h:209
@ YATL_S_NODE_INLINE_TABLE
Definition yatl.h:206
@ YATL_S_LEAF_KEYVAL
Definition yatl.h:207
@ YATL_S_NODE_TABLE
Definition yatl.h:203
@ YATL_S_SLICE_VALUE
Definition yatl.h:210
@ YATL_TYPE_BAREVALUE
Definition yatl.h:220
@ YATL_TYPE_STRING
Definition yatl.h:222
@ YATL_TYPE_ARRAY
Definition yatl.h:223
@ YATL_TYPE_INLINE_TABLE
Definition yatl.h:224
YATL_Span_t YATL_span_create(void)
Create an initialized span.
YATL_Cursor_t YATL_cursor_create(void)
Create an initialized cursor.
YATL_log_level_t
Log levels for YATL diagnostic messages.
Definition yatl.h:130
@ YATL_LOG_ERROR
Definition yatl.h:134
@ YATL_LOG_DEBUG
Definition yatl.h:131
@ YATL_LOG_WARN
Definition yatl.h:133
@ YATL_LOG_INFO
Definition yatl.h:132
YATL_Result_t YATL_span_ml_set_value(YATL_Span_t *span, const char **lines, const size_t *lengths, size_t line_count)
Set the value of a span, supporting multi-line values.
YATL_Result_t YATL_span_set_value(YATL_Span_t *span, const char *value, size_t length)
Set the value of a span with a single-line value.Replaces the value content of a span with new conten...
YATL_Result_t YATL_span_find_name(const YATL_Span_t *in_span, const char *name, YATL_Span_t *out_span)
Find a table or key-value by name.
YATL_Result_t YATL_span_iter_line(const YATL_Span_t *span, YATL_Cursor_t *cursor, const char **out_text, size_t *out_len)
Iterate over line segments within a span.
YATL_Result_t YATL_doc_span(const YATL_Doc_t *doc, YATL_Span_t *out_span)
Get a span covering the entire document.
YATL_Result_t YATL_cursor_move(YATL_Cursor_t *cursor, long npos)
Move a cursor by a character offset.
YATL_Result_t YATL_span_find_next(const YATL_Span_t *in_span, YATL_Cursor_t *cursor, YATL_Span_t *out_span)
Find the next span within a boundary span.
YATL_Result_t YATL_span_find_next_by_name(const YATL_Span_t *in_span, const char *name, const YATL_Cursor_t *in_cursor, YATL_Cursor_t *out_cursor, YATL_Span_t *out_span)
Find next table or key-value by name with cursor support.
YATL_Result_t YATL_span_keyval_slice(const YATL_Span_t *in_span, YATL_Span_t *key, YATL_Span_t *val)
Slice a key-value span into separate key and value spans.
const char * YATL_span_type_name(YATL_SpanType_t type)
Get the string name of a span type.
YATL_Result_t YATL_span_text(const YATL_Span_t *in_span, const char **out_text, size_t *out_len)
Get text content of a single-line span.
YATL_SpanType_t YATL_span_type(const YATL_Span_t *span)
Get the type of a span.
YATL_Result_t YATL_span_get_string(const YATL_Span_t *in_span, const char *key, const char **out_text, size_t *out_len)
Convenience function to find a key and get its string value.
#define YATL_CURSOR_SIZE
Size of opaque YATL_Cursor_t structure in bytes.
Definition yatl.h:60
struct YATL_Doc YATL_Doc_t
Opaque document structure.
struct YATL_Cursor YATL_Cursor_t
Opaque cursor structure.
struct YATL_Line YATL_Line_t
Opaque line structure.
#define YATL_DOC_SIZE
Size of opaque YATL_Doc_t structure in bytes.
Definition yatl.h:72
#define YATL_SPAN_SIZE
Size of opaque YATL_Span_t structure in bytes.
Definition yatl.h:66
struct YATL_Span YATL_Span_t
Opaque span structure.
#define YATL_LINE_SIZE
Size of opaque YATL_Line_t structure in bytes.
Definition yatl.h:54
Opaque cursor structure.
Definition yatl.h:94
Opaque document structure.
Definition yatl.h:122
Opaque line structure.
Definition yatl.h:81
Opaque span structure.
Definition yatl.h:109