]>
Commit | Line | Data |
---|---|---|
eafe8130 TL |
1 | // Formatting library for C++ - std::locale support |
2 | // | |
3 | // Copyright (c) 2012 - present, Victor Zverovich | |
4 | // All rights reserved. | |
5 | // | |
6 | // For the license information refer to format.h. | |
7 | ||
8 | #ifndef FMT_LOCALE_H_ | |
9 | #define FMT_LOCALE_H_ | |
10 | ||
eafe8130 | 11 | #include <locale> |
9f95a23c | 12 | #include "format.h" |
eafe8130 TL |
13 | |
14 | FMT_BEGIN_NAMESPACE | |
15 | ||
16 | namespace internal { | |
17 | template <typename Char> | |
18 | typename buffer_context<Char>::type::iterator vformat_to( | |
9f95a23c | 19 | const std::locale& loc, basic_buffer<Char>& buf, |
eafe8130 TL |
20 | basic_string_view<Char> format_str, |
21 | basic_format_args<typename buffer_context<Char>::type> args) { | |
9f95a23c TL |
22 | typedef back_insert_range<basic_buffer<Char>> range; |
23 | return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str), args, | |
24 | internal::locale_ref(loc)); | |
eafe8130 TL |
25 | } |
26 | ||
27 | template <typename Char> | |
28 | std::basic_string<Char> vformat( | |
9f95a23c | 29 | const std::locale& loc, basic_string_view<Char> format_str, |
eafe8130 TL |
30 | basic_format_args<typename buffer_context<Char>::type> args) { |
31 | basic_memory_buffer<Char> buffer; | |
32 | internal::vformat_to(loc, buffer, format_str, args); | |
33 | return fmt::to_string(buffer); | |
34 | } | |
9f95a23c | 35 | } // namespace internal |
eafe8130 TL |
36 | |
37 | template <typename S, typename Char = FMT_CHAR(S)> | |
38 | inline std::basic_string<Char> vformat( | |
9f95a23c | 39 | const std::locale& loc, const S& format_str, |
eafe8130 TL |
40 | basic_format_args<typename buffer_context<Char>::type> args) { |
41 | return internal::vformat(loc, to_string_view(format_str), args); | |
42 | } | |
43 | ||
44 | template <typename S, typename... Args> | |
9f95a23c TL |
45 | inline std::basic_string<FMT_CHAR(S)> format(const std::locale& loc, |
46 | const S& format_str, | |
47 | const Args&... args) { | |
48 | return internal::vformat(loc, to_string_view(format_str), | |
49 | {internal::make_args_checked(format_str, args...)}); | |
eafe8130 TL |
50 | } |
51 | ||
9f95a23c TL |
52 | template <typename String, typename OutputIt, typename... Args, |
53 | FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value)> | |
54 | inline OutputIt vformat_to( | |
55 | OutputIt out, const std::locale& loc, const String& format_str, | |
56 | typename format_args_t<OutputIt, FMT_CHAR(String)>::type args) { | |
eafe8130 TL |
57 | typedef output_range<OutputIt, FMT_CHAR(String)> range; |
58 | return vformat_to<arg_formatter<range>>( | |
9f95a23c | 59 | range(out), to_string_view(format_str), args, internal::locale_ref(loc)); |
eafe8130 TL |
60 | } |
61 | ||
9f95a23c TL |
62 | template <typename OutputIt, typename S, typename... Args, |
63 | FMT_ENABLE_IF(internal::is_string<S>::value&& | |
64 | internal::is_output_iterator<OutputIt>::value)> | |
65 | inline OutputIt format_to(OutputIt out, const std::locale& loc, | |
66 | const S& format_str, const Args&... args) { | |
eafe8130 TL |
67 | internal::check_format_string<Args...>(format_str); |
68 | typedef typename format_context_t<OutputIt, FMT_CHAR(S)>::type context; | |
69 | format_arg_store<context, Args...> as{args...}; | |
70 | return vformat_to(out, loc, to_string_view(format_str), | |
71 | basic_format_args<context>(as)); | |
72 | } | |
73 | ||
74 | FMT_END_NAMESPACE | |
75 | ||
76 | #endif // FMT_LOCALE_H_ |