fmt/include/fmt/locale.h

79 lines
2.8 KiB
C
Raw Normal View History

2018-11-14 20:39:37 +03: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 22:42:59 +03:00
2019-01-13 05:27:38 +03:00
#include "format.h"
2018-11-14 20:39:37 +03:00
FMT_BEGIN_NAMESPACE
2020-05-10 17:25:42 +03:00
namespace detail {
2018-11-14 20:39:37 +03:00
template <typename Char>
2019-06-03 03:13:50 +03:00
typename buffer_context<Char>::iterator vformat_to(
const std::locale& loc, buffer<Char>& buf,
2018-11-14 20:39:37 +03:00
basic_string_view<Char> format_str,
2020-01-15 22:42:59 +03:00
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
2020-05-30 02:51:45 +03:00
using af = arg_formatter<typename buffer_context<Char>::iterator, Char>;
return vformat_to<af>(std::back_inserter(buf), to_string_view(format_str),
args, detail::locale_ref(loc));
2018-11-14 20:39:37 +03:00
}
template <typename Char>
2020-01-15 22:42:59 +03: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 20:39:37 +03:00
basic_memory_buffer<Char> buffer;
2020-05-10 17:25:42 +03:00
detail::vformat_to(loc, buffer, format_str, args);
2018-11-14 20:39:37 +03:00
return fmt::to_string(buffer);
}
2020-05-10 17:25:42 +03:00
} // namespace detail
2018-11-14 20:39:37 +03:00
2019-06-01 22:32:24 +03:00
template <typename S, typename Char = char_t<S>>
2018-11-15 02:35:24 +03:00
inline std::basic_string<Char> vformat(
2019-01-13 05:27:38 +03:00
const std::locale& loc, const S& format_str,
2020-01-15 22:42:59 +03:00
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
2020-05-10 17:25:42 +03:00
return detail::vformat(loc, to_string_view(format_str), args);
2018-11-15 02:35:24 +03:00
}
2019-06-01 22:32:24 +03:00
template <typename S, typename... Args, typename Char = char_t<S>>
inline std::basic_string<Char> format(const std::locale& loc,
2019-07-09 21:50:16 +03:00
const S& format_str, Args&&... args) {
2020-05-10 17:25:42 +03:00
return detail::vformat(
2019-07-09 21:50:16 +03:00
loc, to_string_view(format_str),
2020-05-10 17:25:42 +03:00
detail::make_args_checked<Args...>(format_str, args...));
2018-11-14 20:39:37 +03:00
}
2019-06-01 22:32:24 +03:00
template <typename S, typename OutputIt, typename... Args,
typename Char = enable_if_t<
2020-05-10 17:25:42 +03:00
detail::is_output_iterator<OutputIt>::value, char_t<S>>>
2020-01-15 22:42:59 +03:00
inline OutputIt vformat_to(
OutputIt out, const std::locale& loc, const S& format_str,
format_args_t<type_identity_t<OutputIt>, Char> args) {
2020-07-04 16:41:24 +03:00
using af = detail::arg_formatter<OutputIt, Char>;
2020-05-30 02:51:45 +03:00
return vformat_to<af>(out, to_string_view(format_str), args,
detail::locale_ref(loc));
2018-11-15 02:35:24 +03:00
}
2019-03-16 22:58:18 +03:00
template <typename OutputIt, typename S, typename... Args,
2020-05-10 17:25:42 +03:00
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt>::value&&
detail::is_string<S>::value)>
2019-03-16 22:58:18 +03:00
inline OutputIt format_to(OutputIt out, const std::locale& loc,
2019-07-09 21:50:16 +03:00
const S& format_str, Args&&... args) {
2020-05-10 17:25:42 +03:00
detail::check_format_string<Args...>(format_str);
using context = format_context_t<OutputIt, char_t<S>>;
2018-11-15 02:35:24 +03:00
format_arg_store<context, Args...> as{args...};
return vformat_to(out, loc, to_string_view(format_str),
basic_format_args<context>(as));
}
2018-11-14 20:39:37 +03:00
FMT_END_NAMESPACE
#endif // FMT_LOCALE_H_