Parses a formatted string in much the same way as parse_string, but handles \n by creating a new formatted_string.
| 97 | // Parses a formatted string in much the same way as parse_string, but |
| 98 | // handles \n by creating a new formatted_string. |
| 99 | void formatted_string::parse_string_to_multiple(const string &s, |
| 100 | vector<formatted_string> &out, |
| 101 | int wrap_col) |
| 102 | { |
| 103 | vector<int> colour_stack(1, LIGHTGREY); |
| 104 | vector<int> bg_stack(1, BLACK); |
| 105 | |
| 106 | vector<string> lines = split_string("\n", s, false, true); |
| 107 | if (wrap_col > 0) |
| 108 | { |
| 109 | vector<string> pre_split = std::move(lines); |
| 110 | for (string &line : pre_split) |
| 111 | { |
| 112 | do |
| 113 | { |
| 114 | lines.push_back(wordwrap_line(line, wrap_col, true, true)); |
| 115 | } |
| 116 | while (!line.empty()); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | for (const string &line : lines) |
| 121 | { |
| 122 | out.emplace_back(); |
| 123 | formatted_string& fs = out.back(); |
| 124 | // apply initial colors or the colors leftover on the stack from |
| 125 | // previous lines. Only apply background in case there was an explicit |
| 126 | // bg tag from previous lines. |
| 127 | fs.textcolour(colour_stack.back()); |
| 128 | if (bg_stack.size() > 1) |
| 129 | fs.textbackground(bg_stack.back()); |
| 130 | parse_string1(line, fs, colour_stack, bg_stack); |
| 131 | // if the colour strings are unbalanced at this point, reset the |
| 132 | // colors at the end of the line, and then re-apply them to the next |
| 133 | // line (if there is one) on the next cycle of this loop |
| 134 | if (colour_stack.back() != colour_stack.front()) |
| 135 | fs.textcolour(colour_stack.front()); // XXX: this does nothing |
| 136 | if (bg_stack.back() != bg_stack.front()) |
| 137 | fs.textbackground(bg_stack.front()); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | // Helper for the other parse_ methods. |
| 142 | void formatted_string::parse_string1(const string &s, formatted_string &fs, |
nothing calls this directly
no test coverage detected