mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-16 17:06:05 +08:00
96 lines
3.4 KiB
Plaintext
96 lines
3.4 KiB
Plaintext
string_stream
|
|
wstring_stream
|
|
u16string_stream
|
|
u32string_stream
|
|
|
|
Classes to build strings using a streaming api.
|
|
Uses etl::basic_format_spec to define the required formatting.
|
|
|
|
The documentation below is for etl::string_stream.
|
|
The other streams have a similar API, though using w, u16 or u32 types.
|
|
____________________________________________________________________________________________________
|
|
Member functions
|
|
explicit string_stream(etl::istring& str)
|
|
Construct, using the supplied string as a buffer.
|
|
Uses the default format spec.
|
|
____________________________________________________________________________________________________
|
|
string_stream(etl::istring& str, const etl::format_spec& spec)
|
|
Construct, using the supplied string as a buffer.
|
|
Initialised with the supplied format spec.
|
|
____________________________________________________________________________________________________
|
|
void set_format(const etl::format_spec& spec_)
|
|
Sets a new format spec to use.
|
|
____________________________________________________________________________________________________
|
|
const etl::format_spec& get_format() const
|
|
Gets the current format spec.
|
|
____________________________________________________________________________________________________
|
|
etl::istring& str()
|
|
Gets a reference to the internal string.
|
|
____________________________________________________________________________________________________
|
|
const etl::istring& str() const
|
|
Gets a const reference to the internal string.
|
|
____________________________________________________________________________________________________
|
|
void str(const etl::istring::const_pointer p)
|
|
Resets the internal string to the text pointed to by p.
|
|
____________________________________________________________________________________________________
|
|
void str(const etl::istring& text)
|
|
Resets the internal string to text.
|
|
____________________________________________________________________________________________________
|
|
Streaming operators
|
|
|
|
string_stream& operator <<(string_stream& ss, T value)
|
|
|
|
Where T may be one of the following:-
|
|
|
|
Any fundamental type.
|
|
etl::format_spec
|
|
etl::setbase(n)
|
|
etl::bin
|
|
etl::oct
|
|
etl::dec
|
|
etl::hex
|
|
etl::setfill(c)
|
|
etl::setw(n)
|
|
etl::setprecision(n)
|
|
etl::left
|
|
etl::right
|
|
etl::boolalpha
|
|
etl::noboolalpha
|
|
etl::uppercase
|
|
etl::nouppercase
|
|
etl::showbase
|
|
etl::noshowbase
|
|
etl::string
|
|
etl::istring
|
|
etl::string_view
|
|
const char*
|
|
See etl::format_spec
|
|
|
|
Custom user types may be streamed by overloading the streaming operator.
|
|
____________________________________________________________________________________________________
|
|
Examples
|
|
|
|
Using format_spec
|
|
etl::format_spec format1 = etl::format_spec().hex().width(8).fill('0');
|
|
etl::format_spec format2;
|
|
etl::format_spec format3 = etl::format_spec().width(6).fill('#').precision(3);
|
|
etl::string<50> text;
|
|
etl::string_stream stream(text);
|
|
|
|
stream << format1 << 1193046 << format2 << " " << format3 << 3.1415;
|
|
const etl::istring& result = stream.str();
|
|
|
|
text is set to "00123456 #3.142"
|
|
____________________________________________________________________________________________________
|
|
Using stream manipulators
|
|
etl::string<50> text;
|
|
etl::string_stream stream(text);
|
|
|
|
stream << etl::hex << etl::setw(8) << etl::setfill('0') << 1193046
|
|
<< etl::setw(0) << " "
|
|
<< etl::setw(6) << etl::setfill('#') << etl::setprecision(3) << 3.1415;
|
|
const etl::istring& result = stream.str();
|
|
|
|
text is set to "00123456 #3.142"
|
|
|