NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1
26#ifndef MUTT_MUTT_BUFFER_H
27#define MUTT_MUTT_BUFFER_H
28
29#include <stdbool.h>
30#include <stddef.h>
31
35struct Buffer
36{
37 char *data;
38 char *dptr;
39 size_t dsize;
40};
41
42struct Buffer *buf_new (const char *str);
43void buf_free (struct Buffer **ptr);
44void buf_alloc (struct Buffer *buf, size_t size);
45void buf_dealloc (struct Buffer *buf);
46void buf_fix_dptr (struct Buffer *buf);
47struct Buffer *buf_init (struct Buffer *buf);
48bool buf_is_empty (const struct Buffer *buf);
49size_t buf_len (const struct Buffer *buf);
50void buf_reset (struct Buffer *buf);
51char * buf_strdup (const struct Buffer *buf);
52struct Buffer *buf_dup (const struct Buffer *buf);
53void buf_seek (struct Buffer *buf, size_t offset);
54const char* buf_find_string (const struct Buffer *buf, const char *s);
55const char* buf_find_char (const struct Buffer *buf, const char c);
56char buf_at (const struct Buffer *buf, size_t offset);
57bool buf_str_equal (const struct Buffer *a, const struct Buffer *b);
58bool buf_istr_equal (const struct Buffer *a, const struct Buffer *b);
59int buf_coll (const struct Buffer *a, const struct Buffer *b);
60size_t buf_startswith (const struct Buffer *buf, const char *prefix);
61const char *buf_rfind (const struct Buffer *buf, const char *str);
62
63// Functions that APPEND to a Buffer
64size_t buf_addch (struct Buffer *buf, char c);
65size_t buf_addstr (struct Buffer *buf, const char *s);
66size_t buf_addstr_n (struct Buffer *buf, const char *s, size_t len);
67int buf_add_printf (struct Buffer *buf, const char *fmt, ...)
68 __attribute__((__format__(__printf__, 2, 3)));
69void buf_join_str (struct Buffer *str, const char *item, char sep);
70
71// Functions that INSERT into a Buffer
72size_t buf_insert (struct Buffer *buf, size_t offset, const char *s);
73
74// Functions that OVERWRITE a Buffer
75size_t buf_concat_path (struct Buffer *buf, const char *dir, const char *fname);
76size_t buf_concatn_path (struct Buffer *dst, const char *dir, size_t dirlen, const char *fname, size_t fnamelen);
77size_t buf_copy (struct Buffer *dst, const struct Buffer *src);
78int buf_printf (struct Buffer *buf, const char *fmt, ...)
79 __attribute__((__format__(__printf__, 2, 3)));
80size_t buf_strcpy (struct Buffer *buf, const char *s);
81size_t buf_strcpy_n (struct Buffer *buf, const char *s, size_t len);
82size_t buf_substrcpy (struct Buffer *buf, const char *beg, const char *end);
83void buf_dequote_comment (struct Buffer *buf);
84void buf_lower (struct Buffer *buf);
85void buf_inline_replace (struct Buffer *buf, size_t pos, size_t len, const char *str);
86
96static inline const char *buf_string(const struct Buffer *buf)
97{
98 if (!buf || !buf->data)
99 return "";
100
101 return buf->data;
102}
103
104#endif /* MUTT_MUTT_BUFFER_H */
int buf_coll(const struct Buffer *a, const struct Buffer *b)
Collate two strings (compare using locale)
Definition: buffer.c:725
bool buf_istr_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal, case insensitive.
Definition: buffer.c:697
int buf_printf(struct Buffer *buf, const char *fmt,...) __attribute__((__format__(__printf__
void buf_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
Definition: buffer.c:622
size_t buf_addstr_n(struct Buffer *buf, const char *s, size_t len)
Add a string to a Buffer, expanding it if necessary.
Definition: buffer.c:96
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:491
const char * buf_find_string(const struct Buffer *buf, const char *s)
Return a pointer to a substring found in the buffer.
Definition: buffer.c:640
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:377
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
void buf_alloc(struct Buffer *buf, size_t size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:337
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:182
void buf_dequote_comment(struct Buffer *buf)
Un-escape characters in an email address comment.
Definition: buffer.c:434
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition: buffer.c:670
int void buf_join_str(struct Buffer *str, const char *item, char sep)
Join a buffer with a string separated by sep.
Definition: buffer.c:750
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
Definition: buffer.c:319
void buf_inline_replace(struct Buffer *buf, size_t pos, size_t len, const char *str)
Definition: buffer.c:770
struct Buffer * buf_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:61
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
size_t buf_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
Definition: buffer.c:416
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition: buffer.c:304
int size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
size_t buf_concatn_path(struct Buffer *dst, const char *dir, size_t dirlen, const char *fname, size_t fnamelen)
Join a directory name and a filename.
Definition: buffer.c:546
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:226
bool buf_str_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal.
Definition: buffer.c:685
const char * buf_rfind(const struct Buffer *buf, const char *str)
Find last instance of a substring.
Definition: buffer.c:797
struct Buffer * buf_dup(const struct Buffer *buf)
Copy a Buffer into a new allocated buffer.
Definition: buffer.c:586
int buf_add_printf(struct Buffer *buf, const char *fmt,...) __attribute__((__format__(__printf__
const char * buf_find_char(const struct Buffer *buf, const char c)
Return a pointer to a char found in the buffer.
Definition: buffer.c:655
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:601
size_t buf_insert(struct Buffer *buf, size_t offset, const char *s)
Add a string in the middle of a buffer.
Definition: buffer.c:256
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:571
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:509
void buf_lower(struct Buffer *buf)
Sets a buffer to lowercase.
Definition: buffer.c:736
size_t buf_startswith(const struct Buffer *buf, const char *prefix)
Check whether a buffer starts with a prefix.
Definition: buffer.c:709
size_t buf_substrcpy(struct Buffer *buf, const char *beg, const char *end)
Copy a partial string into a Buffer.
Definition: buffer.c:471
String manipulation buffer.
Definition: buffer.h:36
char * dptr
Current read/write position.
Definition: buffer.h:38
size_t dsize
Length of data.
Definition: buffer.h:39
char * data
Pointer to data.
Definition: buffer.h:37