General purpose object for storing and parsing strings. More...
#include <stddef.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | Buffer |
String manipulation buffer. More... | |
Functions | |
void | mutt_buffer_alloc (struct Buffer *buf, size_t size) |
Make sure a buffer can store at least new_size bytes. More... | |
void | mutt_buffer_dealloc (struct Buffer *buf) |
Release the memory allocated by a buffer. More... | |
void | mutt_buffer_fix_dptr (struct Buffer *buf) |
Move the dptr to end of the Buffer. More... | |
struct Buffer * | mutt_buffer_init (struct Buffer *buf) |
Initialise a new Buffer. More... | |
bool | mutt_buffer_is_empty (const struct Buffer *buf) |
Is the Buffer empty? More... | |
size_t | mutt_buffer_len (const struct Buffer *buf) |
Calculate the length of a Buffer. More... | |
struct Buffer | mutt_buffer_make (size_t size) |
Make a new buffer on the stack. More... | |
void | mutt_buffer_reset (struct Buffer *buf) |
Reset an existing Buffer. More... | |
char * | mutt_buffer_strdup (const struct Buffer *buf) |
Copy a Buffer's string. More... | |
void | mutt_buffer_seek (struct Buffer *buf, size_t offset) |
Set current read/write position to offset from beginning. More... | |
size_t | mutt_buffer_addch (struct Buffer *buf, char c) |
Add a single character to a Buffer. More... | |
size_t | mutt_buffer_addstr (struct Buffer *buf, const char *s) |
Add a string to a Buffer. More... | |
size_t | mutt_buffer_addstr_n (struct Buffer *buf, const char *s, size_t len) |
Add a string to a Buffer, expanding it if necessary. More... | |
int | mutt_buffer_add_printf (struct Buffer *buf, const char *fmt,...) |
Format a string appending a Buffer. More... | |
size_t | mutt_buffer_insert (struct Buffer *buf, size_t offset, const char *s) |
Add a string in the middle of a buffer. More... | |
size_t | mutt_buffer_concat_path (struct Buffer *buf, const char *dir, const char *fname) |
Join a directory name and a filename. More... | |
size_t | mutt_buffer_concatn_path (struct Buffer *dst, const char *dir, size_t dirlen, const char *fname, size_t fnamelen) |
Join a directory name and a filename. More... | |
size_t | mutt_buffer_copy (struct Buffer *dst, const struct Buffer *src) |
Copy a Buffer's contents to another Buffer. More... | |
int | mutt_buffer_printf (struct Buffer *buf, const char *fmt,...) |
Format a string overwriting a Buffer. More... | |
size_t | mutt_buffer_strcpy (struct Buffer *buf, const char *s) |
Copy a string into a Buffer. More... | |
size_t | mutt_buffer_strcpy_n (struct Buffer *buf, const char *s, size_t len) |
Copy a string into a Buffer. More... | |
size_t | mutt_buffer_substrcpy (struct Buffer *buf, const char *beg, const char *end) |
Copy a partial string into a Buffer. More... | |
static const char * | mutt_buffer_string (const struct Buffer *buf) |
Convert a buffer to a const char * "string". More... | |
General purpose object for storing and parsing strings.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file buffer.h.
void mutt_buffer_alloc | ( | struct Buffer * | buf, |
size_t | new_size | ||
) |
Make sure a buffer can store at least new_size bytes.
buf | Buffer to change |
new_size | New size |
Definition at line 313 of file buffer.c.
void mutt_buffer_dealloc | ( | struct Buffer * | buf | ) |
void mutt_buffer_fix_dptr | ( | struct Buffer * | buf | ) |
Move the dptr to end of the Buffer.
buf | Buffer to alter |
Ensure buffer->dptr points to the end of the buffer.
Definition at line 189 of file buffer.c.
bool mutt_buffer_is_empty | ( | const struct Buffer * | buf | ) |
size_t mutt_buffer_len | ( | const struct Buffer * | buf | ) |
struct Buffer mutt_buffer_make | ( | size_t | size | ) |
Make a new buffer on the stack.
size | Initial size |
buf | Initialized buffer |
The buffer must be released using mutt_buffer_dealloc
Definition at line 67 of file buffer.c.
void mutt_buffer_reset | ( | struct Buffer * | buf | ) |
char * mutt_buffer_strdup | ( | const struct Buffer * | buf | ) |
void mutt_buffer_seek | ( | struct Buffer * | buf, |
size_t | offset | ||
) |
Set current read/write position to offset from beginning.
buf | Buffer to use |
offset | Distance from the beginning |
This is used for cases where the buffer is read from A value is placed in the buffer, and then b->dptr is set back to the beginning as a read marker instead of write marker.
Definition at line 521 of file buffer.c.
size_t mutt_buffer_addch | ( | struct Buffer * | buf, |
char | c | ||
) |
Add a single character to a Buffer.
buf | Buffer to add to |
c | Character to add |
num | Bytes written to Buffer |
If necessary, the Buffer will be expanded.
Definition at line 248 of file buffer.c.
size_t mutt_buffer_addstr | ( | struct Buffer * | buf, |
const char * | s | ||
) |
Add a string to a Buffer.
buf | Buffer to add to |
s | String to add |
num | Bytes written to Buffer |
If necessary, the Buffer will be expanded.
Definition at line 233 of file buffer.c.
size_t mutt_buffer_addstr_n | ( | struct Buffer * | buf, |
const char * | s, | ||
size_t | len | ||
) |
Add a string to a Buffer, expanding it if necessary.
buf | Buffer to add to |
s | String to add |
len | Length of the string |
num | Bytes written to Buffer |
0 | Error |
Dynamically grow a Buffer to accommodate s, in increments of 128 bytes. Always one byte bigger than necessary for the null terminator, and the buffer is always NUL-terminated
Definition at line 105 of file buffer.c.
int mutt_buffer_add_printf | ( | struct Buffer * | buf, |
const char * | fmt, | ||
... | |||
) |
Format a string appending a Buffer.
buf | Buffer |
fmt | printf-style format string |
... | Arguments to be formatted |
num | Characters written |
-1 | Error |
Definition at line 211 of file buffer.c.
size_t mutt_buffer_insert | ( | struct Buffer * | buf, |
size_t | offset, | ||
const char * | s | ||
) |
Add a string in the middle of a buffer.
buf | Buffer |
offset | Position for the insertion |
s | String to insert |
num | Characters written |
-1 | Error |
Definition at line 263 of file buffer.c.
size_t mutt_buffer_concat_path | ( | struct Buffer * | buf, |
const char * | dir, | ||
const char * | fname | ||
) |
Join a directory name and a filename.
buf | Buffer to add to |
dir | Directory name |
fname | File name |
num | Bytes written to Buffer |
If both dir and fname are supplied, they are separated with '/'. If either is missing, then the other will be copied exactly.
Definition at line 427 of file buffer.c.
size_t mutt_buffer_concatn_path | ( | struct Buffer * | buf, |
const char * | dir, | ||
size_t | dirlen, | ||
const char * | fname, | ||
size_t | fnamelen | ||
) |
Join a directory name and a filename.
buf | Buffer for the result |
dir | Directory name |
dirlen | Directory name |
fname | File name |
fnamelen | File name |
num | Size of buffer |
If both dir and fname are supplied, they are separated with '/'. If either is missing, then the other will be copied exactly.
Definition at line 464 of file buffer.c.
Copy a Buffer's contents to another Buffer.
num | Bytes written to Buffer |
0 | Error |
Definition at line 500 of file buffer.c.
int mutt_buffer_printf | ( | struct Buffer * | buf, |
const char * | fmt, | ||
... | |||
) |
Format a string overwriting a Buffer.
buf | Buffer |
fmt | printf-style format string |
... | Arguments to be formatted |
num | Characters written |
-1 | Error |
Definition at line 168 of file buffer.c.
size_t mutt_buffer_strcpy | ( | struct Buffer * | buf, |
const char * | s | ||
) |
size_t mutt_buffer_strcpy_n | ( | struct Buffer * | buf, |
const char * | s, | ||
size_t | len | ||
) |
Copy a string into a Buffer.
buf | Buffer to overwrite |
s | String to copy |
len | Length of string to copy |
num | Bytes written to Buffer |
Overwrites any existing content.
Definition at line 380 of file buffer.c.
size_t mutt_buffer_substrcpy | ( | struct Buffer * | buf, |
const char * | beg, | ||
const char * | end | ||
) |
Copy a partial string into a Buffer.
buf | Buffer to overwrite |
beg | Start of string to copy |
end | End of string to copy |
num | Bytes written to Buffer |
Overwrites any existing content.
Definition at line 395 of file buffer.c.
|
inlinestatic |