mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-27 12:49:46 +01:00
Move is_char specializations to xchar.h
This commit is contained in:
@@ -724,6 +724,23 @@ inline auto get_container(std::back_insert_iterator<Container> it)
|
||||
return *accessor(it).container;
|
||||
}
|
||||
|
||||
template <typename Char, typename InputIt, typename OutputIt>
|
||||
FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out)
|
||||
-> OutputIt {
|
||||
while (begin != end) *out++ = static_cast<Char>(*begin++);
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename Char, FMT_ENABLE_IF(std::is_same<Char, char>::value)>
|
||||
FMT_CONSTEXPR auto copy_str(const Char* begin, const Char* end, Char* out)
|
||||
-> Char* {
|
||||
if (is_constant_evaluated())
|
||||
return copy_str<Char, const Char*, Char*>(begin, end, out);
|
||||
auto size = to_unsigned(end - begin);
|
||||
memcpy(out, begin, size);
|
||||
return out + size;
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
A contiguous memory buffer with an optional growing ability. It is an internal
|
||||
@@ -848,7 +865,12 @@ class iterator_buffer final : public Traits, public buffer<T> {
|
||||
void grow(size_t) final FMT_OVERRIDE {
|
||||
if (this->size() == buffer_size) flush();
|
||||
}
|
||||
void flush();
|
||||
|
||||
void flush() {
|
||||
auto size = this->size();
|
||||
this->clear();
|
||||
out_ = copy_str<T>(data_, data_ + this->limit(size), out_);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit iterator_buffer(OutputIt out, size_t n = buffer_size)
|
||||
@@ -1463,6 +1485,12 @@ FMT_CONSTEXPR FMT_INLINE auto visit_format_arg(
|
||||
|
||||
FMT_BEGIN_DETAIL_NAMESPACE
|
||||
|
||||
template <typename Char, typename InputIt>
|
||||
auto copy_str(InputIt begin, InputIt end, appender out) -> appender {
|
||||
get_container(out).append(begin, end);
|
||||
return out;
|
||||
}
|
||||
|
||||
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
|
||||
// A workaround for gcc 4.8 to make void_t work in a SFINAE context.
|
||||
template <typename... Ts> struct void_t_impl { using type = void; };
|
||||
|
||||
@@ -432,46 +432,6 @@ using char8_type = char8_t;
|
||||
enum char8_type : unsigned char {};
|
||||
#endif
|
||||
|
||||
template <typename InputIt, typename OutChar>
|
||||
using needs_conversion = bool_constant<
|
||||
std::is_same<typename std::iterator_traits<InputIt>::value_type,
|
||||
char>::value &&
|
||||
std::is_same<OutChar, char8_type>::value>;
|
||||
|
||||
template <typename OutChar, typename InputIt, typename OutputIt,
|
||||
FMT_ENABLE_IF(!needs_conversion<InputIt, OutChar>::value)>
|
||||
FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out)
|
||||
-> OutputIt {
|
||||
while (begin != end) *out++ = *begin++;
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename OutChar, typename InputIt,
|
||||
FMT_ENABLE_IF(!needs_conversion<InputIt, OutChar>::value)>
|
||||
FMT_CONSTEXPR20 auto copy_str(InputIt begin, InputIt end, OutChar* out)
|
||||
-> OutChar* {
|
||||
if (is_constant_evaluated()) {
|
||||
return copy_str<OutChar, InputIt, OutChar*>(begin, end, out);
|
||||
}
|
||||
auto size = to_unsigned(end - begin);
|
||||
std::uninitialized_copy(begin, end, make_checked(out, size));
|
||||
return out + size;
|
||||
}
|
||||
|
||||
template <typename OutChar, typename InputIt, typename OutputIt,
|
||||
FMT_ENABLE_IF(needs_conversion<InputIt, OutChar>::value)>
|
||||
auto copy_str(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
|
||||
while (begin != end) *out++ = static_cast<char8_type>(*begin++);
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename OutChar, typename InputIt,
|
||||
FMT_ENABLE_IF(!needs_conversion<InputIt, OutChar>::value)>
|
||||
auto copy_str(InputIt begin, InputIt end, appender out) -> appender {
|
||||
get_container(out).append(begin, end);
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename OutChar, typename InputIt, typename OutputIt>
|
||||
FMT_CONSTEXPR FMT_NOINLINE auto copy_str_noinline(InputIt begin, InputIt end,
|
||||
OutputIt out) -> OutputIt {
|
||||
@@ -633,13 +593,6 @@ void buffer<T>::append(const U* begin, const U* end) {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename T, typename Traits>
|
||||
void iterator_buffer<OutputIt, T, Traits>::flush() {
|
||||
auto size = this->size();
|
||||
this->clear();
|
||||
out_ = copy_str<T>(data_, data_ + this->limit(size), out_);
|
||||
}
|
||||
|
||||
template <typename T, typename Enable = void>
|
||||
struct is_locale : std::false_type {};
|
||||
template <typename T>
|
||||
@@ -648,11 +601,6 @@ struct is_locale<T, void_t<decltype(T::classic())>> : std::true_type {};
|
||||
|
||||
FMT_MODULE_EXPORT_BEGIN
|
||||
|
||||
template <> struct is_char<wchar_t> : std::true_type {};
|
||||
template <> struct is_char<detail::char8_type> : std::true_type {};
|
||||
template <> struct is_char<char16_t> : std::true_type {};
|
||||
template <> struct is_char<char32_t> : std::true_type {};
|
||||
|
||||
// The number of characters to store in the basic_memory_buffer object itself
|
||||
// to avoid dynamic memory allocation.
|
||||
enum { inline_buffer_size = 500 };
|
||||
|
||||
@@ -35,6 +35,11 @@ template <typename... Args>
|
||||
using wformat_string = basic_format_string<wchar_t, type_identity_t<Args>...>;
|
||||
#endif
|
||||
|
||||
template <> struct is_char<wchar_t> : std::true_type {};
|
||||
template <> struct is_char<detail::char8_type> : std::true_type {};
|
||||
template <> struct is_char<char16_t> : std::true_type {};
|
||||
template <> struct is_char<char32_t> : std::true_type {};
|
||||
|
||||
template <typename... Args>
|
||||
constexpr format_arg_store<wformat_context, Args...> make_wformat_args(
|
||||
const Args&... args) {
|
||||
|
||||
Reference in New Issue
Block a user