fmtlegacy/include/fmt/locale.h

78 lines
2.9 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>
2019-01-13 02:27:38 +00:00
#include "format.h"
2018-11-14 17:39:37 +00:00
FMT_BEGIN_NAMESPACE
namespace internal {
template <typename Char>
2019-06-03 00:13:50 +00:00
typename buffer_context<Char>::iterator vformat_to(
const std::locale& loc, buffer<Char>& buf,
2018-11-14 17:39:37 +00:00
basic_string_view<Char> format_str,
2019-06-03 00:13:50 +00:00
basic_format_args<buffer_context<Char>> args) {
typedef back_insert_range<buffer<Char>> range;
2019-01-13 02:27:38 +00:00
return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str), args,
internal::locale_ref(loc));
2018-11-14 17:39:37 +00:00
}
template <typename Char>
2019-06-03 00:13:50 +00:00
std::basic_string<Char> vformat(const std::locale& loc,
basic_string_view<Char> format_str,
basic_format_args<buffer_context<Char>> args) {
2018-11-14 17:39:37 +00:00
basic_memory_buffer<Char> buffer;
internal::vformat_to(loc, buffer, format_str, args);
return fmt::to_string(buffer);
}
2019-01-13 02:27:38 +00:00
} // namespace internal
2018-11-14 17:39:37 +00:00
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,
2019-06-03 00:13:50 +00:00
basic_format_args<buffer_context<Char>> args) {
2018-11-14 23:35:24 +00:00
return internal::vformat(loc, to_string_view(format_str), args);
}
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,
const S& format_str,
const Args&... args) {
2019-02-11 00:59:58 +00:00
return internal::vformat(loc, to_string_view(format_str),
{internal::make_args_checked(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,
typename Char = enable_if_t<
internal::is_output_iterator<OutputIt>::value, char_t<S>>>
inline OutputIt vformat_to(OutputIt out, const std::locale& loc,
const S& format_str,
typename format_args_t<OutputIt, Char>::type args) {
using range = output_range<OutputIt, Char>;
2018-11-14 23:35:24 +00:00
return vformat_to<arg_formatter<range>>(
2019-01-13 02:27:38 +00:00
range(out), to_string_view(format_str), args, internal::locale_ref(loc));
2018-11-14 23:35:24 +00:00
}
2019-03-16 19:58:18 +00:00
template <typename OutputIt, typename S, typename... Args,
2019-06-01 19:32:24 +00:00
FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value&&
internal::is_string<S>::value)>
2019-03-16 19:58:18 +00:00
inline OutputIt format_to(OutputIt out, const std::locale& loc,
const S& format_str, const Args&... args) {
2018-11-14 23:35:24 +00:00
internal::check_format_string<Args...>(format_str);
2019-06-01 19:32:24 +00:00
using context = typename format_context_t<OutputIt, char_t<S>>::type;
2018-11-14 23:35:24 +00: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 17:39:37 +00:00
FMT_END_NAMESPACE
#endif // FMT_LOCALE_H_