cmDocumentationFormatter: TextIndent member is std::string now

Was `const char*`.
This commit is contained in:
Alex Turbov
2022-08-23 08:40:41 +04:00
parent b0fe4036b7
commit 5f3f811836
2 changed files with 17 additions and 20 deletions
+14 -18
View File
@@ -2,8 +2,8 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDocumentationFormatter.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <ostream>
#include <string>
@@ -14,6 +14,10 @@
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
namespace {
const std::string NAME_SIZED_PADDING = " ";
}
void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
const char* text)
{
@@ -55,9 +59,7 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
void cmDocumentationFormatter::PrintPreformatted(std::ostream& os,
std::string const& text) const
{
assert(this->TextIndent);
if (this->TextIndent[0]) {
if (!this->TextIndent.empty()) {
auto indented = text;
cmSystemTools::ReplaceString(indented, "\n",
cmStrCat('\n', this->TextIndent));
@@ -76,11 +78,6 @@ void cmDocumentationFormatter::PrintParagraph(std::ostream& os,
os << '\n';
}
void cmDocumentationFormatter::SetIndent(const char* indent)
{
this->TextIndent = indent;
}
void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text)
{
// Print text arranged in an indented column of fixed width.
@@ -88,7 +85,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text)
long column = 0;
bool newSentence = false;
bool firstLine = true;
int width = this->TextWidth - static_cast<int>(strlen(this->TextIndent));
int width = this->TextWidth - static_cast<int>(this->TextIndent.size());
// Loop until the end of the text.
while (*l) {
@@ -112,10 +109,10 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text)
os << ' ';
column += 1;
}
} else {
} else if (!firstLine && !this->TextIndent.empty()) {
// First word on line. Print indentation unless this is the
// first line.
os << (firstLine ? "" : this->TextIndent);
os << this->TextIndent;
}
// Print the word.
@@ -164,21 +161,20 @@ void cmDocumentationFormatter::PrintSection(
for (cmDocumentationEntry const& entry : entries) {
if (!entry.Name.empty()) {
os << std::setw(2) << std::left << entry.CustomNamePrefix << entry.Name;
this->TextIndent = " ";
int align = static_cast<int>(strlen(this->TextIndent)) - 4;
this->TextIndent = NAME_SIZED_PADDING;
int align = static_cast<int>(this->TextIndent.size()) - 4;
for (int i = static_cast<int>(entry.Name.size()); i < align; ++i) {
os << ' ';
}
if (entry.Name.size() > strlen(this->TextIndent) - 4) {
os << '\n';
os.write(this->TextIndent, strlen(this->TextIndent) - 2);
if (static_cast<int>(entry.Name.size()) > align) {
os << '\n' << this->TextIndent.substr(0, this->TextIndent.size() - 2);
}
os << "= ";
this->PrintColumn(os, entry.Brief.c_str());
os << '\n';
} else {
os << '\n';
this->TextIndent = "";
this->TextIndent = {};
this->PrintFormatted(os, entry.Brief.c_str());
}
}
+3 -2
View File
@@ -5,6 +5,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
class cmDocumentationSection;
@@ -17,9 +18,9 @@ public:
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 SetIndent(const char* indent);
void SetIndent(std::string indent) { this->TextIndent = std::move(indent); }
private:
int TextWidth = 77;
const char* TextIndent = "";
std::string TextIndent = {};
};