#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; 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); u32 txt_insert(Txt *b, u32 cur, const char *s, u32 n); u32 txt_delete(Txt *b, u32 cur, u32 n); u32 txt_insert_c(Txt *b, u32 cur, u32 ch); u32 txt_delete_c(Txt *b, u32 cur); int txt_load(Txt *b, const char *path); int txt_save(Txt *b, const char *path); void txt_free(Txt *b); TxtLoc txt_at(Txt *b, u32 cur); u32 txt_ofs(Txt *b, TxtLoc l); TxtLoc txt_next(Txt *b, TxtLoc l); TxtLoc txt_prev(Txt *b, TxtLoc l); int txt_at_start(Txt *b, TxtLoc l); int txt_at_end(Txt *b, TxtLoc l); u32 txt_chr(Txt *b, TxtLoc l); u8 txt_byte(Txt *b, TxtLoc l); #endif