| 30 | namespace tensorflow { |
| 31 | |
| 32 | string WordWrap(StringPiece prefix, StringPiece str, int width) { |
| 33 | const string indent_next_line = "\n" + Spaces(prefix.size()); |
| 34 | width -= prefix.size(); |
| 35 | string result; |
| 36 | strings::StrAppend(&result, prefix); |
| 37 | |
| 38 | while (!str.empty()) { |
| 39 | if (static_cast<int>(str.size()) <= width) { |
| 40 | // Remaining text fits on one line. |
| 41 | strings::StrAppend(&result, str); |
| 42 | break; |
| 43 | } |
| 44 | auto space = str.rfind(' ', width); |
| 45 | if (space == StringPiece::npos) { |
| 46 | // Rather make a too-long line and break at a space. |
| 47 | space = str.find(' '); |
| 48 | if (space == StringPiece::npos) { |
| 49 | strings::StrAppend(&result, str); |
| 50 | break; |
| 51 | } |
| 52 | } |
| 53 | // Breaking at character at position <space>. |
| 54 | StringPiece to_append = str.substr(0, space); |
| 55 | str.remove_prefix(space + 1); |
| 56 | // Remove spaces at break. |
| 57 | while (str_util::EndsWith(to_append, " ")) { |
| 58 | to_append.remove_suffix(1); |
| 59 | } |
| 60 | while (absl::ConsumePrefix(&str, " ")) { |
| 61 | } |
| 62 | |
| 63 | // Go on to the next line. |
| 64 | strings::StrAppend(&result, to_append); |
| 65 | if (!str.empty()) strings::StrAppend(&result, indent_next_line); |
| 66 | } |
| 67 | |
| 68 | return result; |
| 69 | } |
| 70 | |
| 71 | bool ConsumeEquals(StringPiece* description) { |
| 72 | if (absl::ConsumePrefix(description, "=")) { |
no test coverage detected