Derive-C
Loading...
Searching...
No Matches
string_builder.c File Reference

Go to the source code of this file.

Macros

#define ALLOC   stdalloc
#define NAME   string_builder
#define KEY   uint32_t
#define KEY_HASH   DC_DEFAULT_HASH
#define VALUE   char const*
#define NAME   id_map
#define NAME   dbg
#define CAPACITY   256
#define ALLOC   dbg
#define NAME   hybrid
#define ALLOC   hybrid
#define NAME   string_builder_hybrid

Functions

static void example_basic ()
static void example_data_structure ()
static void example_hybrid ()
int main ()

Macro Definition Documentation

◆ ALLOC [1/3]

#define ALLOC   hybrid

Definition at line 10 of file string_builder.c.

◆ ALLOC [2/3]

#define ALLOC   dbg

Definition at line 10 of file string_builder.c.

◆ ALLOC [3/3]

#define ALLOC   stdalloc

Definition at line 10 of file string_builder.c.

◆ CAPACITY

#define CAPACITY   256

Definition at line 48 of file string_builder.c.

◆ KEY

#define KEY   uint32_t

Definition at line 23 of file string_builder.c.

◆ KEY_HASH

#define KEY_HASH   DC_DEFAULT_HASH

Definition at line 24 of file string_builder.c.

◆ NAME [1/5]

#define NAME   string_builder_hybrid

Definition at line 11 of file string_builder.c.

◆ NAME [2/5]

#define NAME   hybrid

Definition at line 11 of file string_builder.c.

◆ NAME [3/5]

#define NAME   dbg

Definition at line 11 of file string_builder.c.

◆ NAME [4/5]

#define NAME   id_map

Definition at line 11 of file string_builder.c.

◆ NAME [5/5]

#define NAME   string_builder

Definition at line 11 of file string_builder.c.

◆ VALUE

#define VALUE   char const*

Definition at line 25 of file string_builder.c.

Function Documentation

◆ example_basic()

void example_basic ( )
static

Definition at line 14 of file string_builder.c.

14 {
16 DC_SCOPED(string_builder) sb = string_builder_new(stdalloc_get_ref());
17
18 fprintf(string_builder_stream(&sb), "Hello, world!");
19
20 printf("%s\n", string_builder_string(&sb));
21}
#define DC_SCOPED(type,...)
RAII in C. Call the destructor when the variable goes out of scope.
Definition scope.h:5
#define DC_DEBUG_TRACE
Definition debug.h:17

◆ example_data_structure()

void example_data_structure ( )
static
Examples
utils/string_builder.c.

Definition at line 29 of file string_builder.c.

29 {
31 DC_SCOPED(id_map) map = id_map_new(stdalloc_get_ref());
32
33 id_map_insert(&map, 1, "Alice");
34 id_map_insert(&map, 2, "Bob");
35 id_map_insert(&map, 3, "Charlie");
36
37 DC_SCOPED(string_builder) sb = string_builder_new(stdalloc_get_ref());
38
39 fprintf(string_builder_stream(&sb), "the identities are: ");
40 id_map_debug(&map, dc_debug_fmt_new(), string_builder_stream(&sb));
41
42 printf("%s\n", string_builder_string(&sb));
43}
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_new()
Definition fmt.h:15

◆ example_hybrid()

void example_hybrid ( )
static
Examples
utils/string_builder.c.

Definition at line 57 of file string_builder.c.

57 {
59 DC_SCOPED(dbg) debug_alloc = dbg_new("hybrid_example", stdout, stdalloc_get_ref());
60 hybrid_buffer buf;
61 DC_SCOPED(hybrid) hybrid_alloc = hybrid_new(&buf, &debug_alloc);
62 DC_SCOPED(string_builder_hybrid) sb = string_builder_hybrid_new(&hybrid_alloc);
63
64 fprintf(string_builder_hybrid_stream(&sb), "This is a small sentence.");
65
66 printf("%s\n", string_builder_hybrid_string(&sb));
67}

◆ main()

int main ( )

Definition at line 69 of file string_builder.c.

69 {
73 return 0;
74}
static void example_basic()
static void example_hybrid()
static void example_data_structure()