| 97 | } |
| 98 | |
| 99 | std::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 |
no test coverage detected