NeoMutt  2023-11-03-107-g582dc1
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
buffer.h File Reference

General purpose object for storing and parsing strings. More...

#include <stddef.h>
#include <stdbool.h>
+ Include dependency graph for buffer.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Buffer
 String manipulation buffer. More...
 

Functions

struct Bufferbuf_new (const char *str)
 Allocate a new Buffer.
 
void buf_free (struct Buffer **ptr)
 Deallocates a buffer.
 
void buf_alloc (struct Buffer *buf, size_t size)
 Make sure a buffer can store at least new_size bytes.
 
void buf_dealloc (struct Buffer *buf)
 Release the memory allocated by a buffer.
 
void buf_fix_dptr (struct Buffer *buf)
 Move the dptr to end of the Buffer.
 
struct Bufferbuf_init (struct Buffer *buf)
 Initialise a new Buffer.
 
bool buf_is_empty (const struct Buffer *buf)
 Is the Buffer empty?
 
size_t buf_len (const struct Buffer *buf)
 Calculate the length of a Buffer.
 
struct Buffer buf_make (size_t size)
 Make a new buffer on the stack.
 
void buf_reset (struct Buffer *buf)
 Reset an existing Buffer.
 
char * buf_strdup (const struct Buffer *buf)
 Copy a Buffer's string.
 
struct Bufferbuf_dup (const struct Buffer *buf)
 Copy a Buffer into a new allocated buffer.
 
void buf_seek (struct Buffer *buf, size_t offset)
 Set current read/write position to offset from beginning.
 
const char * buf_find_string (const struct Buffer *buf, const char *s)
 Return a pointer to a substring found in the buffer.
 
const char * buf_find_char (const struct Buffer *buf, const char c)
 Return a pointer to a char found in the buffer.
 
char buf_at (const struct Buffer *buf, size_t offset)
 Return the character at the given offset.
 
bool buf_str_equal (const struct Buffer *a, const struct Buffer *b)
 Return if two buffers are equal.
 
bool buf_istr_equal (const struct Buffer *a, const struct Buffer *b)
 Return if two buffers are equal, case insensitive.
 
int buf_coll (const struct Buffer *a, const struct Buffer *b)
 Collate two strings (compare using locale)
 
size_t buf_startswith (const struct Buffer *buf, const char *prefix)
 Check whether a buffer starts with a prefix.
 
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.
 
size_t buf_addstr_n (struct Buffer *buf, const char *s, size_t len)
 Add a string to a Buffer, expanding it if necessary.
 
int buf_add_printf (struct Buffer *buf, const char *fmt,...) __attribute__((__format__(__printf__
 
int size_t buf_insert (struct Buffer *buf, size_t offset, const char *s)
 Add a string in the middle of a buffer.
 
size_t buf_concat_path (struct Buffer *buf, const char *dir, const char *fname)
 Join a directory name and a filename.
 
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.
 
size_t buf_copy (struct Buffer *dst, const struct Buffer *src)
 Copy a Buffer's contents to another Buffer.
 
int buf_printf (struct Buffer *buf, const char *fmt,...) __attribute__((__format__(__printf__
 
int size_t buf_strcpy (struct Buffer *buf, const char *s)
 Copy a string into a Buffer.
 
size_t buf_strcpy_n (struct Buffer *buf, const char *s, size_t len)
 Copy a string into a Buffer.
 
size_t buf_substrcpy (struct Buffer *buf, const char *beg, const char *end)
 Copy a partial string into a Buffer.
 
void buf_dequote_comment (struct Buffer *buf)
 Un-escape characters in an email address comment.
 
void buf_lower (struct Buffer *buf)
 Sets a buffer to lowercase.
 
void buf_upper (struct Buffer *buf)
 Sets a buffer to uppercase.
 
static const char * buf_string (const struct Buffer *buf)
 Convert a buffer to a const char * "string".
 

Detailed Description

General purpose object for storing and parsing strings.

Authors
  • Ian Zimmerman
  • Richard Russon

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.

Function Documentation

◆ buf_new()

struct Buffer * buf_new ( const char *  str)

Allocate a new Buffer.

Parameters
strString to initialise the buffer with, can be NULL
Return values
ptrPointer to new buffer

Definition at line 316 of file buffer.c.

317{
318 struct Buffer *buf = mutt_mem_calloc(1, sizeof(struct Buffer));
319
320 if (str)
321 buf_addstr(buf, str);
322 else
323 buf_alloc(buf, 1);
324 return buf;
325}
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:238
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:349
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
String manipulation buffer.
Definition: buffer.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_free()

void buf_free ( struct Buffer **  ptr)

Deallocates a buffer.

Parameters
ptrBuffer to free

Definition at line 331 of file buffer.c.

332{
333 if (!ptr || !*ptr)
334 return;
335
336 struct Buffer *buf = *ptr;
337 buf_dealloc(buf);
338
339 FREE(ptr);
340}
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:389
#define FREE(x)
Definition: memory.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_alloc()

void buf_alloc ( struct Buffer buf,
size_t  new_size 
)

Make sure a buffer can store at least new_size bytes.

Parameters
bufBuffer to change
new_sizeNew size
Note
new_size will be rounded up to BufferStepSize

Definition at line 349 of file buffer.c.

350{
351 if (!buf)
352 return;
353
354 if (buf->data && (new_size <= buf->dsize))
355 {
356 // Extra sanity-checking
357 if (!buf->dptr || (buf->dptr < buf->data) || (buf->dptr > (buf->data + buf->dsize)))
358 buf->dptr = buf->data; // LCOV_EXCL_LINE
359 return;
360 }
361
362 if (new_size > (SIZE_MAX - BufferStepSize))
363 {
364 // LCOV_EXCL_START
365 mutt_error(_("Out of memory"));
366 mutt_exit(1);
367 // LCOV_EXCL_STOP
368 }
369
370 const bool was_empty = (buf->dptr == NULL);
371 const size_t offset = (buf->dptr && buf->data) ? (buf->dptr - buf->data) : 0;
372
373 buf->dsize = ROUND_UP(new_size + 1, BufferStepSize);
374
375 mutt_mem_realloc(&buf->data, buf->dsize);
376 buf->dptr = buf->data + offset;
377
378 // Ensures that initially NULL buf->data is properly terminated
379 if (was_empty)
380 {
381 *buf->dptr = '\0';
382 }
383}
static const int BufferStepSize
When increasing the size of a Buffer, add this much extra space.
Definition: buffer.c:46
#define mutt_error(...)
Definition: logging2.h:92
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:228
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define ROUND_UP(NUM, STEP)
Definition: memory.h:36
#define _(a)
Definition: message.h:28
char * dptr
Current read/write position.
Definition: buffer.h:36
size_t dsize
Length of data.
Definition: buffer.h:37
char * data
Pointer to data.
Definition: buffer.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_dealloc()

void buf_dealloc ( struct Buffer buf)

Release the memory allocated by a buffer.

Parameters
bufBuffer to change

Definition at line 389 of file buffer.c.

390{
391 if (!buf || !buf->data)
392 return;
393
394 buf->dptr = NULL;
395 buf->dsize = 0;
396 FREE(&buf->data);
397}
+ Here is the caller graph for this function:

◆ buf_fix_dptr()

void buf_fix_dptr ( struct Buffer buf)

Move the dptr to end of the Buffer.

Parameters
bufBuffer to alter

Ensure buffer->dptr points to the end of the buffer.

Definition at line 194 of file buffer.c.

195{
196 if (!buf)
197 return;
198
199 buf_seek(buf, 0);
200
201 if (buf->data && (buf->dsize > 0))
202 {
203 buf->data[buf->dsize - 1] = '\0';
204 buf->dptr = strchr(buf->data, '\0');
205 }
206}
void buf_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
Definition: buffer.c:593
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_init()

struct Buffer * buf_init ( struct Buffer buf)

Initialise a new Buffer.

Parameters
bufBuffer to initialise
Return values
ptrInitialised Buffer

This must not be called on a Buffer that already contains data.

Definition at line 55 of file buffer.c.

56{
57 if (!buf)
58 return NULL;
59 memset(buf, 0, sizeof(struct Buffer));
60 return buf;
61}
+ Here is the caller graph for this function:

◆ buf_is_empty()

bool buf_is_empty ( const struct Buffer buf)

Is the Buffer empty?

Parameters
bufBuffer to inspect
Return values
trueBuffer is empty

Definition at line 303 of file buffer.c.

304{
305 if (!buf || !buf->data)
306 return true;
307
308 return (buf->data[0] == '\0');
309}

◆ buf_len()

size_t buf_len ( const struct Buffer buf)

Calculate the length of a Buffer.

Parameters
bufBuffer
Return values
numSize of buffer

Definition at line 466 of file buffer.c.

467{
468 if (!buf || !buf->data || !buf->dptr)
469 return 0;
470
471 return buf->dptr - buf->data;
472}
+ Here is the caller graph for this function:

◆ buf_make()

struct Buffer buf_make ( size_t  size)

Make a new buffer on the stack.

Parameters
sizeInitial size
Return values
objInitialized buffer

The buffer must be released using buf_dealloc

Definition at line 70 of file buffer.c.

71{
72 struct Buffer buf = { 0 };
73 if (size != 0)
74 {
75 buf.dptr = buf.data = mutt_mem_calloc(1, size);
76 buf.dsize = size;
77 }
78 return buf;
79}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_reset()

void buf_reset ( struct Buffer buf)

Reset an existing Buffer.

Parameters
bufBuffer to reset

This can be called on a Buffer to reset the pointers, effectively emptying it.

Definition at line 88 of file buffer.c.

89{
90 if (!buf || !buf->data || (buf->dsize == 0))
91 return;
92 memset(buf->data, 0, buf->dsize);
93 buf_seek(buf, 0);
94}
+ Here is the call graph for this function:

◆ buf_strdup()

char * buf_strdup ( const struct Buffer buf)

Copy a Buffer's string.

Parameters
bufBuffer to copy
Return values
ptrCopy of string
Note
Caller must free the returned string

Definition at line 542 of file buffer.c.

543{
544 if (!buf)
545 return NULL;
546
547 return mutt_str_dup(buf->data);
548}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
+ Here is the call graph for this function:

◆ buf_dup()

struct Buffer * buf_dup ( const struct Buffer buf)

Copy a Buffer into a new allocated buffer.

Parameters
bufBuffer to copy
Return values
bufNew allocated copy of buffer
Note
Caller must free the returned buffer

Definition at line 557 of file buffer.c.

558{
559 if (!buf)
560 return NULL;
561
562 return buf_new(buf_string(buf));
563}
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition: buffer.c:316
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_seek()

void buf_seek ( struct Buffer buf,
size_t  offset 
)

Set current read/write position to offset from beginning.

Parameters
bufBuffer to use
offsetDistance 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 593 of file buffer.c.

594{
595 if (buf && (offset < buf_len(buf)))
596 {
597 buf->dptr = buf->data ? buf->data + offset : NULL;
598 }
599}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:466
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_find_string()

const char * buf_find_string ( const struct Buffer buf,
const char *  s 
)

Return a pointer to a substring found in the buffer.

Parameters
bufBuffer to search
sSubstring to find
Return values
NULLsubstring not found
nPointer to the beginning of the found substring

Definition at line 608 of file buffer.c.

609{
610 if (!buf || !s)
611 return NULL;
612
613 return strstr(buf->data, s);
614}
+ Here is the caller graph for this function:

◆ buf_find_char()

const char * buf_find_char ( const struct Buffer buf,
const char  c 
)

Return a pointer to a char found in the buffer.

Parameters
bufBuffer to search
cChar to find
Return values
NULLchar not found
ptrPointer to the found char

Definition at line 623 of file buffer.c.

624{
625 if (!buf)
626 return NULL;
627
628 return strchr(buf->data, c);
629}
+ Here is the caller graph for this function:

◆ buf_at()

char buf_at ( const struct Buffer buf,
size_t  offset 
)

Return the character at the given offset.

Parameters
bufBuffer to search
offsetOffset to get
Return values
NULOffset out of bounds
Returns
n The char at the offset

Definition at line 638 of file buffer.c.

639{
640 if (!buf || (offset > buf_len(buf)))
641 return '\0';
642
643 return buf->data[offset];
644}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_str_equal()

bool buf_str_equal ( const struct Buffer a,
const struct Buffer b 
)

Return if two buffers are equal.

Parameters
a- Buffer to compare
b- Buffer to compare
Return values
trueStrings are equal
falseString are not equal

Definition at line 653 of file buffer.c.

654{
655 return mutt_str_equal(buf_string(a), buf_string(b));
656}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:763
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_istr_equal()

bool buf_istr_equal ( const struct Buffer a,
const struct Buffer b 
)

Return if two buffers are equal, case insensitive.

Parameters
a- First buffer to compare
b- Second buffer to compare
Return values
trueStrings are equal
falseString are not equal

Definition at line 665 of file buffer.c.

666{
668}
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:775
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_coll()

int buf_coll ( const struct Buffer a,
const struct Buffer b 
)

Collate two strings (compare using locale)

Parameters
aFirst buffer to compare
bSecond buffer to compare
Return values
<0a precedes b
0a and b are identical
>0b precedes a

Definition at line 690 of file buffer.c.

691{
692 return mutt_str_coll(buf_string(a), buf_string(b));
693}
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:581
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_startswith()

size_t buf_startswith ( const struct Buffer buf,
const char *  prefix 
)

Check whether a buffer starts with a prefix.

Parameters
bufBuffer to check
prefixPrefix to match
Return values
numLength of prefix if str starts with prefix
0str does not start with prefix

Definition at line 677 of file buffer.c.

678{
679 return mutt_str_startswith(buf_string(buf), prefix);
680}
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:228
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_addch()

size_t buf_addch ( struct Buffer buf,
char  c 
)

Add a single character to a Buffer.

Parameters
bufBuffer to add to
cCharacter to add
Return values
numBytes written to Buffer

If necessary, the Buffer will be expanded.

Definition at line 253 of file buffer.c.

254{
255 if (!buf)
256 return 0;
257 return buf_addstr_n(buf, &c, 1);
258}
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:108
+ Here is the call graph for this function:

◆ buf_addstr()

size_t buf_addstr ( struct Buffer buf,
const char *  s 
)

Add a string to a Buffer.

Parameters
bufBuffer to add to
sString to add
Return values
numBytes written to Buffer

If necessary, the Buffer will be expanded.

Definition at line 238 of file buffer.c.

239{
240 if (!buf || !s)
241 return 0;
242 return buf_addstr_n(buf, s, mutt_str_len(s));
243}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:568
+ Here is the call graph for this function:

◆ buf_addstr_n()

size_t buf_addstr_n ( struct Buffer buf,
const char *  s,
size_t  len 
)

Add a string to a Buffer, expanding it if necessary.

Parameters
bufBuffer to add to
sString to add
lenLength of the string
Return values
numBytes written to Buffer
0Error

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 108 of file buffer.c.

109{
110 if (!buf || !s)
111 return 0;
112
113 if (len > (SIZE_MAX - BufferStepSize))
114 {
115 // LCOV_EXCL_START
116 mutt_error(_("Out of memory"));
117 mutt_exit(1);
118 // LCOV_EXCL_STOP
119 }
120
121 if (!buf->data || !buf->dptr || ((buf->dptr + len + 1) > (buf->data + buf->dsize)))
122 buf_alloc(buf, buf->dsize + MAX(BufferStepSize, len + 1));
123
124 memcpy(buf->dptr, s, len);
125 buf->dptr += len;
126 *(buf->dptr) = '\0';
127 return len;
128}
#define MAX(a, b)
Definition: memory.h:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_add_printf()

int buf_add_printf ( struct Buffer buf,
const char *  fmt,
  ... 
)

◆ buf_insert()

int size_t buf_insert ( struct Buffer buf,
size_t  offset,
const char *  s 
)

Add a string in the middle of a buffer.

Parameters
bufBuffer
offsetPosition for the insertion
sString to insert
Return values
numCharacters written
-1Error

Definition at line 268 of file buffer.c.

269{
270 if (!buf || !s || (*s == '\0'))
271 {
272 return -1;
273 }
274
275 const size_t slen = mutt_str_len(s);
276 const size_t curlen = buf_len(buf);
277 buf_alloc(buf, curlen + slen + 1);
278
279 if (offset > curlen)
280 {
281 for (size_t i = curlen; i < offset; ++i)
282 {
283 buf_addch(buf, ' ');
284 }
285 buf_addstr(buf, s);
286 }
287 else
288 {
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;
293 }
294
295 return buf_len(buf) - curlen;
296}
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:253
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_concat_path()

size_t buf_concat_path ( struct Buffer buf,
const char *  dir,
const char *  fname 
)

Join a directory name and a filename.

Parameters
bufBuffer to add to
dirDirectory name
fnameFile name
Return values
numBytes 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 484 of file buffer.c.

485{
486 if (!buf)
487 return 0;
488
489 if (!dir)
490 dir = "";
491 if (!fname)
492 fname = "";
493
494 const bool d_set = (dir[0] != '\0');
495 const bool f_set = (fname[0] != '\0');
496 if (!d_set && !f_set)
497 return 0;
498
499 const int d_len = strlen(dir);
500 const bool slash = d_set && (dir[d_len - 1] == '/');
501
502 const char *fmt = "%s/%s";
503 if (!f_set || !d_set || slash)
504 fmt = "%s%s";
505
506 return buf_printf(buf, fmt, dir, fname);
507}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:173
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_concatn_path()

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.

Parameters
bufBuffer for the result
dirDirectory name
dirlenDirectory name
fnameFile name
fnamelenFile name
Return values
numSize 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 521 of file buffer.c.

523{
524 size_t len = 0;
525 buf_reset(buf);
526 if (dirlen != 0)
527 len += buf_addstr_n(buf, dir, dirlen);
528 if ((dirlen != 0) && (fnamelen != 0))
529 len += buf_addch(buf, '/');
530 if (fnamelen != 0)
531 len += buf_addstr_n(buf, fname, fnamelen);
532 return len;
533}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:88
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_copy()

size_t buf_copy ( struct Buffer dst,
const struct Buffer src 
)

Copy a Buffer's contents to another Buffer.

Parameters
dstBuffer for result
srcBuffer to copy
Return values
numBytes written to Buffer
0Error

Definition at line 572 of file buffer.c.

573{
574 if (!dst)
575 return 0;
576
577 buf_reset(dst);
578 if (!src || !src->data)
579 return 0;
580
581 return buf_addstr_n(dst, src->data, buf_len(src));
582}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_printf()

int buf_printf ( struct Buffer buf,
const char *  fmt,
  ... 
)

◆ buf_strcpy()

int size_t buf_strcpy ( struct Buffer buf,
const char *  s 
)

Copy a string into a Buffer.

Parameters
bufBuffer to overwrite
sString to copy
Return values
numBytes written to Buffer

Overwrites any existing content.

Definition at line 407 of file buffer.c.

408{
409 buf_reset(buf);
410 return buf_addstr(buf, s);
411}
+ Here is the call graph for this function:

◆ buf_strcpy_n()

size_t buf_strcpy_n ( struct Buffer buf,
const char *  s,
size_t  len 
)

Copy a string into a Buffer.

Parameters
bufBuffer to overwrite
sString to copy
lenLength of string to copy
Return values
numBytes written to Buffer

Overwrites any existing content.

Definition at line 422 of file buffer.c.

423{
424 buf_reset(buf);
425 return buf_addstr_n(buf, s, len);
426}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_substrcpy()

size_t buf_substrcpy ( struct Buffer buf,
const char *  beg,
const char *  end 
)

Copy a partial string into a Buffer.

Parameters
bufBuffer to overwrite
begStart of string to copy
endEnd of string to copy
Return values
numBytes written to Buffer

Overwrites any existing content.

Definition at line 452 of file buffer.c.

453{
454 buf_reset(buf);
455 if (end <= beg)
456 return 0;
457
458 return buf_strcpy_n(buf, beg, end - beg);
459}
size_t buf_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
Definition: buffer.c:422
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_dequote_comment()

void buf_dequote_comment ( struct Buffer buf)

Un-escape characters in an email address comment.

Parameters
bufBuffer to be un-escaped
Note
the buffer is modified

Definition at line 434 of file buffer.c.

435{
436 if (!buf)
437 return;
438
440 buf_fix_dptr(buf);
441}
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:194
void mutt_str_dequote_comment(char *str)
Un-escape characters in an email address comment.
Definition: string.c:731
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_lower()

void buf_lower ( struct Buffer buf)

Sets a buffer to lowercase.

Parameters
[out]bufBuffer to transform to lowercase
Note
Modifies the buffer

Definition at line 701 of file buffer.c.

702{
703 if (!buf)
704 return;
705
706 mutt_str_lower(buf->data);
707}
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
Definition: string.c:385
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_upper()

void buf_upper ( struct Buffer buf)

Sets a buffer to uppercase.

Parameters
[out]bufBuffer to transform to uppercase
Note
Modifies the buffer

Definition at line 715 of file buffer.c.

716{
717 if (!buf)
718 return;
719
720 mutt_str_upper(buf->data);
721}
char * mutt_str_upper(char *str)
Convert all characters in the string to uppercase.
Definition: string.c:408
+ Here is the call graph for this function:

◆ buf_string()

static const char * buf_string ( const struct Buffer buf)
inlinestatic

Convert a buffer to a const char * "string".

Parameters
bufBuffer to that is to be converted
Return values
ptrString inside the Buffer

This method exposes Buffer's underlying data field

Note
Returns an empty string if Buffer isn't initialised

Definition at line 93 of file buffer.h.

94{
95 if (!buf || !buf->data)
96 return "";
97
98 return buf->data;
99}