summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2022-08-23 07:58:44 (GMT)
committerAlex Turbov <i.zaufi@gmail.com>2022-11-17 12:37:09 (GMT)
commit3feac60591ea0a4b010c7f21eb9e8854d159d9a0 (patch)
tree104536e1b730910916cdebd82b7c810bff2e4ff8
parent21c3e2107d101954d6e2e60bbd2d660c6d95a455 (diff)
downloadCMake-3feac60591ea0a4b010c7f21eb9e8854d159d9a0.zip
CMake-3feac60591ea0a4b010c7f21eb9e8854d159d9a0.tar.gz
CMake-3feac60591ea0a4b010c7f21eb9e8854d159d9a0.tar.bz2
cmDocumentationFormatter: All printing methods accept strings
-rw-r--r--Source/cmDocumentationFormatter.cxx19
-rw-r--r--Source/cmDocumentationFormatter.h6
-rw-r--r--Source/cmMessenger.cxx2
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)