Home

String builder

String builder similar to Go's implemented as a single-header library à la stb.

source

Usage

        #define SB_IMPLEMENTATION
        #include "sb.h"

        string_builder sb = {0};
        sb_init(&sb);

        sb_write(&sb, "Hello, ");
        sb_writef(&sb, "%s%c", "World", '!');

        puts(sb.buf); // Prints "Hello, World!"

        // The buffer can also be returned as an allocated string:
        char *s = sb_to_string(&sb);
        puts(s);
        free(s); // The caller is responsible for freeing it.

        sb_deinit(&sb);