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

to_string


Functions that will render a text representation of bools, integrals, floating point and pointers.
Uses etl::basic_format_spec to define the required formatting.

It will convert to any of the ETL string types.

____________________________________________________________________________________________________

Default format specification


template <typename T, const size_t SIZE>
const etl::istring& to_string(const T value, etl::string<SIZE>& str, const bool append = false)

template <typename T, const size_t SIZE>
const etl::iwstring& to_string(const T value, etl::wstring<SIZE>& str, const bool append = false)

template <typename T, const size_t SIZE>
const etl::iu16string& to_string(const T value, etl::u16string<SIZE>& str, const bool append = false)

template <typename T, const size_t SIZE>
const etl::iu32string& to_string(const T value, etl::u32string<SIZE>& str, const bool append = false)

value   The value to convert to a string.
str     The string in with to place the rendered text.
append  If true then appends the text to the current string's content. Default false.
____________________________________________________________________________________________________

Supplied format specification


template <typename T, const size_t SIZE>
const etl::istring& to_string(const T value, etl::string<SIZE>& str, const etl::format_spec& format,
const bool append = false)

template <typename T, const size_t SIZE>
const etl::iwstring& to_string(const T value, etl::wstring<SIZE>& str, const etl::wformat_spec& format,
const bool append = false)

template <typename T, const size_t SIZE>
const etl::iu16string& to_string(const T value, etl::u16string<SIZE>& str, const etl::ui16format_spec&
format, const bool append = false)

template <typename T, const size_t SIZE>
const etl::iu32string& to_string(const T value, etl::u32string<SIZE>& str, const etl::u32format_spec&
format, const bool append = false)

value   The value to convert to a string.
str     The string in with to place the rendered text.
format  The format specification.
append  If true then appends the text to the current string's content. Default false.

____________________________________________________________________________________________________

Examples


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);

____________________________________________________________________________________________________

etl::format_spec format;

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

etl::string<8> text;

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

etl::string<19> text = "The result is ";

etl::to_string(3.1415, text, etl::format_spec().precision(3), true);
// 'text' is set to "The result is 3.142"
to_string.h, to_wstring.h, to_u16string.h, to_u32string.h