59 memset(buf, 0,
sizeof(
struct Buffer));
90 if (!buf || !buf->
data || (buf->
dsize == 0))
124 memcpy(buf->
dptr, s, len);
146 int blen = buf->
dsize - doff;
149 va_copy(ap_retry, ap);
151 int len = vsnprintf(buf->
dptr, blen, fmt, ap);
155 len = vsnprintf(buf->
dptr, len + 1, fmt, ap_retry);
204 buf->
dptr = strchr(buf->
data,
'\0');
270 if (!buf || !s || (*s ==
'\0'))
276 const size_t curlen =
buf_len(buf);
281 for (
size_t i = curlen; i < offset; ++i)
289 memmove(buf->
data + offset + slen, buf->
data + offset, curlen - offset);
290 memcpy(buf->
data + offset, s, slen);
291 buf->
data[curlen + slen] =
'\0';
292 buf->
dptr = buf->
data + curlen + slen;
305 if (!buf || !buf->
data)
308 return (buf->
data[0] ==
'\0');
334 struct Buffer *buf = *ptr;
352 if (buf->
data && (new_size <= buf->
dsize))
363 const bool was_empty = (buf->
dptr == NULL);
364 const size_t offset = (buf->
dptr && buf->
data) ? (buf->
dptr - buf->
data) : 0;
385 if (!buf || !buf->
data)
462 if (!buf || !buf->
data || !buf->
dptr)
488 const bool d_set = (dir[0] !=
'\0');
489 const bool f_set = (fname[0] !=
'\0');
490 if (!d_set && !f_set)
493 const int d_len = strlen(dir);
494 const bool slash = d_set && (dir[d_len - 1] ==
'/');
496 const char *fmt =
"%s/%s";
497 if (!f_set || !d_set || slash)
516 const char *fname,
size_t fnamelen)
522 if ((dirlen != 0) && (fnamelen != 0))
572 if (!src || !src->
data)
589 if (buf && (offset <
buf_len(buf)))
607 return strstr(buf->
data, s);
622 return strchr(buf->
data, c);
634 if (!buf || (offset >
buf_len(buf)))
637 return buf->
data[offset];
bool buf_istr_equal(struct Buffer *a, struct Buffer *b)
Return if two buffers are equal, case insentive.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
char buf_at(struct Buffer *buf, size_t offset)
Return the character at the given offset.
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.
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?
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
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.
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
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.
const char * buf_find_string(struct Buffer *buf, const char *s)
Return a pointer to a substring found in the buffer.
bool buf_str_equal(struct Buffer *a, struct Buffer *b)
Return if two buffers are equal.
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
void buf_upper(struct Buffer *buf)
Sets a buffer to uppercase.
const char * buf_find_char(struct Buffer *buf, const char c)
Return a pointer to a char found in the 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.
int buf_coll(struct Buffer *a, struct Buffer *b)
Collate two strings (compare using locale)
struct Buffer * buf_dup(const struct Buffer *buf)
Copy a Buffer into a new allocated 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_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.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Memory management wrappers.
#define ROUND_UP(NUM, STEP)
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
void mutt_str_dequote_comment(char *str)
Un-escape characters in an email address comment.
char * mutt_str_dup(const char *str)
Copy a string, safely.
char * mutt_str_upper(char *str)
Convert all characters in the string to uppercase.
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_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.