Offers formatted output to string_t.
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2012 Jörg Seebohn
Header file FormatString.
Implementation file FormatString impl.
test | |
unittest_string_format | Tests formatted output to string_t. |
int unittest_string_format( void )
Tests formatted output to string_t.
struct string_field_t
val | Type of the string field. |
val | Value of the field to be formatted. |
lifetime | |
string_field_INIT_EMPTY | Static initializer. |
initstring_stringfield | Inits string_field_t describing a string value. |
initfloat_stringfield | Inits string_field_t describing a float value. |
initdouble_stringfield | Inits string_field_t describing a double value. |
Type of the string field. For supported values see string_field_e.
int initstring_stringfield( /*out*/string_field_t * strfield, struct string_t * strval )
Inits string_field_t describing a string value.
int initfloat_stringfield( /*out*/string_field_t * strfield, float fval )
Inits string_field_t describing a float value.
int initdouble_stringfield( /*out*/string_field_t * strfield, double dval )
Inits string_field_t describing a double value.
query | |
sizeformat_string | Returns in string_t.size the size of the formatted output fields. |
format | |
format_string | Writes formatted output to string_t. |
int sizeformat_string( /*out*/struct string_t * str, int dummy )
Returns in string_t.size the size of the formatted output fields. No content is written to the string memory only the size in bytes is set to the sum of the size of the formatted field output as if it would have been written.
No other field in string_t is set or changed except string_t.size.
int format_string( struct string_t * str, /*out*/size_t * nr_of_fully_written_fields, int dummy )
Writes formatted output to string_t. After return parameter nr_of_fully_written_fields is set to the number of fully formatted and written fields. If the returned value is less then the number of input fields then there was no memory left in parameter str. A value is either written fully or not at all.
On successfull return the str parameter’s size is set to the number of written bytes. There are no more bytes written then the value provided in size on function entry.
#define initdouble_stringfield( strfield, dval ) ( __extension__ ({ (strfield)->type = string_field_DOUBLE ; (strfield)->val.d = dval ; 0 ; }))
Implements string_field_t.initdouble_stringfield.
#define initfloat_stringfield( strfield, fval ) ( __extension__ ({ (strfield)->type = string_field_FLOAT ; (strfield)->val.f = fval ; 0 ; }))
Implements string_field_t.initfloat_stringfield.
#define initstring_stringfield( strfield, strval ) ( __extension__ ({ (strfield)->type = string_field_STRING ; (strfield)->val.str.addr = (strval)->addr ; (strfield)->val.str.size = (strval)->size ; 0 ; }))
Implements string_field_t.initstring_stringfield.
typedef struct string_field_t string_field_t
Tests formatted output to string_t.
int unittest_string_format( void )
struct string_field_t
Value of the field to be formatted.
union { int32_t i32 ; uint32_t u32 ; ssize_t isz ; size_t usz ; int64_t i64 ; uint64_t u64 ; float f ; double d ; struct { const uint8_t * addr ; size_t size ; } str ; } val
Static initializer.
#define string_field_INIT_EMPTY { string_field_EMPTY, { 0 } }
Inits string_field_t describing a string value.
int initstring_stringfield( /*out*/string_field_t * strfield, struct string_t * strval )
Inits string_field_t describing a float value.
int initfloat_stringfield( /*out*/string_field_t * strfield, float fval )
Inits string_field_t describing a double value.
int initdouble_stringfield( /*out*/string_field_t * strfield, double dval )
Returns in string_t.size the size of the formatted output fields.
int sizeformat_string( /*out*/struct string_t * str, int dummy )
Size in bytes of memory.
size_t size
Writes formatted output to string_t.
int format_string( struct string_t * str, /*out*/size_t * nr_of_fully_written_fields, int dummy )
Implements string_field_t.initdouble_stringfield.
#define initdouble_stringfield( strfield, dval ) ( __extension__ ({ (strfield)->type = string_field_DOUBLE ; (strfield)->val.d = dval ; 0 ; }))
Implements string_field_t.initfloat_stringfield.
#define initfloat_stringfield( strfield, fval ) ( __extension__ ({ (strfield)->type = string_field_FLOAT ; (strfield)->val.f = fval ; 0 ; }))
Implements string_field_t.initstring_stringfield.
#define initstring_stringfield( strfield, strval ) ( __extension__ ({ (strfield)->type = string_field_STRING ; (strfield)->val.str.addr = (strval)->addr ; (strfield)->val.str.size = (strval)->size ; 0 ; }))