FormatDec -> format_decimal

This commit is contained in:
Victor Zverovich 2014-07-29 08:45:29 -07:00
parent bf5b246717
commit d346a4120d
2 changed files with 15 additions and 14 deletions

View File

@ -1894,7 +1894,7 @@ class FormatInt {
// a pointer to the end of the formatted string. This function doesn't
// write a terminating null character.
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;
if (internal::is_negative(value)) {
*buffer++ = '-';

View File

@ -1455,27 +1455,28 @@ TEST(FormatIntTest, FormatInt) {
}
template <typename T>
std::string FormatDec(T value) {
std::string format_decimal(T value) {
char buffer[10];
char *ptr = buffer;
fmt::FormatDec(ptr, value);
fmt::format_decimal(ptr, value);
return std::string(buffer, ptr);
}
TEST(FormatIntTest, FormatDec) {
EXPECT_EQ("-42", FormatDec(static_cast<char>(-42)));
EXPECT_EQ("-42", FormatDec(static_cast<short>(-42)));
EXPECT_EQ("-42", format_decimal(static_cast<char>(-42)));
EXPECT_EQ("-42", format_decimal(static_cast<short>(-42)));
std::ostringstream os;
os << std::numeric_limits<unsigned short>::max();
EXPECT_EQ(os.str(), FormatDec(std::numeric_limits<unsigned short>::max()));
EXPECT_EQ("1", FormatDec(1));
EXPECT_EQ("-1", FormatDec(-1));
EXPECT_EQ("42", FormatDec(42));
EXPECT_EQ("-42", FormatDec(-42));
EXPECT_EQ("42", FormatDec(42l));
EXPECT_EQ("42", FormatDec(42ul));
EXPECT_EQ("42", FormatDec(42ll));
EXPECT_EQ("42", FormatDec(42ull));
EXPECT_EQ(os.str(),
format_decimal(std::numeric_limits<unsigned short>::max()));
EXPECT_EQ("1", format_decimal(1));
EXPECT_EQ("-1", format_decimal(-1));
EXPECT_EQ("42", format_decimal(42));
EXPECT_EQ("-42", format_decimal(-42));
EXPECT_EQ("42", format_decimal(42l));
EXPECT_EQ("42", format_decimal(42ul));
EXPECT_EQ("42", format_decimal(42ll));
EXPECT_EQ("42", format_decimal(42ull));
}
TEST(FormatTest, Print) {