| Boost.Locale

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Examples

- Class List
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions
boost::locale::basic_format< CharType > Class Template Reference
Format

a printf like class that allows type-safe and locale aware message formatting More...

`#include <boost/locale/format.hpp>`

List of all members.

## Classes

class | format_guard

## Public Types

typedef CharType | char_type
| Underlying character type.
typedef basic_message< char_type > | message_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_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

## Detailed Description

### template<typename CharType>
class boost::locale::basic_format< CharType >

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

      cout << format("Hello {1}, you are {2} years old") % name % age << endl;

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:

       cout << format("The height of water at {1,time} is {2,num=fixed,precision=3}") % time % height;

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 number
  - `oct` -- display in octal format
  - `sci` or `scientific` -- display in scientific format
  - `fix` or `fixed` -- display in fixed format
  For example `number=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 format
  - `m` 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` manipulator
- `spell` 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:

          cout << format("Today {1,date} ({1,date,locale=he_IL.UTF-8@calendar=hebrew,date} Hebrew Date)") % date;

- `timezone` or `tz` -- the name of the timezone to display the time in. For example:

          cout << format("Time is: Local {1,time}, ({1,time,tz=EET} Eastern European Time)") % date;

- `local` - display the time in local time
- `gmt` - display the time in UTC time scale

          cout << format("Local time is: {1,time,local}, universal time is {1,time,gmt}") % time;

Invalid formatting strings are slightly ignored. This would prevent from translator to crash the program in unexpected location.

## Member Typedef Documentation

template<typename CharType >

typedef basic_message<char_type> boost::locale::basic_format< CharType >::message_type

The translation message type

template<typename CharType >

typedef std::basic_string<CharType> boost::locale::basic_format< CharType >::string_type

string type for this type of character

## Constructor & Destructor Documentation

template<typename CharType >

boost::locale::basic_format< CharType >::basic_format | ( | string_type | format_string | ) | `[inline]`

Create a format class for format_string

template<typename CharType >

boost::locale::basic_format< CharType >::basic_format | ( | message_type const & | trans | ) | `[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

## Member Function Documentation

template<typename CharType >
template<typename Formattible >

basic_format& boost::locale::basic_format< CharType >::operator% | ( | Formattible const & | object | ) | `[inline]`

Add new parameter to format list. The object should be a type with defined expression out << object where `out` is `std::basic_ostream`.

template<typename CharType >

string_type boost::locale::basic_format< CharType >::str | ( | std::locale const & | loc = `std::locale()` | ) | const`[inline]`

Format a string using a locale loc

template<typename CharType >

void boost::locale::basic_format< CharType >::write | ( | stream_type & | out | ) | const`[inline]`

write a formatted string to output stream out using out's locale

The documentation for this class was generated from the following file:

- boost/locale/format.hpp