Herb C Reference
Loading...
Searching...
No Matches
buffer.c File Reference
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "include/buffer.h"
#include "include/macros.h"
#include "include/memory.h"
#include "include/util.h"

Functions

bool buffer_init (buffer_T *buffer)
 
buffer_T buffer_new (void)
 
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)
 
bool buffer_increase_capacity (buffer_T *buffer, const size_t required_length)
 Increases the capacity of the buffer if needed to accommodate additional content.
 
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, const size_t length)
 Appends a string of specified length to the buffer.
 
void buffer_append_char (buffer_T *buffer, const char character)
 
void buffer_append_repeated (buffer_T *buffer, const char character, size_t length)
 
void buffer_append_whitespace (buffer_T *buffer, const size_t length)
 
void buffer_prepend (buffer_T *buffer, const char *text)
 
void buffer_concat (buffer_T *destination, buffer_T *source)
 
bool buffer_reserve (buffer_T *buffer, const size_t min_capacity)
 
void buffer_clear (buffer_T *buffer)
 
void buffer_free (buffer_T *buffer)
 

Function Documentation

◆ buffer_init()

bool buffer_init ( buffer_T buffer)

◆ buffer_new()

buffer_T buffer_new ( void  )

◆ 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_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_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,
const char  character 
)

◆ buffer_append_repeated()

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

◆ buffer_append_whitespace()

void buffer_append_whitespace ( buffer_T buffer,
const 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_reserve()

bool buffer_reserve ( buffer_T buffer,
const size_t  min_capacity 
)

◆ buffer_clear()

void buffer_clear ( buffer_T buffer)

◆ buffer_free()

void buffer_free ( buffer_T buffer)