summaryrefslogtreecommitdiff
path: root/src/text-buffer.h
blob: 3c858165bf150ed9b9e12f28f08f9c5d8ee5b603 (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
43
/* parc
 * Copyright (C) 2025 Ekaitz Zarraga <ekaitz@elenq.tech>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * This is a growable char buffer, it grows automatically on append.
 * It must be cleared after use as it allocates memory.
 */

#ifndef TEXT_BUFFER_H
#define TEXT_BUFFER_H

#include <stddef.h>

typedef struct
  {
    size_t used;
    size_t size;
    char *contents;
  }
text_buffer;

void text_buffer_init (text_buffer *tb);
void text_buffer_resize (text_buffer *tb, size_t size);
void text_buffer_append (text_buffer *tb, char c);
char text_buffer_index (text_buffer *tb, size_t pos);
void text_buffer_fill (text_buffer *tb, char *fill, size_t size);
void text_buffer_clear (text_buffer *tb);

#endif /* TEXT_BUFFER_H */