fmtlegacy/include/fmt/locale.h

68 lines
2.3 KiB
C
Raw Normal View History

2018-11-14 17:39:37 +00:00
// Formatting library for C++ - std::locale support
//
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.
#ifndef FMT_LOCALE_H_
#define FMT_LOCALE_H_
#include <locale>
2020-01-15 19:42:59 +00:00
2019-01-13 02:27:38 +00:00
#include "format.h"
2018-11-14 17:39:37 +00:00
FMT_BEGIN_NAMESPACE
2020-05-10 14:25:42 +00:00
namespace detail {
2018-11-14 17:39:37 +00:00
template <typename Char>
2020-01-15 19:42:59 +00:00
std::basic_string<Char> vformat(
const std::locale& loc, basic_string_view<Char> format_str,
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
2018-11-14 17:39:37 +00:00
basic_memory_buffer<Char> buffer;
2020-10-21 13:53:19 +00:00
detail::vformat_to(buffer, format_str, args, detail::locale_ref(loc));
2018-11-14 17:39:37 +00:00
return fmt::to_string(buffer);
}
2020-05-10 14:25:42 +00:00
} // namespace detail
2018-11-14 17:39:37 +00:00
FMT_MODULE_EXPORT_BEGIN
2019-06-01 19:32:24 +00:00
template <typename S, typename Char = char_t<S>>
2018-11-14 23:35:24 +00:00
inline std::basic_string<Char> vformat(
2019-01-13 02:27:38 +00:00
const std::locale& loc, const S& format_str,
2020-01-15 19:42:59 +00:00
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
2020-05-10 14:25:42 +00:00
return detail::vformat(loc, to_string_view(format_str), args);
2018-11-14 23:35:24 +00:00
}
2019-06-01 19:32:24 +00:00
template <typename S, typename... Args, typename Char = char_t<S>>
inline std::basic_string<Char> format(const std::locale& loc,
2019-07-09 18:50:16 +00:00
const S& format_str, Args&&... args) {
2020-10-20 20:35:31 +00:00
return detail::vformat(loc, to_string_view(format_str),
fmt::make_args_checked<Args...>(format_str, args...));
2018-11-14 17:39:37 +00:00
}
2019-06-01 19:32:24 +00:00
template <typename S, typename OutputIt, typename... Args,
2020-10-20 20:35:31 +00:00
typename Char = char_t<S>,
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value)>
2020-01-15 19:42:59 +00:00
inline OutputIt vformat_to(
OutputIt out, const std::locale& loc, const S& format_str,
2020-07-19 15:42:02 +00:00
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
decltype(detail::get_buffer<Char>(out)) buf(detail::get_buffer_init(out));
2020-10-21 00:39:50 +00:00
vformat_to(buf, to_string_view(format_str), args, detail::locale_ref(loc));
2020-07-19 15:42:02 +00:00
return detail::get_iterator(buf);
2018-11-14 23:35:24 +00:00
}
2019-03-16 19:58:18 +00:00
template <typename OutputIt, typename S, typename... Args,
2020-10-27 08:55:26 +00:00
bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value>
2021-03-21 14:28:46 +00:00
inline auto format_to(OutputIt out, const std::locale& loc, const S& format_str,
Args&&... args) ->
2020-10-27 08:55:26 +00:00
typename std::enable_if<enable, OutputIt>::type {
const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
2020-07-19 15:42:02 +00:00
return vformat_to(out, loc, to_string_view(format_str), vargs);
2018-11-14 23:35:24 +00:00
}
FMT_MODULE_EXPORT_END
2018-11-14 17:39:37 +00:00
FMT_END_NAMESPACE
#endif // FMT_LOCALE_H_