forked from fmtlib/fmt
FormatDec -> format_decimal
This commit is contained in:
2
format.h
2
format.h
@ -1894,7 +1894,7 @@ class FormatInt {
|
|||||||
// a pointer to the end of the formatted string. This function doesn't
|
// a pointer to the end of the formatted string. This function doesn't
|
||||||
// write a terminating null character.
|
// write a terminating null character.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void FormatDec(char *&buffer, T value) {
|
inline void format_decimal(char *&buffer, T value) {
|
||||||
typename internal::IntTraits<T>::MainType abs_value = value;
|
typename internal::IntTraits<T>::MainType abs_value = value;
|
||||||
if (internal::is_negative(value)) {
|
if (internal::is_negative(value)) {
|
||||||
*buffer++ = '-';
|
*buffer++ = '-';
|
||||||
|
@ -1455,27 +1455,28 @@ TEST(FormatIntTest, FormatInt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::string FormatDec(T value) {
|
std::string format_decimal(T value) {
|
||||||
char buffer[10];
|
char buffer[10];
|
||||||
char *ptr = buffer;
|
char *ptr = buffer;
|
||||||
fmt::FormatDec(ptr, value);
|
fmt::format_decimal(ptr, value);
|
||||||
return std::string(buffer, ptr);
|
return std::string(buffer, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatIntTest, FormatDec) {
|
TEST(FormatIntTest, FormatDec) {
|
||||||
EXPECT_EQ("-42", FormatDec(static_cast<char>(-42)));
|
EXPECT_EQ("-42", format_decimal(static_cast<char>(-42)));
|
||||||
EXPECT_EQ("-42", FormatDec(static_cast<short>(-42)));
|
EXPECT_EQ("-42", format_decimal(static_cast<short>(-42)));
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << std::numeric_limits<unsigned short>::max();
|
os << std::numeric_limits<unsigned short>::max();
|
||||||
EXPECT_EQ(os.str(), FormatDec(std::numeric_limits<unsigned short>::max()));
|
EXPECT_EQ(os.str(),
|
||||||
EXPECT_EQ("1", FormatDec(1));
|
format_decimal(std::numeric_limits<unsigned short>::max()));
|
||||||
EXPECT_EQ("-1", FormatDec(-1));
|
EXPECT_EQ("1", format_decimal(1));
|
||||||
EXPECT_EQ("42", FormatDec(42));
|
EXPECT_EQ("-1", format_decimal(-1));
|
||||||
EXPECT_EQ("-42", FormatDec(-42));
|
EXPECT_EQ("42", format_decimal(42));
|
||||||
EXPECT_EQ("42", FormatDec(42l));
|
EXPECT_EQ("-42", format_decimal(-42));
|
||||||
EXPECT_EQ("42", FormatDec(42ul));
|
EXPECT_EQ("42", format_decimal(42l));
|
||||||
EXPECT_EQ("42", FormatDec(42ll));
|
EXPECT_EQ("42", format_decimal(42ul));
|
||||||
EXPECT_EQ("42", FormatDec(42ull));
|
EXPECT_EQ("42", format_decimal(42ll));
|
||||||
|
EXPECT_EQ("42", format_decimal(42ull));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatTest, Print) {
|
TEST(FormatTest, Print) {
|
||||||
|
Reference in New Issue
Block a user