Skip to content

About

dynamic_string is a pure C dynamic string library that provides common string operations while always maintaining a valid null-terminated C string.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

English | 简体中文

dynamic_string

C Standard CMake GitHub License CI

dynamic_string is a pure C implementation of a dynamic string abstract data type (ADT). It provides a rich set of string operations—including creation, concatenation, searching, replacement, and formatting—while always maintaining a valid null-terminated (\0) C string underneath, focusing on text processing rather than binary safety.

Table of Contents

API ↑

This library provides a rich and complete API, organized into the following groups:

  • Creation and Destruction: Create, Destroy, Clone.
  • Property Accessors: Get C-String, Get Length, Get Capacity, Set Capacity.
  • Content Editing: Copy, Append, Insert, Remove.
  • Relations and Comparison: Prefix/Suffix Check, Contains Check, Size Comparison.
  • Search, Count and Replace.
  • Split and Join.

See the API Reference for the complete reference of every function.

Use in Other Projects ↑

Add Dependencies ↑

CPM.cmake ↑

Requirements: CPM.cmake.

In your CMakeLists.txt:

include(${PROJECT_SOURCE_DIR}/cmake/CPM.cmake)

CPMAddPackage("gh:mtueih/dynamic_string#v3.0.0")

CMake find_package (must be installed) ↑

In your CMakeLists.txt:

find_package(dynamic_string REQUIRED)

Link the Library ↑

In your CMakeLists.txt:

target_link_libraries(your_target PRIVATE dynamic_string::dynamic_string)

Use in Code ↑

Include Header Files ↑

#include <dynamic_string/dynamic_string.h>

Use the Library Functions ↑

#include <dynamic_string/dynamic_string.h>
#include <stdio.h>

int main(void)
{
    /* Create a dynamic string. */
    dstr_adt *s = dstr_create("Hello");
    if (s == NULL)
    {
        return 1;
    }

    /* Append a string. */
    if (dstr_cat_cstr(s, ", World!") != DSTR_SUCCESS)
    {
        dstr_destroy(s);
        return 1;
    }

    /* Append using a format string. */
    if (dstr_cat_format(s, " num=%d", 42) != DSTR_SUCCESS)
    {
        dstr_destroy(s);
        return 1;
    }

    /* Print the result. */
    printf("%s\n", dstr_cstr(s)); /* "Hello, World! num=42". */
    printf("length: %zu\n", dstr_length(s));

    /* Destroy. */
    dstr_destroy(s);
    return 0;
}

Build from Source ↑

Requirements ↑

Build Steps ↑

Clone the Repository ↑

git clone https://github.com/mtueih/dynamic_string.git --depth 1 -b v3.0.0
cd dynamic_string

Configure, Build and Install ↑

cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DDYNAMIC_STRING_INSTALL=ON
cmake --build build --config Release --parallel
cmake --install build --config Release --strip --prefix install

Notes on the commands above:

  • The install command. Using --prefix install installs the artifacts into the install directory instead of installing them globally, so you can use the artifacts in your own way. To install globally, simply remove it.

License ↑

This project is licensed under the ISC License — see the LICENSE file for details.

About

dynamic_string is a pure C dynamic string library that provides common string operations while always maintaining a valid null-terminated C string.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages