mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Use char_traits::length in string_view ctor (#914)
This commit is contained in:
@ -208,17 +208,6 @@ FMT_CONSTEXPR typename std::make_unsigned<Int>::type to_unsigned(Int value) {
|
|||||||
return static_cast<typename std::make_unsigned<Int>::type>(value);
|
return static_cast<typename std::make_unsigned<Int>::type>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A constexpr std::char_traits::length replacement for pre-C++17.
|
|
||||||
template <typename Char>
|
|
||||||
FMT_CONSTEXPR size_t length(const Char *s) {
|
|
||||||
const Char *start = s;
|
|
||||||
while (*s) ++s;
|
|
||||||
return s - start;
|
|
||||||
}
|
|
||||||
#if FMT_GCC_VERSION && !defined(__arm__)
|
|
||||||
FMT_CONSTEXPR size_t length(const char *s) { return std::strlen(s); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 405
|
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 405
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
struct is_constructible: std::false_type {};
|
struct is_constructible: std::false_type {};
|
||||||
@ -377,8 +366,8 @@ class basic_string_view {
|
|||||||
the size with ``std::char_traits<Char>::length``.
|
the size with ``std::char_traits<Char>::length``.
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
FMT_CONSTEXPR basic_string_view(const Char *s)
|
basic_string_view(const Char *s)
|
||||||
: data_(s), size_(internal::length(s)) {}
|
: data_(s), size_(std::char_traits<Char>::length(s)) {}
|
||||||
|
|
||||||
/** Constructs a string reference from a ``std::basic_string`` object. */
|
/** Constructs a string reference from a ``std::basic_string`` object. */
|
||||||
template <typename Alloc>
|
template <typename Alloc>
|
||||||
@ -422,6 +411,7 @@ class basic_string_view {
|
|||||||
}
|
}
|
||||||
friend bool operator<(basic_string_view lhs, basic_string_view rhs) {
|
friend bool operator<(basic_string_view lhs, basic_string_view rhs) {
|
||||||
return lhs.compare(rhs) < 0;
|
return lhs.compare(rhs) < 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
friend bool operator<=(basic_string_view lhs, basic_string_view rhs) {
|
friend bool operator<=(basic_string_view lhs, basic_string_view rhs) {
|
||||||
return lhs.compare(rhs) <= 0;
|
return lhs.compare(rhs) <= 0;
|
||||||
|
@ -2273,9 +2273,10 @@ struct test_format_string_handler {
|
|||||||
bool error = false;
|
bool error = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
FMT_CONSTEXPR bool parse_string(fmt::string_view s) {
|
template <size_t N>
|
||||||
|
FMT_CONSTEXPR bool parse_string(const char (&s)[N]) {
|
||||||
test_format_string_handler h;
|
test_format_string_handler h;
|
||||||
fmt::internal::parse_format_string<true>(s, h);
|
fmt::internal::parse_format_string<true>(fmt::string_view(s, N - 1), h);
|
||||||
return !h.error;
|
return !h.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user