mirror of
https://github.com/fmtlib/fmt.git
synced 2025-08-01 03:34:45 +02:00
Add FormatInt::data() and document members.
This commit is contained in:
@@ -1408,6 +1408,11 @@ TEST(FormatterTest, Examples) {
|
|||||||
ReportError("File not found: {0}") << path;
|
ReportError("File not found: {0}") << path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(FormatIntTest, Data) {
|
||||||
|
fmt::FormatInt format_int(42);
|
||||||
|
EXPECT_EQ("42", std::string(format_int.data(), format_int.size()));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(FormatIntTest, FormatInt) {
|
TEST(FormatIntTest, FormatInt) {
|
||||||
EXPECT_EQ("42", fmt::FormatInt(42).str());
|
EXPECT_EQ("42", fmt::FormatInt(42).str());
|
||||||
EXPECT_EQ(2, fmt::FormatInt(42).size());
|
EXPECT_EQ(2, fmt::FormatInt(42).size());
|
||||||
|
20
format.h
20
format.h
@@ -1330,12 +1330,30 @@ class FormatInt {
|
|||||||
explicit FormatInt(unsigned long value) : str_(FormatDecimal(value)) {}
|
explicit FormatInt(unsigned long value) : str_(FormatDecimal(value)) {}
|
||||||
explicit FormatInt(unsigned long long value) : str_(FormatDecimal(value)) {}
|
explicit FormatInt(unsigned long long value) : str_(FormatDecimal(value)) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the number of characters written to the output buffer.
|
||||||
|
*/
|
||||||
|
std::size_t size() const { return buffer_ - str_ + BUFFER_SIZE - 1; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a pointer to the output buffer content. No terminating null
|
||||||
|
character is appended.
|
||||||
|
*/
|
||||||
|
const char *data() const { return str_; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a pointer to the output buffer content with terminating null
|
||||||
|
character appended.
|
||||||
|
*/
|
||||||
const char *c_str() const {
|
const char *c_str() const {
|
||||||
buffer_[BUFFER_SIZE - 1] = '\0';
|
buffer_[BUFFER_SIZE - 1] = '\0';
|
||||||
return str_;
|
return str_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the content of the output buffer as an `std::string`.
|
||||||
|
*/
|
||||||
std::string str() const { return std::string(str_, size()); }
|
std::string str() const { return std::string(str_, size()); }
|
||||||
std::size_t size() const { return buffer_ - str_ + BUFFER_SIZE - 1; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Formats a decimal integer value writing into buffer and returns
|
// Formats a decimal integer value writing into buffer and returns
|
||||||
|
Reference in New Issue
Block a user