NeoMutt  2024-02-01-35-geee02f
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 <stddef.h>
30#include <stdbool.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);
50struct Buffer buf_make (size_t size);
51void buf_reset (struct Buffer *buf);
52char * buf_strdup (const struct Buffer *buf);
53struct Buffer *buf_dup (const struct Buffer *buf);
54void buf_seek (struct Buffer *buf, size_t offset);
55const char* buf_find_string (const struct Buffer *buf, const char *s);
56const char* buf_find_char (const struct Buffer *buf, const char c);
57char buf_at (const struct Buffer *buf, size_t offset);
58bool buf_str_equal (const struct Buffer *a, const struct Buffer *b);
59bool buf_istr_equal (const struct Buffer *a, const struct Buffer *b);
60int buf_coll (const struct Buffer *a, const struct Buffer *b);
61size_t buf_startswith (const struct Buffer *buf, const char *prefix);
62const char *buf_rfind (const struct Buffer *buf, const char *str);
63
64// Functions that APPEND to a Buffer
65size_t buf_addch (struct Buffer *buf, char c);
66size_t buf_addstr (struct Buffer *buf, const char *s);
67size_t buf_addstr_n (struct Buffer *buf, const char *s, size_t len);
68int buf_add_printf (struct Buffer *buf, const char *fmt, ...)
69 __attribute__((__format__(__printf__, 2, 3)));
70void buf_join_str (struct Buffer *str, const char *item, char sep);
71
72// Functions that INSERT into a Buffer
73size_t buf_insert (struct Buffer *buf, size_t offset, const char *s);
74
75// Functions that OVERWRITE a Buffer
76size_t buf_concat_path (struct Buffer *buf, const char *dir, const char *fname);
77size_t buf_concatn_path (struct Buffer *dst, const char *dir, size_t dirlen, const char *fname, size_t fnamelen);
78size_t buf_copy (struct Buffer *dst, const struct Buffer *src);
79int buf_printf (struct Buffer *buf, const char *fmt, ...)
80 __attribute__((__format__(__printf__, 2, 3)));
81size_t buf_strcpy (struct Buffer *buf, const char *s);
82size_t buf_strcpy_n (struct Buffer *buf, const char *s, size_t len);
83size_t buf_substrcpy (struct Buffer *buf, const char *beg, const char *end);
84void buf_dequote_comment (struct Buffer *buf);
85void buf_lower (struct Buffer *buf);
86void buf_inline_replace (struct Buffer *buf, size_t pos, size_t len, const char *str);
87
97static inline const char *buf_string(const struct Buffer *buf)
98{
99 if (!buf || !buf->data)
100 return "";
101
102 return buf->data;
103}
104
105#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:742
bool buf_istr_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal, case insensitive.
Definition: buffer.c:714
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:639
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:113
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:508
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:657
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:394
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:93
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:308
void buf_alloc(struct Buffer *buf, size_t size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:354
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:75
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:199
void buf_dequote_comment(struct Buffer *buf)
Un-escape characters in an email address comment.
Definition: buffer.c:451
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition: buffer.c:687
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:767
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
Definition: buffer.c:336
void buf_inline_replace(struct Buffer *buf, size_t pos, size_t len, const char *str)
Definition: buffer.c:787
struct Buffer * buf_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:60
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:97
size_t buf_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
Definition: buffer.c:433
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition: buffer.c:321
int size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:412
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:563
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:258
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:243
bool buf_str_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal.
Definition: buffer.c:702
const char * buf_rfind(const struct Buffer *buf, const char *str)
Find last instance of a substring.
Definition: buffer.c:814
struct Buffer * buf_dup(const struct Buffer *buf)
Copy a Buffer into a new allocated buffer.
Definition: buffer.c:603
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:672
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:618
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:273
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:588
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:526
void buf_lower(struct Buffer *buf)
Sets a buffer to lowercase.
Definition: buffer.c:753
size_t buf_startswith(const struct Buffer *buf, const char *prefix)
Check whether a buffer starts with a prefix.
Definition: buffer.c:726
size_t buf_substrcpy(struct Buffer *buf, const char *beg, const char *end)
Copy a partial string into a Buffer.
Definition: buffer.c:488
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