aboutsummaryrefslogtreecommitdiff
path: root/src/format.h
blob: bceff0c35e139af8f88de181ec5fe7331554d289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef COMET_FORMAT_H
#define COMET_FORMAT_H

#include <stdint.h>
#include <stdbool.h>

typedef struct {
    char **parts;
    size_t length;
} format_t;

typedef enum {
    FORMAT_SUCCESS,
    FORMAT_NESTED,
    FORMAT_UNKNOWN,
    FORMAT_UNTERMINATED,
} format_status_t;

typedef enum {
    FORMAT_NONE,
    FORMAT_STRING,
    FORMAT_BYTE,
    FORMAT_FUNCTION,
} format_action_t;

typedef char *(*format_function_t)(const char *key);

typedef struct {
    format_action_t action;
    const char *key;
    union {
        const char *value;
        uint8_t byte;
        format_function_t fn;
    };
} format_pair_t;

format_status_t format_init(format_t *format, const char *string, char delim, const format_pair_t *pairs);

void format_free(format_t *format);

#endif