|
The types, constants and functions that constitute the cstring API.
Modules | |
Function Control Flags | |
These flags control the behaviour of the various functions in the library. | |
Classes | |
struct | cstring_t |
The cstring structure. More... | |
Defines | |
#define | cstring_t_DEFAULT { 0, NULL, 0, 0 } |
Default initialised value for a cstring_t instance. | |
Typedefs | |
typedef int | cstring_flags_t |
Flags type. | |
Enumerations | |
enum | CSTRING_RC { CSTRING_RC_SUCCESS = 0, CSTRING_RC_OUTOFMEMORY, CSTRING_RC_FIXED, CSTRING_RC_BORROWED, CSTRING_RC_READONLY, CSTRING_RC_INVALIDARENA, CSTRING_RC_CUSTOMARENANOTSUPPORTED, CSTRING_RC_EXCEEDFIXEDCAPACITY, CSTRING_RC_EXCEEDBORROWEDCAPACITY, CSTRING_RC_CANNOTYIELDFROMSO, CSTRING_RC_ARENAOVERLOADED, CSTRING_RC_INVALIDSTREAM, CSTRING_RC_EOF, CSTRING_RC_INVALIDSECTION, CSTRING_RC_IOERROR, CSTRING_RC_SYSTEMSPECIFICFAILURE } |
The return code type of the cstring API. More... | |
Functions | |
CSTRING_EXTERN_C char const * | cstring_getStatusCodeString (CSTRING_RC rc) |
Returns a non-NULL nul-terminated character string describing the given error code. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_init (struct cstring_t *pcs) |
Initialises a cstring instance to a default form. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_create (struct cstring_t *pcs, char const *s) |
Creates a cstring instance from a C-style string. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_createLen (struct cstring_t *pcs, char const *s, size_t cch) |
Creates a cstring instance from a fixed number of characters. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_createN (struct cstring_t *pcs, char ch, size_t n) |
Creates a cstring instance consisting of a number of repetitions of a character. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_createEx (struct cstring_t *pcs, char const *s, cstring_flags_t flags, void *arena, size_t capacity) |
Creates a cstring instance with special characteristics from a C-style string. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_createLenEx (struct cstring_t *pcs, char const *s, size_t cch, cstring_flags_t flags, void *arena, size_t capacity) |
Creates a cstring instance with special characteristics from a fixed number of characters. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_destroy (struct cstring_t *pcs) |
Releases resources and resets the attributes of the cstring instance. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_yield2 (struct cstring_t *pcs, char **pPayload, void **pRaw) |
Removes the allocated buffer from the cstring instance into a caller supplied pointer. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_setCapacity (struct cstring_t *pcs, size_t capacity) |
Sets the capacity of the cstring instance. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_assign (struct cstring_t *pcs, char const *s) |
Assigns a C-style string to the cstring instance. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_assignLen (struct cstring_t *pcs, char const *s, size_t cch) |
Assigns a fixed number of characters to the cstring instance. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_copy (struct cstring_t *pcs, struct cstring_t const *pcsSrc) |
Copies the contents of one cstring instance to another. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_append (struct cstring_t *pcs, char const *s) |
Appends a C-style string to the cstring instance. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_appendLen (struct cstring_t *pcs, char const *s, size_t cch) |
Appends a fixed number of characters to the cstring instance. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_truncate (struct cstring_t *pcs, size_t len) |
Truncates the cstring instance. | |
CSTRING_EXTERN_C CSTRING_RC | cstring_swap (struct cstring_t *pcs1, struct cstring_t *pcs2) |
Swaps the contents of the two cstring instances. |
#define cstring_t_DEFAULT { 0, NULL, 0, 0 } |
Default initialised value for a cstring_t instance.
typedef int cstring_flags_t |
Flags type.
enum CSTRING_RC |
The return code type of the cstring API.
CSTRING_EXTERN_C CSTRING_RC cstring_append | ( | struct cstring_t * | pcs, | |
char const * | s | |||
) |
Appends a C-style string to the cstring instance.
pcs | The cstring to append to | |
s | Pointer to the C-style string to append. May be NULL |
CSTRING_RC_SUCCESS | the requested number of bytes were appended to the cstring | |
CSTRING_RC_READONLY | the cstring instance is marked readonly (CSTRING_F_MEMORY_IS_READONLY) | |
CSTRING_RC_EXCEEDFIXEDCAPACITY | the cstring instance is marked fixed (CSTRING_F_MEMORY_IS_FIXED) | |
CSTRING_RC_EXCEEDBORROWEDCAPACITY | the cstring instance is marked borrowed (CSTRING_F_MEMORY_IS_BORROWED) | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation |
CSTRING_EXTERN_C CSTRING_RC cstring_appendLen | ( | struct cstring_t * | pcs, | |
char const * | s, | |||
size_t | cch | |||
) |
Appends a fixed number of characters to the cstring instance.
pcs | The cstring to append to | |
s | Pointer to the first character in the array from which to append. Must not be NULL, unless cch is 0 | |
cch | The number of characters to append |
CSTRING_RC_SUCCESS | the requested number of bytes were appended to the cstring | |
CSTRING_RC_READONLY | the cstring instance is marked readonly (CSTRING_F_MEMORY_IS_READONLY) | |
CSTRING_RC_EXCEEDFIXEDCAPACITY | the cstring instance is marked fixed (CSTRING_F_MEMORY_IS_FIXED) | |
CSTRING_RC_EXCEEDBORROWEDCAPACITY | the cstring instance is marked borrowed (CSTRING_F_MEMORY_IS_BORROWED) | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation |
CSTRING_EXTERN_C CSTRING_RC cstring_assign | ( | struct cstring_t * | pcs, | |
char const * | s | |||
) |
Assigns a C-style string to the cstring instance.
pcs | The cstring to assign to | |
s | Pointer to the C-style string to assign. May be NULL |
CSTRING_RC_SUCCESS | the requested number of bytes were assigned to the cstring | |
CSTRING_RC_READONLY | the cstring instance is marked readonly (CSTRING_F_MEMORY_IS_READONLY) | |
CSTRING_RC_EXCEEDFIXEDCAPACITY | the cstring instance is marked fixed (CSTRING_F_MEMORY_IS_FIXED) | |
CSTRING_RC_EXCEEDBORROWEDCAPACITY | the cstring instance is marked borrowed (CSTRING_F_MEMORY_IS_BORROWED) | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation |
s
can refer to (part of) the payload of pcs
, and the function will still operate correctly to produce the logically desired result. CSTRING_EXTERN_C CSTRING_RC cstring_assignLen | ( | struct cstring_t * | pcs, | |
char const * | s, | |||
size_t | cch | |||
) |
Assigns a fixed number of characters to the cstring instance.
pcs | The cstring to assign to | |
s | Pointer to the first character in the array from which to assign. Must not be NULL, unless cch is 0 | |
cch | The number of characters to assign |
CSTRING_RC_SUCCESS | the requested number of bytes were assigned to the cstring | |
CSTRING_RC_READONLY | the cstring instance is marked readonly (CSTRING_F_MEMORY_IS_READONLY) | |
CSTRING_RC_EXCEEDFIXEDCAPACITY | the cstring instance is marked fixed (CSTRING_F_MEMORY_IS_FIXED) | |
CSTRING_RC_EXCEEDBORROWEDCAPACITY | the cstring instance is marked borrowed (CSTRING_F_MEMORY_IS_BORROWED) | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation |
CSTRING_EXTERN_C CSTRING_RC cstring_copy | ( | struct cstring_t * | pcs, | |
struct cstring_t const * | pcsSrc | |||
) |
Copies the contents of one cstring instance to another.
pcs | The cstring to assign to | |
pcsSrc | The cstring whose contents will be copied |
CSTRING_RC_SUCCESS | the requested number of bytes were copied to the cstring | |
CSTRING_RC_READONLY | the cstring instance is marked readonly (CSTRING_F_MEMORY_IS_READONLY) | |
CSTRING_RC_EXCEEDFIXEDCAPACITY | the cstring instance is marked fixed (CSTRING_F_MEMORY_IS_FIXED) | |
CSTRING_RC_EXCEEDBORROWEDCAPACITY | the cstring instance is marked borrowed (CSTRING_F_MEMORY_IS_BORROWED) | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation |
CSTRING_EXTERN_C CSTRING_RC cstring_create | ( | struct cstring_t * | pcs, | |
char const * | s | |||
) |
Creates a cstring instance from a C-style string.
pcs | The uninitialised cstring instance to be created | |
s | Pointer to the C-style string to copy. May be NULL |
CSTRING_RC_SUCCESS | the capacity was adjusted | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation |
CSTRING_EXTERN_C CSTRING_RC cstring_createEx | ( | struct cstring_t * | pcs, | |
char const * | s, | |||
cstring_flags_t | flags, | |||
void * | arena, | |||
size_t | capacity | |||
) |
Creates a cstring instance with special characteristics from a C-style string.
pcs | The uninitialised cstring instance to be created | |
s | Pointer to the C-style string to copy. May be NULL | |
flags | The flags defining the characteristics of the cstring instance | |
arena | The memory buffer for borrowed (CSTRING_F_MEMORY_IS_BORROWED), or a pointer to a custom memory arena. Note that custom memory arenas are not currently supported, and this parameter must be NULL unless the flag CSTRING_F_MEMORY_IS_BORROWED is specified | |
capacity | The capacity of the buffer specified in arena , or otherwise ignored |
CSTRING_RC_SUCCESS | the capacity was adjusted | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation | |
CSTRING_RC_INVALIDARENA | an invalid arena specification was given in the flags parameter | |
CSTRING_RC_CUSTOMARENANOTSUPPORTED | A custom arena was specified, which is not yet supported |
CSTRING_EXTERN_C CSTRING_RC cstring_createLen | ( | struct cstring_t * | pcs, | |
char const * | s, | |||
size_t | cch | |||
) |
Creates a cstring instance from a fixed number of characters.
pcs | The uninitialised cstring instance to be created | |
s | Pointer to the first character in the array from which to copy. Must not be NULL, unless cch is 0 | |
cch | The number of characters to be copied into the cstring instance |
CSTRING_RC_SUCCESS | the capacity was adjusted | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation |
CSTRING_EXTERN_C CSTRING_RC cstring_createLenEx | ( | struct cstring_t * | pcs, | |
char const * | s, | |||
size_t | cch, | |||
cstring_flags_t | flags, | |||
void * | arena, | |||
size_t | capacity | |||
) |
Creates a cstring instance with special characteristics from a fixed number of characters.
pcs | The uninitialised cstring instance to be created | |
s | Pointer to the first character in the array from which to copy. Must not be NULL, unless cch is 0 | |
cch | The number of characters to be copied into the cstring instance | |
flags | The flags defining the characteristics of the cstring instance | |
arena | The memory buffer for borrowed (CSTRING_F_MEMORY_IS_BORROWED), or a pointer to a custom memory arena. Note that custom memory arenas are not currently supported, and this parameter must be NULL unless the flag CSTRING_F_MEMORY_IS_BORROWED is specified | |
capacity | The capacity of the buffer specified in arena , or otherwise ignored |
CSTRING_RC_SUCCESS | the capacity was adjusted | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation | |
CSTRING_RC_INVALIDARENA | an invalid arena specification was given in the flags parameter | |
CSTRING_RC_CUSTOMARENANOTSUPPORTED | A custom arena was specified, which is not yet supported |
CSTRING_EXTERN_C CSTRING_RC cstring_createN | ( | struct cstring_t * | pcs, | |
char | ch, | |||
size_t | n | |||
) |
Creates a cstring instance consisting of a number of repetitions of a character.
pcs | The uninitialised cstring instance to be created | |
ch | The character to be repeated | |
n | The number of repetitions of character c |
CSTRING_RC_SUCCESS | the capacity was adjusted | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation |
CSTRING_EXTERN_C CSTRING_RC cstring_destroy | ( | struct cstring_t * | pcs | ) |
Releases resources and resets the attributes of the cstring instance.
pcs | The cstring instance to be destroyed |
CSTRING_RC_SUCCESS | the capacity was destroyed |
CSTRING_EXTERN_C char const* cstring_getStatusCodeString | ( | CSTRING_RC | rc | ) |
Returns a non-NULL nul-terminated character string describing the given error code.
rc | The error code. Must be one of the CSTRING_RC enumeration |
CSTRING_EXTERN_C CSTRING_RC cstring_init | ( | struct cstring_t * | pcs | ) |
Initialises a cstring instance to a default form.
This is equivalent to assigning an instance from cstring_t_DEFAULT.
CSTRING_EXTERN_C CSTRING_RC cstring_setCapacity | ( | struct cstring_t * | pcs, | |
size_t | capacity | |||
) |
Sets the capacity of the cstring instance.
pcs | The cstring instance to be adjusted | |
capacity | The capacity to which the cstring instance should be adjusted |
CSTRING_RC_SUCCESS | the capacity was adjusted | |
CSTRING_RC_READONLY | the cstring instance is marked readonly (CSTRING_F_MEMORY_IS_READONLY) | |
CSTRING_RC_EXCEEDFIXEDCAPACITY | the cstring instance is marked fixed (CSTRING_F_MEMORY_IS_FIXED) | |
CSTRING_RC_EXCEEDBORROWEDCAPACITY | the cstring instance is marked borrowed (CSTRING_F_MEMORY_IS_BORROWED) | |
CSTRING_RC_OUTOFMEMORY | insufficient memory to carry out the operation |
CSTRING_EXTERN_C CSTRING_RC cstring_swap | ( | struct cstring_t * | pcs1, | |
struct cstring_t * | pcs2 | |||
) |
Swaps the contents of the two cstring instances.
pcs1 | the cstring instance whose contents will be swapped with pcs2 | |
pcs2 | the cstring instance whose contents will be swapped with pcs1 |
CSTRING_RC_SUCCESS | string instance contents were swapped | |
CSTRING_RC_READONLY | one or both instances are marked readonly (CSTRING_F_MEMORY_IS_READONLY) | |
CSTRING_RC_BORROWED | one or both instances are marked fixed (CSTRING_F_MEMORY_IS_BORROWED) |
CSTRING_EXTERN_C CSTRING_RC cstring_truncate | ( | struct cstring_t * | pcs, | |
size_t | len | |||
) |
Truncates the cstring instance.
pcs | The cstring to truncate | |
len | The required length. Ignored if not less than the current length |
CSTRING_RC_SUCCESS | cstring instance contents were truncated (or the truncation length was out of bounds) | |
CSTRING_RC_READONLY | the cstring instance is marked readonly (CSTRING_F_MEMORY_IS_READONLY) |
CSTRING_EXTERN_C CSTRING_RC cstring_yield2 | ( | struct cstring_t * | pcs, | |
char ** | pPayload, | |||
void ** | pRaw | |||
) |
Removes the allocated buffer from the cstring instance into a caller supplied pointer.
pcs | the cstring instance whose buffer is to be retrieved. May not be NULL. | |
pRaw | pointer to a buffer pointer which will receive the yielded raw memory. May not be NULL. May not be equal to pPayload. | |
pPayload | pointer to a buffer pointer which will receive the yielded payload. May not be NULL. May not be equal to pRaw. |
CSTRING_RC_SUCCESS | the buffer was yielded | |
CSTRING_RC_READONLY | the cstring instance is marked readonly (CSTRING_F_MEMORY_IS_READONLY) | |
CSTRING_RC_BORROWED | the cstring instance is marked fixed (CSTRING_F_MEMORY_IS_BORROWED) | |
CSTRING_RC_CANNOTYIELDFROMSO | the cstring instance uses realloc() in a Win32 dynamic library |
|
cstring Library documentation (c) Matthew Wilson and Synesis Software Pty Ltd, 1994-2009 |