| 13 | using std::regex_replace; |
| 14 | |
| 15 | vector<string> splitIntoLines(const string& s) { |
| 16 | vector<string> lines; |
| 17 | auto p = &s[0]; |
| 18 | auto lineBegin = p; |
| 19 | const auto end = p + s.size(); |
| 20 | // Iterate over input string |
| 21 | while (p <= end) { |
| 22 | // Add a new result line when we hit a \n character or the end of the string |
| 23 | if (p == end || *p == '\n') { |
| 24 | string line(lineBegin, p); |
| 25 | // Trim \r characters |
| 26 | boost::algorithm::trim_if(line, [](char c) { return c == '\r'; }); |
| 27 | lines.push_back(line); |
| 28 | lineBegin = p + 1; |
| 29 | } |
| 30 | ++p; |
| 31 | } |
| 32 | |
| 33 | return lines; |
| 34 | } |
| 35 | |
| 36 | vector<string> wrapSingleLineString(const string& s, int lineLength, int hangingIndent) { |
| 37 | if (lineLength <= 0) throw std::invalid_argument("lineLength must be > 0."); |