mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-30 05:40:06 +00:00
Reduce char_traits usage
This commit is contained in:
parent
61f144bd61
commit
c9287eb9f7
@ -8,10 +8,10 @@
|
||||
#ifndef FMT_CORE_H_
|
||||
#define FMT_CORE_H_
|
||||
|
||||
#include <cstddef> // std::byte
|
||||
#include <cstdio> // std::FILE
|
||||
#include <cstring> // std::strlen
|
||||
#include <limits> // std::numeric_limits
|
||||
#include <cstddef> // std::byte
|
||||
#include <cstdio> // std::FILE
|
||||
#include <cstring> // std::strlen
|
||||
#include <limits> // std::numeric_limits
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
@ -445,6 +445,12 @@ FMT_CONSTEXPR inline auto is_utf8() -> bool {
|
||||
return FMT_UNICODE || (sizeof(section) == 3 && uchar(section[0]) == 0xC2 &&
|
||||
uchar(section[1]) == 0xA7);
|
||||
}
|
||||
|
||||
template <typename Char> FMT_CONSTEXPR auto length(const Char* s) -> size_t {
|
||||
size_t len = 0;
|
||||
while (*s++) ++len;
|
||||
return len;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
@ -476,14 +482,14 @@ template <typename Char> class basic_string_view {
|
||||
the size with ``std::char_traits<Char>::length``.
|
||||
\endrst
|
||||
*/
|
||||
FMT_CONSTEXPR_CHAR_TRAITS
|
||||
FMT_CONSTEXPR20
|
||||
FMT_INLINE
|
||||
basic_string_view(const Char* s)
|
||||
: data_(s),
|
||||
size_(detail::const_check(std::is_same<Char, char>::value &&
|
||||
!detail::is_constant_evaluated(true))
|
||||
!detail::is_constant_evaluated(false))
|
||||
? std::strlen(reinterpret_cast<const char*>(s))
|
||||
: std::char_traits<Char>::length(s)) {}
|
||||
: detail::length(s)) {}
|
||||
|
||||
/** Constructs a string reference from a ``std::basic_string`` object. */
|
||||
template <typename Traits, typename Alloc>
|
||||
@ -519,8 +525,8 @@ template <typename Char> class basic_string_view {
|
||||
return size_ >= sv.size_ &&
|
||||
std::char_traits<Char>::compare(data_, sv.data_, sv.size_) == 0;
|
||||
}
|
||||
FMT_CONSTEXPR_CHAR_TRAITS auto starts_with(Char c) const noexcept -> bool {
|
||||
return size_ >= 1 && std::char_traits<Char>::eq(*data_, c);
|
||||
FMT_CONSTEXPR auto starts_with(Char c) const noexcept -> bool {
|
||||
return size_ >= 1 && *data_ == c;
|
||||
}
|
||||
FMT_CONSTEXPR_CHAR_TRAITS auto starts_with(const Char* s) const -> bool {
|
||||
return starts_with(basic_string_view<Char>(s));
|
||||
@ -1544,8 +1550,7 @@ template <> struct is_output_iterator<appender, char> : std::true_type {};
|
||||
|
||||
template <typename It, typename T>
|
||||
struct is_output_iterator<
|
||||
It, T,
|
||||
void_t<decltype(*std::declval<It&>()++ = std::declval<T>())>>
|
||||
It, T, void_t<decltype(*std::declval<It&>()++ = std::declval<T>())>>
|
||||
: std::true_type {};
|
||||
|
||||
template <typename It> struct is_back_insert_iterator : std::false_type {};
|
||||
|
@ -38,10 +38,10 @@
|
||||
#include <cstring> // std::memcpy
|
||||
#include <initializer_list> // std::initializer_list
|
||||
#include <iterator>
|
||||
#include <limits> // std::numeric_limits
|
||||
#include <memory> // std::uninitialized_copy
|
||||
#include <stdexcept> // std::runtime_error
|
||||
#include <system_error> // std::system_error
|
||||
#include <limits> // std::numeric_limits
|
||||
#include <memory> // std::uninitialized_copy
|
||||
#include <stdexcept> // std::runtime_error
|
||||
#include <system_error> // std::system_error
|
||||
|
||||
#ifdef __cpp_lib_bit_cast
|
||||
# include <bit> // std::bit_cast
|
||||
|
Loading…
Reference in New Issue
Block a user