65 memset(buf, 0,
sizeof(
struct Buffer));
78 if (!buf || !buf->
data || (buf->
dsize == 0))
112 memcpy(buf->
dptr, s, len);
134 int blen = buf->
dsize - doff;
137 va_copy(ap_retry, ap);
139 int len = vsnprintf(buf->
dptr, blen, fmt, ap);
143 len = vsnprintf(buf->
dptr, len + 1, fmt, ap_retry);
192 buf->
dptr = strchr(buf->
data,
'\0');
258 if (!buf || !s || (*s ==
'\0'))
264 const size_t curlen =
buf_len(buf);
269 for (
size_t i = curlen; i < offset; ++i)
277 memmove(buf->
data + offset + slen, buf->
data + offset, curlen - offset);
278 memcpy(buf->
data + offset, s, slen);
279 buf->
data[curlen + slen] =
'\0';
280 buf->
dptr = buf->
data + curlen + slen;
293 if (!buf || !buf->
data)
296 return (buf->
data[0] ==
'\0');
324 struct Buffer *buf = *ptr;
342 if (buf->
data && (new_size <= buf->
dsize))
358 const bool was_empty = (buf->
dptr == NULL);
359 const size_t offset = (buf->
dptr && buf->
data) ? (buf->
dptr - buf->
data) : 0;
379 if (!buf || !buf->
data)
436 if (!buf || !buf->
data || (buf->
dsize == 0))
444 if (*buf->
dptr ==
'\\')
450 else if (*buf->
dptr !=
'\"')
493 if (!buf || !buf->
data || !buf->
dptr)
519 const bool d_set = (dir[0] !=
'\0');
520 const bool f_set = (fname[0] !=
'\0');
521 if (!d_set && !f_set)
524 const int d_len = strlen(dir);
525 const bool slash = d_set && (dir[d_len - 1] ==
'/');
527 const char *fmt =
"%s/%s";
528 if (!f_set || !d_set || slash)
547 const char *fname,
size_t fnamelen)
557 if ((dirlen != 0) && (fnamelen != 0))
607 if (!src || !src->
data)
645 return strstr(buf->
data, s);
660 return strchr(buf->
data, c);
672 if (!buf || (offset >
buf_len(buf)))
675 return buf->
data[offset];
775 size_t olen = buf->
dsize;
778 size_t new_size = buf->
dsize - len + rlen + 1;
779 if (new_size > buf->
dsize)
782 memmove(buf->
data + pos + rlen, buf->
data + pos + len, olen - pos - len);
783 memmove(buf->
data + pos, str, rlen);
802 int len = strlen(str);
803 const char *end = buf->
data + buf->
dsize - len;
805 for (
const char *p = end; p >= buf->
data; --p)
807 for (
size_t i = 0; i < len; i++)
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
int buf_coll(const struct Buffer *a, const struct Buffer *b)
Collate two strings (compare using locale)
bool buf_istr_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal, case insensitive.
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
void buf_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
size_t buf_addstr_n(struct Buffer *buf, const char *s, size_t len)
Add a string to a Buffer, expanding it if necessary.
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
const char * buf_find_string(const struct Buffer *buf, const char *s)
Return a pointer to a substring found in the buffer.
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
static int buf_vaprintf(struct Buffer *buf, const char *fmt, va_list ap)
Format a string into a Buffer.
void buf_dequote_comment(struct Buffer *buf)
Un-escape characters in an email address comment.
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
void buf_inline_replace(struct Buffer *buf, size_t pos, size_t len, const char *str)
struct Buffer * buf_init(struct Buffer *buf)
Initialise a new Buffer.
size_t buf_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
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.
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
void buf_join_str(struct Buffer *buf, const char *str, char sep)
Join a buffer with a string separated by sep.
bool buf_str_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal.
const char * buf_rfind(const struct Buffer *buf, const char *str)
Find last instance of a substring.
struct Buffer * buf_dup(const struct Buffer *buf)
Copy a Buffer into a new allocated buffer.
const char * buf_find_char(const struct Buffer *buf, const char c)
Return a pointer to a char found in the buffer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
size_t buf_insert(struct Buffer *buf, size_t offset, const char *s)
Add a string in the middle of a buffer.
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
void buf_lower(struct Buffer *buf)
Sets a buffer to lowercase.
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
static const int BufferStepSize
When increasing the size of a Buffer, add this much extra space.
size_t buf_startswith(const struct Buffer *buf, const char *prefix)
Check whether a buffer starts with a prefix.
size_t buf_substrcpy(struct Buffer *buf, const char *beg, const char *end)
Copy a partial string into a Buffer.
General purpose object for storing and parsing strings.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
void mutt_exit(int code)
Leave NeoMutt NOW.
Memory management wrappers.
#define ROUND_UP(NUM, STEP)
#define MUTT_MEM_CALLOC(n, type)
#define MUTT_MEM_REALLOC(pptr, n, type)
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
char * mutt_str_dup(const char *str)
Copy a string, safely.
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
String manipulation functions.
String manipulation buffer.
char * dptr
Current read/write position.
size_t dsize
Length of data.
char * data
Pointer to data.