A C++ template library for embedded applications
Designed and maintained by
Aster Consulting Ltd
MIT licensed
Join the ETL community

basic_format_spec

format_spec

wformat_spec

u16format_spec

u32format_spec


A template class and four typedefs that allow a specification for string formatting functions.
It defines specifications for bool, integrals, floating point and pointers.
Used in conjunction with etl::to_string.

The class stores the following specifications:
base           The number base. Predefined settings for binary, octal, decimal and hex.
width          The total minimum field width for the value's text representation.
precision      The total number of decimal places.
upper_case     If true then hex digits are in upper case.
left_justified If true then the text representation is left justified with padding up to the field width on the right.
boolalpha      If true then Boolean values are rendered as "true" and "false".
fill           Determines the character used for the padding for width.
____________________________________________________________________________________________________

basic_format_spec


template <typename TString>
class basic_format_spec

____________________________________________________________________________________________________

basic_format_spec()

The default constructor.

Sets:-
base           : 10
width          : 0
precision      : 0
upper case     :  true
left justified : false
boolalpha      : false
fill           : ' '
____________________________________________________________________________________________________

basic_format_spec& base(const uint32_t b)

Sets the base to b.
____________________________________________________________________________________________________

basic_format_spec& binary()

Sets the base to binary.
____________________________________________________________________________________________________

basic_format_spec& octal()

Sets the base to octal.
____________________________________________________________________________________________________

basic_format_spec& hex()

Sets the base to hexadecimal.
____________________________________________________________________________________________________

basic_format_spec& octal()

Sets the base to octal.
____________________________________________________________________________________________________

uint32_t get_base() const

Returns the current setting for base.
____________________________________________________________________________________________________

basic_format_spec& width(const uint32_t w)

Sets the width to w.
____________________________________________________________________________________________________

uint32_t get_width() const

Returns the current width value.
____________________________________________________________________________________________________

basic_format_spec& precision(const uint32_t p)

Sets the precision to p.
____________________________________________________________________________________________________

uint32_t get_precision() const

Returns the current precision value.
____________________________________________________________________________________________________

basic_format_spec& upper_case(const bool u)

Sets the upper case flag  to u.
____________________________________________________________________________________________________

bool is_upper_case() const

Returns true if the upper case flag is set.
____________________________________________________________________________________________________

basic_format_spec& fill(const typename TString::value_type c)

Sets the fill character to c.
____________________________________________________________________________________________________

typename TString::value_type get_fill() const

Returns the fill character.
____________________________________________________________________________________________________

basic_format_spec& left()

Sets the left justified flag  to true.
____________________________________________________________________________________________________

bool is_left() const

Returns true if the left justified flag is set.
____________________________________________________________________________________________________

basic_format_spec& right()

Sets the left justified flag  to false.
____________________________________________________________________________________________________

bool is_right() const

Returns true if the left justified flag is clear.
____________________________________________________________________________________________________

basic_format_spec& boolalpha(bool b)

Sets the bool alpha flag  to b.
____________________________________________________________________________________________________

bool is_boolalpha() const

Returns true if the bool alpha flag is set.

____________________________________________________________________________________________________

Typedefs


typedef etl::basic_format_spec<etl::istring>    format_spec;
typedef etl::basic_format_spec<etl::iwstring>   wformat_spec;
typedef etl::basic_format_spec<etl::iu16string> u16format_spec;
typedef etl::basic_format_spec<etl::iu32string> u32format_spec;

____________________________________________________________________________________________________

Example


etl::format_spec format;

// Format as a hex character, minimum fill width of 8, fill with zeros.
format.hex().width(8).fill('0');

etl::string<8> text;

// 'text' is set to "00123456"
etl::to_string(1193046, text, format);

// Format minimum fill width of 8, fill with space and three decimal digits.
format.width(8).fill(' ').precision(3);

// 'text' is set to "   3.142"
etl::to_string(3.1415, text, format);
format_spec.h