MCPcopy Create free account
hub / github.com/LeelaChessZero/lc0 / FlowText

Function FlowText

src/utils/string.cc:99–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99std::vector<std::string> FlowText(const std::string& src, size_t width) {
100 std::vector<std::string> result;
101 auto paragraphs = StrSplit(src, "\n");
102 for (const auto& paragraph : paragraphs) {
103 result.emplace_back();
104 auto words = StrSplit(paragraph, " ");
105 for (const auto& word : words) {
106 if (result.back().empty()) {
107 // First word in line, always add.
108 } else if (result.back().size() + word.size() + 1 > width) {
109 // The line doesn't have space for a new word.
110 result.emplace_back();
111 } else {
112 // Appending to the current line.
113 result.back() += " ";
114 }
115 result.back() += word;
116 }
117 }
118 return result;
119}
120
121} // namespace lczero

Callers 1

FormatFlagFunction · 0.85

Calls 4

StrSplitFunction · 0.85
emplace_backMethod · 0.80
emptyMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected