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

Function FormatLine

Source/cmDocumentationFormatter.cxx:27–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25 std::string(cmDocumentationFormatter::TEXT_WIDTH, ' ');
26
27void FormatLine(std::back_insert_iterator<std::vector<cm::string_view>> outIt,
28 cm::string_view const text, cm::string_view const padding)
29{
30 auto tokens = cmTokenizedView(text, ' ', cmTokenizerMode::New);
31 if (tokens.empty()) {
32 return;
33 }
34
35 // Push padding in front of a first line
36 if (!padding.empty()) {
37 outIt = padding;
38 }
39
40 auto currentWidth = padding.size();
41 auto newSentence = false;
42
43 for (auto token : tokens) {
44 // It's no need to add a space if this is a very first
45 // word on a line.
46 auto const needSpace = currentWidth > padding.size();
47 // Evaluate the size of a current token + possibly spaces before it.
48 auto const tokenWithSpaceSize = token.size() + std::size_t(needSpace) +
49 std::size_t(needSpace && newSentence);
50 // Check if a current word fits on a line.
51 // Also, take in account:
52 // - extra space if not a first word on a line
53 // - extra space if last token ends w/ a period
54 if (currentWidth + tokenWithSpaceSize <=
55 cmDocumentationFormatter::TEXT_WIDTH) {
56 // If not a first word on a line...
57 if (needSpace) {
58 // ... add a space after the last token +
59 // possibly one more space if the last token
60 // ends with a period (means, end of a sentence).
61 outIt = newSentence ? TWO_SPACES : SPACE;
62 }
63 outIt = token;
64 currentWidth += tokenWithSpaceSize;
65 } else {
66 // Start a new line!
67 outIt = EOL;
68 if (!padding.empty()) {
69 outIt = padding;
70 }
71 outIt = token;
72 currentWidth = padding.size() + token.size();
73 }
74
75 // Start a new sentence if the current word ends with period
76 newSentence = token.back() == '.';
77 }
78 // Always add EOL at the end of formatted text
79 outIt = EOL;
80}
81} // anonymous namespace
82
83std::string cmDocumentationFormatter::Format(cm::string_view text) const

Callers 1

FormatMethod · 0.85

Calls 4

cmTokenizedViewFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…