Skip to content

synesissoftware/cstring

Repository files navigation

cstring

Language License GitHub release Last Commit CMake on multiple platforms

Extensible dynamic character strings - and arrays of strings - in C, for Unix and Windows.

Table of Contents

Introduction

C-style strings is a small, standalone library, that provides extensible C-style string instances and extensible arrays of such.

Installation

ctring comes with CMake configuration/build files.

Components

API / core library

The C API is based around two structures:

  • cstring_t, which represents a resizeable string instance; and
    struct 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 of cstring_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 to cstring_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 a char 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

Examples are provided in the examples directory, along with a markdown description for each.

Project Information

Where to get help

GitHub Page

Contribution guidelines

Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/cstring.

Dependencies

Tests-only Dependencies

For unit-testing, cstring depends on:

Related projects

Projects in which cstring is used include:

License

cstring is released under the 3-clause BSD license. See LICENSE for details.

About

Extensible strings and string-arrays for C

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •