Examples for using the string builder.
Examples for using the string builder.
#include <stdio.h>
#define ALLOC stdalloc
#define NAME string_builder
DC_SCOPED(string_builder) sb = string_builder_new(stdalloc_get_ref());
fprintf(string_builder_stream(&sb), "Hello, world!");
printf("%s\n", string_builder_string(&sb));
}
#define KEY uint32_t
#define KEY_HASH DC_DEFAULT_HASH
#define VALUE char const*
#define NAME id_map
DC_SCOPED(id_map) map = id_map_new(stdalloc_get_ref());
id_map_insert(&map, 1, "Alice");
id_map_insert(&map, 2, "Bob");
id_map_insert(&map, 3, "Charlie");
DC_SCOPED(string_builder) sb = string_builder_new(stdalloc_get_ref());
fprintf(string_builder_stream(&sb), "the identities are: ");
printf("%s\n", string_builder_string(&sb));
}
#define NAME dbg
#define CAPACITY 256
#define ALLOC dbg
#define NAME hybrid
#define ALLOC hybrid
#define NAME string_builder_hybrid
DC_SCOPED(dbg) debug_alloc = dbg_new(
"hybrid_example", stdout, stdalloc_get_ref());
hybrid_buffer buf;
DC_SCOPED(hybrid) hybrid_alloc = hybrid_new(&buf, &debug_alloc);
DC_SCOPED(string_builder_hybrid) sb = string_builder_hybrid_new(&hybrid_alloc);
fprintf(string_builder_hybrid_stream(&sb), "This is a small sentence.");
printf("%s\n", string_builder_hybrid_string(&sb));
}
return 0;
}
static void example_basic()
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_new()
#define DC_SCOPED(type,...)
RAII in C. Call the destructor when the variable goes out of scope.
static void example_hybrid()
static void example_data_structure()