Herb C Reference
Loading...
Searching...
No Matches
buffer.h File Reference
#include <stdbool.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  BUFFER_STRUCT
 

Typedefs

typedef struct BUFFER_STRUCT buffer_T
 

Functions

bool buffer_init (buffer_T *buffer)
 
buffer_T buffer_new (void)
 
bool buffer_increase_capacity (buffer_T *buffer, size_t required_length)
 Increases the capacity of the buffer if needed to accommodate additional content.
 
bool buffer_reserve (buffer_T *buffer, size_t min_capacity)
 
void buffer_append (buffer_T *buffer, const char *text)
 Appends a null-terminated string to the buffer.
 
void buffer_append_with_length (buffer_T *buffer, const char *text, size_t length)
 Appends a string of specified length to the buffer.
 
void buffer_append_char (buffer_T *buffer, char character)
 
void buffer_append_repeated (buffer_T *buffer, char character, size_t length)
 
void buffer_append_whitespace (buffer_T *buffer, size_t length)
 
void buffer_prepend (buffer_T *buffer, const char *text)
 
void buffer_concat (buffer_T *destination, buffer_T *source)
 
char * buffer_value (const buffer_T *buffer)
 
size_t buffer_length (const buffer_T *buffer)
 
size_t buffer_capacity (const buffer_T *buffer)
 
size_t buffer_sizeof (void)
 
void buffer_clear (buffer_T *buffer)
 
void buffer_free (buffer_T *buffer)
 

Typedef Documentation

◆ buffer_T

typedef struct BUFFER_STRUCT buffer_T

Function Documentation

◆ buffer_init()

bool buffer_init ( buffer_T buffer)

◆ buffer_new()

buffer_T buffer_new ( void  )

◆ buffer_increase_capacity()

bool buffer_increase_capacity ( buffer_T buffer,
const size_t  required_length 
)

Increases the capacity of the buffer if needed to accommodate additional content.

This function only handles memory allocation and does not modify the buffer content or null termination.

Parameters
bufferThe buffer to increase capacity for
required_lengthThe additional length needed beyond current buffer length
Returns
true if capacity is sufficient (either already or after reallocation), false if reallocation failed

◆ buffer_reserve()

bool buffer_reserve ( buffer_T buffer,
size_t  min_capacity 
)

◆ buffer_append()

void buffer_append ( buffer_T buffer,
const char *  text 
)

Appends a null-terminated string to the buffer.

Note
This function requires that 'text' is a properly null-terminated string. When reading data from files or other non-string sources, ensure the data is null-terminated before calling this function, or use buffer_append_with_length instead.
Parameters
bufferThe buffer to append to
textA null-terminated string to append
Returns
void

◆ buffer_append_with_length()

void buffer_append_with_length ( buffer_T buffer,
const char *  text,
const size_t  length 
)

Appends a string of specified length to the buffer.

Unlike buffer_append(), this function does not require the text to be null-terminated as it uses the provided length instead of strlen(). This is particularly useful when working with data from files, network buffers, or other non-null-terminated sources.

Parameters
bufferThe buffer to append to
textThe text to append (doesn't need to be null-terminated)
lengthThe number of bytes to append from text
Returns
void

◆ buffer_append_char()

void buffer_append_char ( buffer_T buffer,
char  character 
)

◆ buffer_append_repeated()

void buffer_append_repeated ( buffer_T buffer,
char  character,
size_t  length 
)

◆ buffer_append_whitespace()

void buffer_append_whitespace ( buffer_T buffer,
size_t  length 
)

◆ buffer_prepend()

void buffer_prepend ( buffer_T buffer,
const char *  text 
)

◆ buffer_concat()

void buffer_concat ( buffer_T destination,
buffer_T source 
)

◆ buffer_value()

char * buffer_value ( const buffer_T buffer)

◆ buffer_length()

size_t buffer_length ( const buffer_T buffer)

◆ buffer_capacity()

size_t buffer_capacity ( const buffer_T buffer)

◆ buffer_sizeof()

size_t buffer_sizeof ( void  )

◆ buffer_clear()

void buffer_clear ( buffer_T buffer)

◆ buffer_free()

void buffer_free ( buffer_T buffer)