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
43
|
#ifndef TXT_H
#define TXT_H
#include "dynarr.h"
typedef enum : u8 {
TXT_SRC,
TXT_ADD
} TxtBufIdx;
typedef struct TxtPiece {
TxtBufIdx buf;
u32 ofs, n;
} TxtPiece;
typedef struct {
char *s;
u32 n, c;
} TxtBuf;
typedef struct {
u32 p, i;
} TxtLoc;
typedef struct {
DYNARR(TxtPiece) ptbl;
TxtBuf buf[2];
u32 len;
} Txt;
TxtLoc txt_at(Txt *b, u32 cur);
u32 txt_split_piece(Txt *b, u32 pi, u32 i);
void txt_remove_piece(Txt *b, u32 pi);
void txt_insert_piece(Txt *b, u32 pi, TxtBufIdx buf, u32 ofs, u32 n);
void txt_buf_append(Txt *b, TxtBufIdx bi, const char *s, u32 n);
u32 txt_insert(Txt *b, u32 cur, const char *s, u32 n);
u32 txt_insert_c(Txt *b, u32 cur, char ch);
u32 txt_delete(Txt *b, u32 cur, u32 n);
int txt_open(Txt *b, const char *path);
#endif
|