Indent the first line by "initial" spaces and all following lines by "rest" spaces.
| 118 | // Indent the first line by "initial" spaces and all following lines |
| 119 | // by "rest" spaces. |
| 120 | string Indent(int initial, int rest, StringPiece in) { |
| 121 | // TODO(josh11b): Also word-wrapping? |
| 122 | string copy(in.data(), in.size()); |
| 123 | absl::StripTrailingAsciiWhitespace(©); |
| 124 | std::vector<string> v = str_util::Split(copy, '\n'); |
| 125 | |
| 126 | string result; |
| 127 | bool first = true; |
| 128 | for (const string& line : v) { |
| 129 | if (first) { |
| 130 | result = strings::StrCat(Spaces(initial), line, "\n"); |
| 131 | first = false; |
| 132 | } else { |
| 133 | if (line.empty()) { |
| 134 | strings::StrAppend(&result, "\n"); |
| 135 | } else { |
| 136 | strings::StrAppend(&result, Spaces(rest), line, "\n"); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | return result; |
| 141 | } |
| 142 | |
| 143 | // Adds append to *dest, with a space if the first line will be <= width, |
| 144 | // or a newline otherwise. |
no test coverage detected