mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-02 02:29:08 +00:00
Move implementation specific stuff from format.h to format.cc.
This commit is contained in:
parent
c7cfa7d4e7
commit
fb32161fa4
10
format.cc
10
format.cc
@ -109,6 +109,12 @@ inline int safe_printf(char *buffer, size_t size, const char *format, ...) {
|
||||
|
||||
#endif // _MSC_VER
|
||||
|
||||
template <typename T>
|
||||
struct IsLongDouble { enum {VALUE = 0}; };
|
||||
|
||||
template <>
|
||||
struct IsLongDouble<long double> { enum {VALUE = 1}; };
|
||||
|
||||
const char RESET_COLOR[] = "\x1b[0m";
|
||||
|
||||
typedef void (*FormatFunc)(fmt::Writer &, int , fmt::StringRef);
|
||||
@ -260,8 +266,6 @@ inline Arg::StringValue<wchar_t> ignore_incompatible_str(
|
||||
Arg::StringValue<wchar_t> s) { return s; }
|
||||
} // namespace
|
||||
|
||||
int fmt::internal::signbit_noinline(double value) { return getsign(value); }
|
||||
|
||||
void fmt::SystemError::init(
|
||||
int error_code, StringRef format_str, const ArgList &args) {
|
||||
error_code_ = error_code;
|
||||
@ -645,7 +649,7 @@ void fmt::BasicWriter<Char>::write_double(T value, const FormatSpec &spec) {
|
||||
*format_ptr++ = '.';
|
||||
*format_ptr++ = '*';
|
||||
}
|
||||
if (internal::IsLongDouble<T>::VALUE)
|
||||
if (IsLongDouble<T>::VALUE)
|
||||
*format_ptr++ = 'L';
|
||||
*format_ptr++ = type;
|
||||
*format_ptr = '\0';
|
||||
|
14
format.h
14
format.h
@ -410,8 +410,6 @@ inline bool is_negative(T value) {
|
||||
return SignChecker<std::numeric_limits<T>::is_signed>::is_negative(value);
|
||||
}
|
||||
|
||||
int signbit_noinline(double value);
|
||||
|
||||
template <typename T>
|
||||
struct IntTraits {
|
||||
// Smallest of uint32_t and uint64_t that is large enough to represent
|
||||
@ -435,12 +433,6 @@ FMT_SPECIALIZE_MAKE_UNSIGNED(int, unsigned);
|
||||
FMT_SPECIALIZE_MAKE_UNSIGNED(long, unsigned long);
|
||||
FMT_SPECIALIZE_MAKE_UNSIGNED(LongLong, ULongLong);
|
||||
|
||||
template <typename T>
|
||||
struct IsLongDouble { enum {VALUE = 0}; };
|
||||
|
||||
template <>
|
||||
struct IsLongDouble<long double> { enum {VALUE = 1}; };
|
||||
|
||||
void report_unknown_type(char code, const char *type);
|
||||
|
||||
extern const uint32_t POWERS_OF_10_32[];
|
||||
@ -452,7 +444,7 @@ extern const uint64_t POWERS_OF_10_64[];
|
||||
inline unsigned count_digits(uint64_t n) {
|
||||
// Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
|
||||
// and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits.
|
||||
uint64_t t = (64 - __builtin_clzll(n | 1)) * 1233 >> 12;
|
||||
unsigned t = (64 - __builtin_clzll(n | 1)) * 1233 >> 12;
|
||||
return t - (n < POWERS_OF_10_64[t]) + 1;
|
||||
}
|
||||
# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
|
||||
@ -1862,10 +1854,10 @@ class FormatInt {
|
||||
}
|
||||
|
||||
void FormatSigned(LongLong value) {
|
||||
ULongLong abs_value = value;
|
||||
ULongLong abs_value = static_cast<ULongLong>(value);
|
||||
bool negative = value < 0;
|
||||
if (negative)
|
||||
abs_value = 0 - value;
|
||||
abs_value = 0 - abs_value;
|
||||
str_ = format_decimal(abs_value);
|
||||
if (negative)
|
||||
*--str_ = '-';
|
||||
|
@ -1,17 +1,21 @@
|
||||
set(TEST_MAIN_SRC test-main.cc gtest-extra.cc gtest-extra.h util.cc)
|
||||
add_library(test-main ${TEST_MAIN_SRC})
|
||||
target_link_libraries(test-main gtest format)
|
||||
target_link_libraries(test-main gtest)
|
||||
|
||||
# Adds a test.
|
||||
# Usage: add_fmt_test(name libs srcs...)
|
||||
function(add_fmt_test name libs)
|
||||
add_executable(${name} ${name}.cc ${ARGN})
|
||||
cmake_parse_arguments(add_fmt_test CUSTOM_LINK "" "" ${ARGN})
|
||||
add_executable(${name} ${name}.cc ${add_fmt_test_UNPARSED_ARGUMENTS})
|
||||
target_link_libraries(${name} ${libs})
|
||||
if (NOT add_fmt_test_CUSTOM_LINK)
|
||||
target_link_libraries(${name} format)
|
||||
endif ()
|
||||
add_test(${name} ${name})
|
||||
endfunction()
|
||||
|
||||
add_fmt_test(gtest-extra-test test-main)
|
||||
add_fmt_test(format-test test-main)
|
||||
add_fmt_test(format-test test-main CUSTOM_LINK ../posix.cc ../posix.h)
|
||||
add_fmt_test(printf-test test-main)
|
||||
foreach (target format-test printf-test)
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
@ -35,6 +35,13 @@
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
// Include format.cc instead of format.h to test implementation-specific stuff.
|
||||
#include "format.cc"
|
||||
#include "util.h"
|
||||
#include "gtest-extra.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(_WIN32) && !defined(__MINGW32__)
|
||||
// Fix MSVC warning about "unsafe" fopen.
|
||||
FILE *safe_fopen(const char *filename, const char *mode) {
|
||||
@ -45,12 +52,6 @@ FILE *safe_fopen(const char *filename, const char *mode) {
|
||||
#define fopen safe_fopen
|
||||
#endif
|
||||
|
||||
#include "format.h"
|
||||
#include "util.h"
|
||||
#include "gtest-extra.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
@ -1230,7 +1231,7 @@ TEST(FormatterTest, FormatNaN) {
|
||||
double nan = std::numeric_limits<double>::quiet_NaN();
|
||||
EXPECT_EQ("nan", format("{}", nan));
|
||||
EXPECT_EQ("+nan", format("{:+}", nan));
|
||||
if (fmt::internal::signbit_noinline(-nan))
|
||||
if (getsign(-nan))
|
||||
EXPECT_EQ("-nan", format("{}", -nan));
|
||||
else
|
||||
fmt::print("Warning: compiler doesn't handle negative NaN correctly");
|
||||
|
Loading…
Reference in New Issue
Block a user