MCPcopy Create free account
hub / github.com/Kitware/CMake / Format

Method Format

Source/cmDocumentationFormatter.cxx:83–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81} // anonymous namespace
82
83std::string cmDocumentationFormatter::Format(cm::string_view text) const
84{
85 // Exit early on empty text
86 if (text.empty()) {
87 return {};
88 }
89
90 assert(this->TextIndent < this->TEXT_WIDTH);
91
92 auto const padding =
93 cm::string_view(MAX_WIDTH_PADDING.c_str(), this->TextIndent);
94
95 std::vector<cm::string_view> tokens;
96 auto outIt = std::back_inserter(tokens);
97 auto prevWasPreFormatted = false;
98
99 // NOTE Can't use `cmTokenizedView()` cuz every sequential EOL does matter
100 // (and `cmTokenizedView()` will squeeze 'em)
101 for ( // clang-format off
102 std::string::size_type start = 0
103 , end = text.find('\n')
104 ; start < text.size()
105 ; start = end + ((end != std::string::npos) ? 1 : 0)
106 , end = text.find('\n', start)
107 ) // clang-format on
108 {
109 auto const isLastLine = end == std::string::npos;
110 auto const line =
111 isLastLine ? text.substr(start) : text.substr(start, end - start);
112
113 if (!line.empty() && line.front() == ' ') {
114 // Preformatted lines go as is w/ a leading padding
115 if (!padding.empty()) {
116 outIt = padding;
117 }
118 outIt = line;
119 prevWasPreFormatted = true;
120 } else {
121 // Separate a normal paragraph from a pre-formatted
122 // w/ an extra EOL
123 if (prevWasPreFormatted) {
124 outIt = EOL;
125 }
126 if (line.empty()) {
127 if (!isLastLine) {
128 outIt = EOL;
129 }
130 } else {
131 FormatLine(outIt, line, padding);
132 }
133 prevWasPreFormatted = false;
134 }
135 if (!isLastLine) {
136 outIt = EOL;
137 }
138 }
139
140 if (prevWasPreFormatted) {

Callers 2

PrintSectionMethod · 0.95
PrintFormattedMethod · 0.95

Calls 8

FormatLineFunction · 0.85
cmJoinStringsFunction · 0.85
c_strMethod · 0.80
emptyMethod · 0.45
findMethod · 0.45
sizeMethod · 0.45
substrMethod · 0.45
frontMethod · 0.45

Tested by

no test coverage detected