NeoMutt  2025-12-11-1061-g88ae84
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1
25
26#ifndef MUTT_MUTT_BUFFER_H
27#define MUTT_MUTT_BUFFER_H
28
29#include <stdarg.h>
30#include <stdbool.h>
31#include <stddef.h>
32
36struct Buffer
37{
38 char *data;
39 char *dptr;
40 size_t dsize;
41};
42
43struct Buffer *buf_new (const char *str);
44void buf_free (struct Buffer **ptr);
45void buf_alloc (struct Buffer *buf, size_t size);
46void buf_dealloc (struct Buffer *buf);
47void buf_fix_dptr (struct Buffer *buf);
48struct Buffer *buf_init (struct Buffer *buf);
49bool buf_is_empty (const struct Buffer *buf);
50size_t buf_len (const struct Buffer *buf);
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)));
70int buf_vaprintf (struct Buffer *buf, const char *fmt, va_list ap)
71 __attribute__((__format__(__printf__, 2, 0)));
72void buf_join_str (struct Buffer *str, const char *item, char sep);
73
74// Functions that INSERT into a Buffer
75size_t buf_insert (struct Buffer *buf, size_t offset, const char *s);
76
77// Functions that OVERWRITE a Buffer
78size_t buf_concat_path (struct Buffer *buf, const char *dir, const char *fname);
79size_t buf_concatn_path (struct Buffer *dst, const char *dir, size_t dirlen, const char *fname, size_t fnamelen);
80size_t buf_copy (struct Buffer *dst, const struct Buffer *src);
81int buf_printf (struct Buffer *buf, const char *fmt, ...)
82 __attribute__((__format__(__printf__, 2, 3)));
83size_t buf_strcpy (struct Buffer *buf, const char *s);
84size_t buf_strcpy_n (struct Buffer *buf, const char *s, size_t len);
85size_t buf_substrcpy (struct Buffer *buf, const char *beg, const char *end);
86void buf_dequote_comment (struct Buffer *buf);
87void buf_lower (struct Buffer *buf);
88void buf_inline_replace (struct Buffer *buf, size_t pos, size_t len, const char *str);
89
99static inline const char *buf_string(const struct Buffer *buf)
100{
101 if (!buf || !buf->data)
102 return "";
103
104 return buf->data;
105}
106
107#endif /* MUTT_MUTT_BUFFER_H */
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:168
int buf_vaprintf(struct Buffer *buf, const char *fmt, va_list ap)
Format a string into a Buffer.
Definition buffer.c:133
void buf_dequote_comment(struct Buffer *buf)
Un-escape characters in an email address comment.
Definition buffer.c:440
void buf_inline_replace(struct Buffer *buf, size_t pos, size_t len, const char *str)
Replace part of a string.
Definition buffer.c:774
size_t buf_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
Definition buffer.c:422
size_t buf_concatn_path(struct Buffer *buf, const char *dir, size_t dirlen, const char *fname, size_t fnamelen)
Join a directory name and a filename.
Definition buffer.c:552
void buf_join_str(struct Buffer *buf, const char *str, char sep)
Join a buffer with a string separated by sep.
Definition buffer.c:754
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:401
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition buffer.c:607
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:263
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition buffer.c:515
void buf_lower(struct Buffer *buf)
Sets a buffer to lowercase.
Definition buffer.c:740
size_t buf_substrcpy(struct Buffer *buf, const char *beg, const char *end)
Copy a partial string into a Buffer.
Definition buffer.c:477
int buf_coll(const struct Buffer *a, const struct Buffer *b)
Collate two strings (compare using locale).
Definition buffer.c:729
bool buf_istr_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal, case insensitive.
Definition buffer.c:701
void buf_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
Definition buffer.c:628
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:109
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:497
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:644
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition buffer.c:383
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:89
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:298
void buf_alloc(struct Buffer *buf, size_t size)
Make sure a buffer can store at least new_size bytes.
Definition buffer.c:342
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition buffer.c:189
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition buffer.c:674
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
Definition buffer.c:326
struct Buffer * buf_init(struct Buffer *buf)
Initialise a new Buffer.
Definition buffer.c:74
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:99
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition buffer.c:311
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:248
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:233
bool buf_str_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal.
Definition buffer.c:689
const char * buf_rfind(const struct Buffer *buf, const char *str)
Find last instance of a substring.
Definition buffer.c:805
struct Buffer * buf_dup(const struct Buffer *buf)
Copy a Buffer into a new allocated buffer.
Definition buffer.c:592
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:659
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:577
size_t buf_startswith(const struct Buffer *buf, const char *prefix)
Check whether a buffer starts with a prefix.
Definition buffer.c:713
String manipulation buffer.
Definition buffer.h:37
char * dptr
Current read/write position.
Definition buffer.h:39
size_t dsize
Length of data.
Definition buffer.h:40
char * data
Pointer to data.
Definition buffer.h:38