MCPcopy Create free account
hub / github.com/DanielSWolf/rhubarb-lip-sync / splitIntoLines

Function splitIntoLines

rhubarb/src/tools/stringTools.cpp:15–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13using std::regex_replace;
14
15vector<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
36vector<string> wrapSingleLineString(const string& s, int lineLength, int hangingIndent) {
37 if (lineLength <= 0) throw std::invalid_argument("lineLength must be > 0.");

Callers 2

wrapStringFunction · 0.85
TESTFunction · 0.85

Calls 2

sizeMethod · 0.45
push_backMethod · 0.45

Tested by 1

TESTFunction · 0.68