cmDocumentationFormatter: All printing methods accept strings

This commit is contained in:
Alex Turbov
2022-08-23 11:58:44 +04:00
parent 21c3e2107d
commit 3feac60591
3 changed files with 14 additions and 13 deletions

View File

@@ -34,13 +34,13 @@ const char* skipToSpace(const char* ptr)
}
void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
const char* text)
std::string const& text) const
{
if (!text) {
if (text.empty()) {
return;
}
for (const char* ptr = text; *ptr;) {
for (const char* ptr = text.c_str(); *ptr;) {
// Any ptrs starting in a space are treated as preformatted text.
std::string preformatted;
while (*ptr == ' ') {
@@ -66,7 +66,7 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
paragraph.append(1, '\n');
}
if (!paragraph.empty()) {
this->PrintParagraph(os, paragraph.c_str());
this->PrintParagraph(os, paragraph);
}
}
}
@@ -86,7 +86,7 @@ void cmDocumentationFormatter::PrintPreformatted(std::ostream& os,
}
void cmDocumentationFormatter::PrintParagraph(std::ostream& os,
const char* text)
std::string const& text) const
{
if (this->TextIndent) {
os << std::string(this->TextIndent, ' ');
@@ -95,7 +95,8 @@ void cmDocumentationFormatter::PrintParagraph(std::ostream& os,
os << '\n';
}
void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text)
void cmDocumentationFormatter::PrintColumn(std::ostream& os,
std::string const& text) const
{
// Print text arranged in an indented column of fixed width.
bool newSentence = false;
@@ -106,7 +107,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text)
std::ptrdiff_t column = 0;
// Loop until the end of the text.
for (const char *l = text, *r = skipToSpace(text); *l;
for (const char *l = text.c_str(), *r = skipToSpace(text.c_str()); *l;
l = skipSpaces(r), r = skipToSpace(l)) {
// Does it fit on this line?
if (r - l < width - column - std::ptrdiff_t(newSentence)) {
@@ -182,12 +183,12 @@ void cmDocumentationFormatter::PrintSection(
os << '\n' << std::setw(int(this->TextIndent - PREFIX_SIZE)) << ' ';
}
os << "= ";
this->PrintColumn(os, entry.Brief.c_str());
this->PrintColumn(os, entry.Brief);
os << '\n';
} else {
os << '\n';
this->TextIndent = 0u;
this->PrintFormatted(os, entry.Brief.c_str());
this->PrintFormatted(os, entry.Brief);
}
}

View File

@@ -13,11 +13,11 @@ class cmDocumentationSection;
class cmDocumentationFormatter
{
public:
void PrintFormatted(std::ostream& os, const char* text);
void PrintFormatted(std::ostream& os, std::string const& text) const;
void PrintPreformatted(std::ostream& os, std::string const& text) const;
void PrintSection(std::ostream& os, cmDocumentationSection const& section);
void PrintParagraph(std::ostream& os, const char* text);
void PrintColumn(std::ostream& os, const char* text);
void PrintParagraph(std::ostream& os, std::string const& text) const;
void PrintColumn(std::ostream& os, std::string const& text) const;
void SetIndent(std::size_t indent) { this->TextIndent = indent; }
private:

View File

@@ -108,7 +108,7 @@ static void printMessageText(std::ostream& msg, std::string const& text)
msg << ":\n";
cmDocumentationFormatter formatter;
formatter.SetIndent(2u);
formatter.PrintFormatted(msg, text.c_str());
formatter.PrintFormatted(msg, text);
}
static void displayMessage(MessageType t, std::ostringstream& msg)