Small, Fast S-Expression Library
Data Structures | Typedefs | Functions
cstring.h File Reference
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  __cstring
 

Typedefs

typedef struct __cstring CSTRING
 

Functions

void sgrowsize (size_t s)
 
CSTRINGsnew (size_t s)
 
CSTRINGsadd (CSTRING *s, char *a)
 
CSTRINGsaddch (CSTRING *s, char a)
 
CSTRINGstrim (CSTRING *s)
 
char * toCharPtr (CSTRING *s)
 
void sempty (CSTRING *s)
 
void sdestroy (CSTRING *s)
 

Typedef Documentation

◆ CSTRING

typedef struct __cstring CSTRING

cstring.h : c string library to make Ron happy. Wrapper around plain C strings that handles automatically growing the string as data is concattenated to the end. (note: this is an improved version of cstring from supermon. Migrate it into that library eventually... )

-matt sottile Structure wrapping the character pointer and size counters (allocated vs. actual used).

Function Documentation

◆ sadd()

CSTRING* sadd ( CSTRING s,
char *  a 
)

Concatenate the second argument to the CSTRING passed in the first. The second argument must be a pointer to a null terminated string. A NULL return value indicates that something went wrong and that sexp_errno should be checked for the cause. The contents of s are left alone. As such, the caller should check the pointer returned before overwriting the value of s, as this may result in a memory leak if an error condition occurs.

◆ saddch()

CSTRING* saddch ( CSTRING s,
char  a 
)

Append a character to the end of the CSTRING. A NULL return value indicates that something went wrong and that sexp_errno should be checked for the cause. The contents of s are left alone. As such, the caller should check the pointer returned before overwriting the value of s, as this may result in a memory leak if an error condition occurs.

◆ sdestroy()

void sdestroy ( CSTRING s)

Destroy the CSTRING struct and the data it points at.

◆ sempty()

void sempty ( CSTRING s)

Set the current length to zero, effectively dumping the string without deallocating it so we can use it later without reallocating any memory.

◆ sgrowsize()

void sgrowsize ( size_t  s)

Set the growth size. Values less than one are ignored.

◆ snew()

CSTRING* snew ( size_t  s)

Allocate a new CSTRING of the given size. A NULL return value indicates that something went wrong and that sexp_errno should be checked for the cause.

◆ strim()

CSTRING* strim ( CSTRING s)

Trim the allocated memory to precisely the string length plus one char to hold the null terminator A NULL return value indicates that something went wrong and that sexp_errno should be checked for the cause. The contents of s are left alone. As such, the caller should check the pointer returned before overwriting the value of s, as this may result in a memory leak if an error condition occurs.

◆ toCharPtr()

char* toCharPtr ( CSTRING s)

Return the base pointer of the CSTRING. NULL either means the base pointer was null, or the CSTRING itself was NULL.