Character Buffer

Character buffer data structure, for simpler string handling.

Ring buffer data structure, for nice dequeues.

Author
Stephen Brennan
Date
Saturday, 23 May 2015
Copyright
Copyright (c) 2015-2016, Stephen Brennan. Released under the Revised BSD License. See the LICENSE.txt for details.
Author
Stephen Brennan
Date
Monday, 8 August 2016
Copyright
Copyright (c) 2016, Stephen Brennan. Released under the Revised BSD License. See the LICENSE.txt for details.

Functions

void cb_init(cbuf * obj, int capacity)

Initialize a brand-new character buffer.

A buffer of the given capacity is initialized, and given an empty string value.

Parameters
  • obj: The cbuf to initialize.
  • capacity: Initial capacity of the buffer.

cbuf* cb_create(int capacity)

Allocate and initialize a brand-new character buffer.

A buffer of the given capacity is initialized, and given an empty string value. The cbuf struct is also allocated and the pointer returned.

Parameters
  • capacity: Initial capacity of the buffer.

void cb_destroy(cbuf * obj)

Deallocate the contents of the string buffer.

Parameters
  • obj: The character buffer to deallocate.

void cb_delete(cbuf * obj)

Deallocate the contents of, and delete the string buffer.

Parameters
  • obj: The character buffer to delete.

void cb_concat(cbuf * obj, char * str)

Concat a string onto the end of the character buffer.

Parameters
  • obj: The buffer to concat onto.
  • str: The string to concat.

void cb_append(cbuf * obj, char next)

Append a character onto the end of the character buffer.

Parameters
  • obj: The buffer to append onto.
  • next: The character to append.

void cb_trim(cbuf * obj)

Reallocate the buffer to the exact size of the contained string.

Parameters
  • obj: The buffer to reallocate.

void cb_clear(cbuf * obj)

Empty the buffer of its contents.

Parameters
  • obj: The buffer to clear.

void cb_printf(cbuf * obj, char * format, ...)

Format and print a string onto the end of a character buffer.

Parameters
  • obj: The object to print onto.
  • format: The format string to print.
  • ...: The arguments to the format string.

void cb_vprintf(cbuf * obj, char * format, va_list va)

Format and print a string onto the cbuf using a va_list.

Parameters
  • obj: The cbuf to print into.
  • format: The format string to print.
  • va: The vararg list.

void wcb_init(wcbuf * obj, int capacity)

Initialize a string buffer to a given capacity.

Parameters
  • obj: The string buffer to initialize.
  • capacity: The initial capacity to give it.

wcbuf* wcb_create(int capacity)

Initialize a string buffer and allocate the struct as well.

Return
A pointer to the buffer.
Parameters
  • capacity: The capacity of the string buffer to create.

void wcb_destroy(wcbuf * obj)

Destroy the wide buffer contained in the wcbuf struct.

Parameters
  • obj: The wide buffer to destroy.

void wcb_delete(wcbuf * obj)

Destroy and delete the wide buffer and struct.

Parameters
  • obj: The wide buffer struct to destroy.

void wcb_concat(wcbuf * obj, wchar_t * str)

Concat a wide character string into the wide buffer.

Parameters
  • obj: The wide buffer to concat onto.
  • str: The wide string to concat on.

void wcb_append(wcbuf * obj, wchar_t next)

Append a single character onto the buffer.

Parameters
  • obj: The wide buffer to append onto.
  • next: The wide character to append.

void wcb_trim(wcbuf * obj)

Reallocate the buffer to the exact size of the contained string.

Parameters
  • obj: The buffer to reallocate.

void wcb_clear(wcbuf * obj)

Empty the buffer of its contents.

Parameters
  • obj: The buffer to clear.

void wcb_printf(wcbuf * obj, wchar_t * format, ...)

Printf a wide character string onto the wide buffer.

Parameters
  • obj: The wide buffer to printf onto.
  • format: Format string to print.
  • ...: The arguments to to put into the format string.

void wcb_vprintf(wcbuf * obj, wchar_t * format, va_list va)

Format and print a string onto the wcbuf using a va_list.

Parameters
  • obj: The wcbuf to print into.
  • format: The format string to print.
  • va: The vararg list.

struct cbuf
#include <cb.h>

A character buffer utility that is easier to handle than a char*.

This character buffer provides an interface for string processing that allows you to be efficient, while not needing to handle nearly as much of the allocations that are necessary. It automatically expands as you add to it.

Public Members

char* buf

Buffer pointer.

int capacity

Allocated size of the buffer.

int length

Length of the string in the buffer.

struct wcbuf
#include <cb.h>

A wide character buffer. Similar to cbuf.

Again, this buffer provides an interface for simpler string manipulation, by managing the buffer reallocations for you. Of course, the difference being that this one is for wide characters.

Public Members

wchar_t* buf

Buffer pointer.

int capacity

Actual capacity of the buffer.

int length

Length of the string in the buffer.