From 3feac60591ea0a4b010c7f21eb9e8854d159d9a0 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 11:58:44 +0400 Subject: cmDocumentationFormatter: All printing methods accept strings --- Source/cmDocumentationFormatter.cxx | 19 ++++++++++--------- Source/cmDocumentationFormatter.h | 6 +++--- Source/cmMessenger.cxx | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index daa78f1..6d170ab 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -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); } } diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index 113db1e..ca942bc 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -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: diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx index cae7216..ff513be 100644 --- a/Source/cmMessenger.cxx +++ b/Source/cmMessenger.cxx @@ -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) -- cgit v0.12