O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
to_string.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
7/* */
14/* ************************************************************************** */
15
16#include "o2s/to_string.h"
17
18#include "private.h"
19
20#include <iso646.h> // not
21
24{
25 string_t result = string_from_literal("[");
26 const void* element = self->start;
27
28 while (element < array_end(self))
29 {
30 String single = convert_element(element);
31
32 string_append(&result, &single);
33 string_append_literal(&result, ", ");
34 element += array_offset(self, 1);
35 }
36 if (not array_is_empty(self))
37 string_pop_n(&result, NULL, 2);
38 string_append_literal(&result, "]");
39 return result;
40}
bool array_is_empty(const array_t *self)
True if the array contains no element.
Definition getters.c:64
void * array_end(const array_t *self)
One-past-the-end pointer of the array.
Definition getters.c:25
Internal state of a dynamic array.
string_t array_to_string(const array_t *self, string_conversion_t convert_element)
Create a string from an array.
Definition to_string.c:23
size_t array_offset(const array_t *self, size_t count)
The size in memory of count elements.
Definition memory.c:23
#define string_append_literal(Self, StringLiteral)
Copy the content of a C string to the end of this string.
Definition string.h:81
#define string_from_literal(StringLiteral)
Allocates a string, copying the content from a C string.
Definition string.h:45
array_t string_t
A string is an array of char.
Definition string.h:30
#define String
Automatically free the allocated storage when going out of scope.
Definition string.h:63
O2S array implementation.
Definition array.h:24
void * start
Underlying storage.
Definition array.h:25
Create strings from data structures.
string_t(* string_conversion_t)(const void *element)
Designate functions that create a string from the address of a value.
Definition to_string.h:25