1//
2// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3//
4// Distributed under the Boost Software License, Version 1.0.
5// https://www.boost.org/LICENSE_1_0.txt
6
7#ifndef BOOST_LOCALE_FORMATTER_HPP_INCLUDED
8#define BOOST_LOCALE_FORMATTER_HPP_INCLUDED
9
10#include <boost/locale/config.hpp>
11#include <cstdint>
12#include <memory>
13#include <string>
14#include <unicode/locid.h>
15
16namespace boost { namespace locale { namespace impl_icu {
17
18 /// \brief Special base polymorphic class that is used as a character type independent base for all formatter
19 /// classes
20 class base_formatter {
21 public:
22 virtual ~base_formatter() = default;
23 };
24
25 /// \brief A class that is used for formatting numbers, currency and dates/times
26 template<typename CharType>
27 class formatter : public base_formatter {
28 public:
29 typedef std::basic_string<CharType> string_type;
30
31 /// Format the value and return the number of Unicode code points
32 virtual string_type format(double value, size_t& code_points) const = 0;
33 /// Format the value and return the number of Unicode code points
34 virtual string_type format(int64_t value, size_t& code_points) const = 0;
35 /// Format the value and return the number of Unicode code points
36 virtual string_type format(int32_t value, size_t& code_points) const = 0;
37
38 /// Parse the string and return the number of used characters. If it returns 0
39 /// then parsing failed.
40 virtual size_t parse(const string_type& str, double& value) const = 0;
41 /// Parse the string and return the number of used characters. If it returns 0
42 /// then parsing failed.
43 virtual size_t parse(const string_type& str, int64_t& value) const = 0;
44 /// Parse the string and return the number of used characters. If it returns 0
45 /// then parsing failed.
46 virtual size_t parse(const string_type& str, int32_t& value) const = 0;
47
48 /// Get formatter for the current state of ios_base -- flags and locale,
49 /// NULL may be returned if an invalid combination of flags is provided or this type
50 /// of formatting is not supported by locale.
51 ///
52 /// Note: formatter is cached. If \a ios is not changed (no flags or locale changed)
53 /// the formatter would remain the same. Otherwise it would be rebuild and cached
54 /// for future use. It is useful for saving time for generation
55 /// of multiple values with same locale.
56 ///
57 /// For example this code will create a new spelling formatter only once:
58 ///
59 /// \code
60 /// std::cout << as::spellout;
61 /// for(int i=1;i<=10;i++)
62 /// std::cout << i << std::endl;
63 /// \endcode
64 ///
65 ///
66 static std::unique_ptr<formatter>
67 create(std::ios_base& ios, const icu::Locale& locale, const std::string& encoding);
68 }; // class formatter
69
70}}} // namespace boost::locale::impl_icu
71
72#endif
73

source code of boost/libs/locale/src/boost/locale/icu/formatter.hpp