Scippy

SoPlex

Sequential object-oriented simPlex

locale.h
Go to the documentation of this file.
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 
11 #include <locale>
12 #include "format.h"
13 
15 
16 namespace internal {
17 template <typename Char>
19  const std::locale& loc, buffer<Char>& buf,
20  basic_string_view<Char> format_str,
22  using range = buffer_range<Char>;
23  return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str), args,
25 }
26 
27 template <typename Char>
28 std::basic_string<Char> vformat(const std::locale& loc,
29  basic_string_view<Char> format_str,
32  internal::vformat_to(loc, buffer, format_str, args);
33  return fmt::to_string(buffer);
34 }
35 } // namespace internal
36 
37 template <typename S, typename Char = char_t<S>>
38 inline std::basic_string<Char> vformat(
39  const std::locale& loc, const S& format_str,
41  return internal::vformat(loc, to_string_view(format_str), args);
42 }
43 
44 template <typename S, typename... Args, typename Char = char_t<S>>
45 inline std::basic_string<Char> format(const std::locale& loc,
46  const S& format_str, Args&&... args) {
47  return internal::vformat(
48  loc, to_string_view(format_str),
49  {internal::make_args_checked<Args...>(format_str, args...)});
50 }
51 
52 template <typename S, typename OutputIt, typename... Args,
53  typename Char = enable_if_t<
55 inline OutputIt vformat_to(OutputIt out, const std::locale& loc,
56  const S& format_str,
59  return vformat_to<arg_formatter<range>>(
60  range(out), to_string_view(format_str), args, internal::locale_ref(loc));
61 }
62 
63 template <typename OutputIt, typename S, typename... Args,
66 inline OutputIt format_to(OutputIt out, const std::locale& loc,
67  const S& format_str, Args&&... args) {
68  internal::check_format_string<Args...>(format_str);
69  using context = format_context_t<OutputIt, char_t<S>>;
70  format_arg_store<context, Args...> as{args...};
71  return vformat_to(out, loc, to_string_view(format_str),
73 }
74 
76 
77 #endif // FMT_LOCALE_H_
#define FMT_BEGIN_NAMESPACE
Definition: core.h:163
std::basic_string< Char > format(const std::locale &loc, const S &format_str, Args &&... args)
Definition: locale.h:45
OutputIt iterator
Definition: core.h:1147
void check_format_string(const S &)
Definition: core.h:1369
void vformat_to(basic_memory_buffer< Char > &buf, const text_style &ts, basic_string_view< Char > format_str, basic_format_args< buffer_context< Char >> args)
Definition: color.h:473
typename internal::char_t_impl< S >::type char_t
Definition: core.h:458
#define FMT_END_NAMESPACE
Definition: core.h:158
typename std::enable_if< B, T >::type enable_if_t
Definition: core.h:204
std::string to_string(const T &value)
Definition: format.h:3245
#define FMT_ENABLE_IF(...)
Definition: core.h:220
void to_string_view(...)
OutputIt format_to(OutputIt out, const std::locale &loc, const S &format_str, Args &&... args)
Definition: locale.h:66
format_arg_store< buffer_context< Char >, remove_reference_t< Args >... > make_args_checked(const S &format_str, const remove_reference_t< Args > &... args)
Definition: core.h:1387
std::basic_string< Char > vformat(basic_string_view< Char > format_str, basic_format_args< buffer_context< Char >> args)
Definition: format.h:3379