summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2022-08-23 04:14:48 (GMT)
committerAlex Turbov <i.zaufi@gmail.com>2022-11-17 12:23:35 (GMT)
commitb0fe4036b7ec2aa7540c7080f14c921e9a485ae3 (patch)
tree07410a73f43aa38dc49fd10700940614cc9f12d1
parent3be0d77cc4ae10506fb513987067e9515169a401 (diff)
downloadCMake-b0fe4036b7ec2aa7540c7080f14c921e9a485ae3.zip
CMake-b0fe4036b7ec2aa7540c7080f14c921e9a485ae3.tar.gz
CMake-b0fe4036b7ec2aa7540c7080f14c921e9a485ae3.tar.bz2
cmDocumentationFormatter: `PrintPreformatted` accept string
Also, make it `const` method cuz it's not modify the state.
-rw-r--r--Source/cmDocumentationFormatter.cxx28
-rw-r--r--Source/cmDocumentationFormatter.h2
2 files changed, 16 insertions, 14 deletions
diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx
index 5773362..8cf101c 100644
--- a/Source/cmDocumentationFormatter.cxx
+++ b/Source/cmDocumentationFormatter.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDocumentationFormatter.h"
+#include <cassert>
#include <cstring>
#include <iomanip>
#include <ostream>
@@ -10,6 +11,8 @@
#include "cmDocumentationEntry.h"
#include "cmDocumentationSection.h"
+#include "cmStringAlgorithms.h"
+#include "cmSystemTools.h"
void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
const char* text)
@@ -31,7 +34,7 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
}
}
if (!preformatted.empty()) {
- this->PrintPreformatted(os, preformatted.c_str());
+ this->PrintPreformatted(os, preformatted);
}
// Other ptrs are treated as paragraphs.
@@ -50,20 +53,19 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
}
void cmDocumentationFormatter::PrintPreformatted(std::ostream& os,
- const char* text)
+ std::string const& text) const
{
- bool newline = true;
- for (const char* ptr = text; *ptr; ++ptr) {
- if (newline && *ptr != '\n') {
- os << this->TextIndent;
- newline = false;
- }
- os << *ptr;
- if (*ptr == '\n') {
- newline = true;
- }
+ assert(this->TextIndent);
+
+ if (this->TextIndent[0]) {
+ auto indented = text;
+ cmSystemTools::ReplaceString(indented, "\n",
+ cmStrCat('\n', this->TextIndent));
+ indented.insert(0u, this->TextIndent);
+ os << indented << '\n';
+ } else {
+ os << text << '\n';
}
- os << '\n';
}
void cmDocumentationFormatter::PrintParagraph(std::ostream& os,
diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h
index ca7ad0c..6f2ccb4 100644
--- a/Source/cmDocumentationFormatter.h
+++ b/Source/cmDocumentationFormatter.h
@@ -13,8 +13,8 @@ class cmDocumentationFormatter
{
public:
void PrintFormatted(std::ostream& os, const char* text);
+ void PrintPreformatted(std::ostream& os, std::string const& text) const;
void PrintSection(std::ostream& os, cmDocumentationSection const& section);
- void PrintPreformatted(std::ostream& os, const char* text);
void PrintParagraph(std::ostream& os, const char* text);
void PrintColumn(std::ostream& os, const char* text);
void SetIndent(const char* indent);