32 if (not string_reserve(&result, 20))
34 const int size = snprintf(result.
start, result.
capacity,
"%g", *value);
36 result.
count = (unsigned)size;
45 if (not string_reserve(&result, 20))
47 const int size = snprintf(result.
start, result.
capacity,
"%lg", *value);
49 result.
count = (unsigned)size;
59 if (not string_reserve(&result, maxsize))
61 const int size = snprintf(result.
start, maxsize,
"%i", *value);
63 result.
count = (unsigned)size;
73 if (not string_reserve(&result, maxsize))
75 const int size = snprintf(result.
start, maxsize,
"%hi", *value);
77 result.
count = (unsigned)size;
87 if (not string_reserve(&result, maxsize))
89 const int size = snprintf(result.
start, maxsize,
"%li", *value);
91 result.
count = (unsigned)size;
101 if (not string_reserve(&result, maxsize))
103 const int size = snprintf(result.
start, maxsize,
"%u", *value);
105 result.
count = (unsigned)size;
118 return string_from(*value, strlen(*value));
132 string_append_char(&result, value);
135 string_append_char(&result,
'\\');
139 string_append_char(&result,
'0');
142 string_append_char(&result,
't');
145 string_append_char(&result,
'n');
148 string_append_char(&result,
'r');
151 string_append_char(&result,
'x');
153 string_append_char(&result,
"0123456789abcdef"[value >> 4]);
154 string_append_char(&result,
"0123456789abcdef"[value & 0xf]);
157 string_append_char(&result,
'\'');
169 return value ?
"true" :
"false";
#define LIBO2S_PREPRO_STRING(EXPRESSION)
Create a string literal from the evaluation of its argument.
Dynamic string implementation.
string_t string_new(void)
Constructs an empty string.
#define string_from_literal(StringLiteral)
Allocates a string, copying the content from a C string.
array_t string_t
A string is an array of char.
void * start
Underlying storage.
size_t count
Number of elements currently stored.
size_t capacity
Number of elements that can fit in the storage.
string_t int_to_string(const int *value)
Create a string from an integer.
string_t float_to_string(const float *value)
Create a sring from a float.
const char * boolean_to_cstring(bool value)
Null-temrminated string from a boolean.
string_t double_to_string(const double *value)
Create a string from a double.
string_t char_to_string(const char *c)
Creates a string to represent the char pointed to by c.
string_t cstring_to_string(const char *const *value)
Create a string from a null-terminated character string.
string_t short_to_string(const short *value)
Create a string from a short integer.
string_t unsigned_to_string(const unsigned *value)
Create a string from an unsigned integer.
string_t long_to_string(const long *value)
Create a string from a long integer.
Create strings from data structures.