]>
git.proxmox.com Git - ceph.git/blob - ceph/src/fmt/include/fmt/locale.h
34b5c89082adf49f5f77f1e68399d60a176615b1
1 // Formatting library for C++ - std::locale support
3 // Copyright (c) 2012 - present, Victor Zverovich
4 // All rights reserved.
6 // For the license information refer to format.h.
18 template <typename Char
>
19 typename buffer_context
<Char
>::iterator
vformat_to(
20 const std::locale
& loc
, buffer
<Char
>& buf
,
21 basic_string_view
<Char
> format_str
,
22 basic_format_args
<buffer_context
<type_identity_t
<Char
>>> args
) {
23 using range
= buffer_range
<Char
>;
24 return vformat_to
<arg_formatter
<range
>>(buf
, to_string_view(format_str
), args
,
25 detail::locale_ref(loc
));
28 template <typename Char
>
29 std::basic_string
<Char
> vformat(
30 const std::locale
& loc
, basic_string_view
<Char
> format_str
,
31 basic_format_args
<buffer_context
<type_identity_t
<Char
>>> args
) {
32 basic_memory_buffer
<Char
> buffer
;
33 detail::vformat_to(loc
, buffer
, format_str
, args
);
34 return fmt::to_string(buffer
);
38 template <typename S
, typename Char
= char_t
<S
>>
39 inline std::basic_string
<Char
> vformat(
40 const std::locale
& loc
, const S
& format_str
,
41 basic_format_args
<buffer_context
<type_identity_t
<Char
>>> args
) {
42 return detail::vformat(loc
, to_string_view(format_str
), args
);
45 template <typename S
, typename
... Args
, typename Char
= char_t
<S
>>
46 inline std::basic_string
<Char
> format(const std::locale
& loc
,
47 const S
& format_str
, Args
&&... args
) {
48 return detail::vformat(
49 loc
, to_string_view(format_str
),
50 detail::make_args_checked
<Args
...>(format_str
, args
...));
53 template <typename S
, typename OutputIt
, typename
... Args
,
54 typename Char
= enable_if_t
<
55 detail::is_output_iterator
<OutputIt
>::value
, char_t
<S
>>>
56 inline OutputIt
vformat_to(
57 OutputIt out
, const std::locale
& loc
, const S
& format_str
,
58 format_args_t
<type_identity_t
<OutputIt
>, Char
> args
) {
59 using range
= detail::output_range
<OutputIt
, Char
>;
60 return vformat_to
<arg_formatter
<range
>>(
61 range(out
), to_string_view(format_str
), args
, detail::locale_ref(loc
));
64 template <typename OutputIt
, typename S
, typename
... Args
,
65 FMT_ENABLE_IF(detail::is_output_iterator
<OutputIt
>::value
&&
66 detail::is_string
<S
>::value
)>
67 inline OutputIt
format_to(OutputIt out
, const std::locale
& loc
,
68 const S
& format_str
, Args
&&... args
) {
69 detail::check_format_string
<Args
...>(format_str
);
70 using context
= format_context_t
<OutputIt
, char_t
<S
>>;
71 format_arg_store
<context
, Args
...> as
{args
...};
72 return vformat_to(out
, loc
, to_string_view(format_str
),
73 basic_format_args
<context
>(as
));
78 #endif // FMT_LOCALE_H_