Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Attila Mark 2020-02-06 22:43:21 -08:00
commit 57763d0fe2
6 changed files with 33 additions and 19 deletions

View File

@ -176,17 +176,17 @@ target_include_directories(fmt PUBLIC
set(FMT_DEBUG_POSTFIX d) set(FMT_DEBUG_POSTFIX d)
set(FMT_DEBUG_POSTFIX d)
set_target_properties(fmt PROPERTIES set_target_properties(fmt PROPERTIES
OUTPUT_NAME fmt VERSION ${FMT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}
VERSION ${FMT_VERSION}
SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}
DEBUG_POSTFIX ${FMT_DEBUG_POSTFIX}) DEBUG_POSTFIX ${FMT_DEBUG_POSTFIX})
# Configure pkg-config fmt.pc properly # Set FMT_LIB_NAME for pkg-config fmt.pc.
get_target_property(FMT_LIB_NAME fmt OUTPUT_NAME) get_target_property(FMT_LIB_NAME fmt OUTPUT_NAME)
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(FMT_LIB_NAME ${FMT_LIB_NAME}${FMT_DEBUG_POSTFIX}) set(FMT_LIB_NAME ${FMT_LIB_NAME}${FMT_DEBUG_POSTFIX})
endif() endif ()
if (BUILD_SHARED_LIBS) if (BUILD_SHARED_LIBS)
if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")

View File

@ -33,7 +33,7 @@ Features
* Safe `printf implementation * Safe `printf implementation
<https://fmt.dev/latest/api.html#printf-formatting>`_ including <https://fmt.dev/latest/api.html#printf-formatting>`_ including
the POSIX extension for positional arguments. the POSIX extension for positional arguments.
* Implementation of `C++20 std::format <https://fmt.dev/Text%20Formatting.html>`__. * Implementation of `C++20 std::format <https://en.cppreference.com/w/cpp/utility/format>`__.
* Support for user-defined types. * Support for user-defined types.
* High performance: faster than common standard library implementations of * High performance: faster than common standard library implementations of
`printf <https://en.cppreference.com/w/cpp/io/c/fprintf>`_ and `printf <https://en.cppreference.com/w/cpp/io/c/fprintf>`_ and

View File

@ -495,12 +495,12 @@ FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
handler.on_text(ptr - 1, ptr); handler.on_text(ptr - 1, ptr);
break; break;
case 'n': { case 'n': {
const Char newline[]{'\n', 0}; const Char newline[] = {'\n'};
handler.on_text(newline, newline + 1); handler.on_text(newline, newline + 1);
break; break;
} }
case 't': { case 't': {
const Char tab[]{'\t', 0}; const Char tab[] = {'\t'};
handler.on_text(tab, tab + 1); handler.on_text(tab, tab + 1);
break; break;
} }
@ -761,10 +761,10 @@ inline std::chrono::duration<Rep, std::milli> get_milliseconds(
template <typename Char, typename Rep, typename OutputIt> template <typename Char, typename Rep, typename OutputIt>
OutputIt format_duration_value(OutputIt out, Rep val, int precision) { OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
const Char pr_f[]{'{', ':', '.', '{', '}', 'f', '}', 0}; const Char pr_f[] = {'{', ':', '.', '{', '}', 'f', '}', 0};
if (precision >= 0) return format_to(out, pr_f, val, precision); if (precision >= 0) return format_to(out, pr_f, val, precision);
const Char fp_f[]{'{', ':', 'g', '}', 0}; const Char fp_f[] = {'{', ':', 'g', '}', 0};
const Char format[]{'{', '}', 0}; const Char format[] = {'{', '}', 0};
return format_to(out, std::is_floating_point<Rep>::value ? fp_f : format, return format_to(out, std::is_floating_point<Rep>::value ? fp_f : format,
val); val);
} }
@ -779,9 +779,9 @@ OutputIt format_duration_unit(OutputIt out) {
} }
return std::copy(s.begin(), s.end(), out); return std::copy(s.begin(), s.end(), out);
} }
const Char num_f[]{'[', '{', '}', ']', 's', 0}; const Char num_f[] = {'[', '{', '}', ']', 's', 0};
if (Period::den == 1) return format_to(out, num_f, Period::num); if (Period::den == 1) return format_to(out, num_f, Period::num);
const Char num_def_f[]{'[', '{', '}', '/', '{', '}', ']', 's', 0}; const Char num_def_f[] = {'[', '{', '}', '/', '{', '}', ']', 's', 0};
return format_to(out, num_def_f, Period::num, Period::den); return format_to(out, num_def_f, Period::num, Period::den);
} }

View File

@ -185,11 +185,20 @@
# define FMT_CLASS_API # define FMT_CLASS_API
#endif #endif
#ifndef FMT_API #ifndef FMT_API
# define FMT_API # if FMT_GCC_VERSION || FMT_CLANG_VERSION
# define FMT_API __attribute__((visibility("default")))
# define FMT_EXTERN_TEMPLATE_API FMT_API
# define FMT_INSTANTIATION_DEF_API
# else
# define FMT_API
# endif
#endif #endif
#ifndef FMT_EXTERN_TEMPLATE_API #ifndef FMT_EXTERN_TEMPLATE_API
# define FMT_EXTERN_TEMPLATE_API # define FMT_EXTERN_TEMPLATE_API
#endif #endif
#ifndef FMT_INSTANTIATION_DEF_API
# define FMT_INSTANTIATION_DEF_API FMT_API
#endif
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
# define FMT_EXTERN extern # define FMT_EXTERN extern
@ -304,7 +313,8 @@ template <typename Char> class basic_string_view {
size_t size_; size_t size_;
public: public:
using char_type = Char; using char_type FMT_DEPRECATED_ALIAS = Char;
using value_type = Char;
using iterator = const Char*; using iterator = const Char*;
FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {} FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {}
@ -462,7 +472,7 @@ struct is_string : std::is_class<decltype(to_string_view(std::declval<S>()))> {
template <typename S, typename = void> struct char_t_impl {}; template <typename S, typename = void> struct char_t_impl {};
template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> { template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
using result = decltype(to_string_view(std::declval<S>())); using result = decltype(to_string_view(std::declval<S>()));
using type = typename result::char_type; using type = typename result::value_type;
}; };
struct error_handler { struct error_handler {

View File

@ -121,7 +121,7 @@ template FMT_API char* internal::sprintf_format(long double,
internal::buffer<char>&, internal::buffer<char>&,
sprintf_specs); sprintf_specs);
template struct FMT_API internal::basic_data<void>; template struct FMT_INSTANTIATION_DEF_API internal::basic_data<void>;
// Workaround a bug in MSVC2013 that prevents instantiation of format_float. // Workaround a bug in MSVC2013 that prevents instantiation of format_float.
int (*instantiate_format_float)(double, int, internal::float_specs, int (*instantiate_format_float)(double, int, internal::float_specs,

View File

@ -402,8 +402,12 @@ TEST(ArgTest, VisitInvalidArg) {
fmt::visit_format_arg(visitor, arg); fmt::visit_format_arg(visitor, arg);
} }
TEST(StringViewTest, ValueType) {
static_assert(std::is_same<string_view::value_type, char>::value, "");
}
TEST(StringViewTest, Length) { TEST(StringViewTest, Length) {
// Test that StringRef::size() returns string length, not buffer size. // Test that string_view::size() returns string length, not buffer size.
char str[100] = "some string"; char str[100] = "some string";
EXPECT_EQ(std::strlen(str), string_view(str).size()); EXPECT_EQ(std::strlen(str), string_view(str).size());
EXPECT_LT(std::strlen(str), sizeof(str)); EXPECT_LT(std::strlen(str), sizeof(str));