Extensible dynamic character strings - and arrays of strings - in C, for Unix and Windows.
C-style strings is a small, standalone library, that provides extensible C-style string instances and extensible arrays of such.
ctring comes with CMake configuration/build files.
The C API is based around two structures:
cstring_t
, which represents a resizeable string instance; andstruct cstring_t { size_t len; /*!< Number of characters. */ cstring_char_t* ptr; /*!< Pointer to the string. If capacity is 0, the value of this member is undetermined. */ size_t capacity; /*!< Number of bytes available. */ cstring_flags_t flags; /*!< Flags. This field belongs to the implementation, and must not be modified by any application code. */ };
cstring_vector_t
, which represents a sequence ofcstring_t
instances;struct cstring_vector_t { size_t len; /*!< Number of strings. */ cstring_t* ptr; /*!< Pointer to the first string. If capacity is 0, the value of this member is undetermined. */ size_t capacity; /*!< Number of instances available. */ cstring_flags_t flags; /*!< Flags. This field belongs to the implementation, and must not be modified by any application code. */ };
the structure, defined as follows:
Creation/destruction functions:
cstring_init()
- initialises an instance to default values (and does not required a following call tocstring_destroy()
);cstring_create()
- creates an instance from a C-style string;cstring_createLen()
- creates an instance from a (portion of a) C-style string;cstring_createN()
- creates an instance from a a number of repetitions of achar
value;cstring_createEx()
- creates an instance with special characteristics (such as using stack memory, ...);cstring_createExLen()
- creates an instance with special characteristics (such as using stack memory, ...);cstring_destroy()
Modification functions:
cstring_assign()
- T.B.C.;cstring_assignLen()
- T.B.C.;cstring_copy()
- T.B.C.;cstring_append()
- T.B.C.;cstring_appendLen()
- T.B.C.;cstring_insert()
- T.B.C.;cstring_insertLen()
- T.B.C.;cstring_replace()
- T.B.C.;cstring_replaceLen()
- T.B.C.;cstring_replaceAll()
- T.B.C.;cstring_truncate()
- T.B.C.;cstring_swap()
- T.B.C.;
File functions:
cstring_readline()
- reads in a line of text from the given text stream;cstring_write()
- writes a string to the given text stream;cstring_writeline()
- writes a line of text to the given text stream;
Examples are provided in the examples
directory, along with a markdown description for each.
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/cstring.
For unit-testing, cstring depends on:
Projects in which cstring is used include:
cstring is released under the 3-clause BSD license. See LICENSE for details.