#include <boost/locale/format.hpp>
Public Types | |
typedef CharType | char_type |
typedef std::basic_string < CharType > | string_type |
typedef std::basic_ostream < CharType > | stream_type |
output stream type for this type of character | |
Public Member Functions | |
basic_format (string_type format_string) | |
basic_format (message const &trans) | |
template<typename Formattible> | |
basic_format & | operator% (Formattible const &object) |
string_type | str (std::locale const &loc=std::locale()) const |
void | write (stream_type &out) const |
This class creates formatted message similarly to printf or boost::format and receives formatted entries via operator %.
For example
cout << format("Hello {1}, you are {2} years old") % name % age << endl;
Formatting is enclosed between curl brackets {
}
and defined by comma separated list of flags in format key[=value] value may also be text included between single quotes '
that is used for special purposes where inclusion of non-ASCII text is allowed
For example:
The special key -- number without value defines a position of input parameter. List of keys:
[0-9]+ -- digits, the index of formatted parameter -- mandatory key.num
or number
-- format a number. Optional values are:hex
-- display hexadecimal numberoct
-- display in octal formatsci
or `scientific` -- display in scientific formatfix
or `fixed` -- display in fixed formatnumber=sci
cur
or currency
-- format currency. Optional values are:
iso
-- display using ISO currency symbol.nat
or national
-- display using national currency symbol.per
or percent
-- format percent value.date
, time
, datetime
or dt
-- format date, time or date and time. Optional values are:s
or short
-- display in short formatm
or medium
-- display in medium format.l
or long
-- display in long format.f
or full
-- display in full format.ftime
with string (quoted) parameter -- display as with strftime
see, as::ftime
manipulatorspell
or spellout
-- spell the number.ord
or ordinal
-- format ordinal number (1st, 2nd... etc)left
or <
-- align to left.right
or >
-- align to right.width
or w
-- set field width (requires parameter).precision
or p
-- set precision (requires parameter).locale
-- with parameter -- switch locale for current operation. This command generates locale with formatting facets giving more fine grained control of formatting. For example: typedef CharType boost::locale::basic_format< CharType >::char_type |
Underlying character type
typedef std::basic_string<CharType> boost::locale::basic_format< CharType >::string_type |
string type for this type of character
boost::locale::basic_format< CharType >::basic_format | ( | string_type | format_string | ) | [inline] |
Create a format class for format_string
boost::locale::basic_format< CharType >::basic_format | ( | message const & | trans | ) | [inline] |
basic_format& boost::locale::basic_format< CharType >::operator% | ( | Formattible const & | object | ) | [inline] |
Add new parameter to format list
string_type boost::locale::basic_format< CharType >::str | ( | std::locale const & | loc = std::locale() |
) | const [inline] |
Format a string using a locale loc
void boost::locale::basic_format< CharType >::write | ( | stream_type & | out | ) | const [inline] |
write a formatted string to output stream out using out's locale