Boost.Locale
|
a printf like class that allows type-safe and locale aware message formatting More...
#include <boost/locale/format.hpp>
Public Types | |
typedef CharType | char_type |
Underlying character type. | |
typedef basic_message< char_type > | message_type |
typedef std::basic_string < CharType > | string_type |
string type for this type of character | |
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_type 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 |
a printf like class that allows type-safe and locale aware message formatting
This class creates a formatted message similar to printf or boost::format and receives formatted entries via operator %.
For example
Formatting is enclosed between curly brackets {
}
and defined by a comma separated list of flags in the 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
Including of literal {
and }
is possible by specifying double brackets {{
and }}
accordingly.
For example:
The special key – a number without a value defines the position of an input parameter. List of keys:
[0-9]+ – digits, the index of a 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: timezone
or tz
– the name of the timezone to display the time in. For example:local
- display the time in local timegmt
- display the time in UTC time scale Invalid formatting strings are slightly ignored. This would prevent from translator to crash the program in unexpected location.
typedef basic_message<char_type> boost::locale::basic_format< CharType >::message_type |
The translation message type
|
inline |
Create a format class for format_string
|
inline |
Create a format class using message trans. The message if translated first according to the rules of target locale and then interpreted as format string
|
inline |
Add new parameter to format list. The object should be a type with defined expression out << object where out
is std::basic_ostream
.
|
inline |
Format a string using a locale loc
|
inline |
write a formatted string to output stream out using out's locale