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 <iso646.h> // not
19
22{
23 string_t result = string_from_literal("[");
24
25 for (unsigned i = 0; i < deque_count(self); i++)
26 {
27 String single = convert_element(deque_get(self, i));
28
29 string_append(&result, &single);
30 string_append_literal(&result, ", ");
31 }
32 if (not deque_is_empty(self))
33 string_pop_n(&result, NULL, 2);
34 string_append_literal(&result, "]");
35 return result;
36}
bool deque_is_empty(const deque_t *self)
True if no elements are currently stored.
Definition getters.c:57
size_t deque_count(const deque_t *self)
The number of elements currently held in the queue.
Definition getters.c:22
void * deque_get(const deque_t *self, size_t index)
The element of the element at an arbitrary index.
Definition getters.c:72
string_t deque_to_string(const deque_t *self, string_conversion_t convert_element)
Create a string that represents a deque.
Definition to_string.c:21
#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
Double-ended queue.
Definition deque.h:27
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