MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / WordWrap

Function WordWrap

tensorflow/core/framework/op_gen_lib.cc:32–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30namespace tensorflow {
31
32string 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
71bool ConsumeEquals(StringPiece* description) {
72 if (absl::ConsumePrefix(description, "=")) {

Callers 7

HandleGraphModeMethod · 0.85
AddEagerAttrsMethod · 0.85
AddEagerExecuteMethod · 0.85
AddOutputGlobalsMethod · 0.85
AddBodyNoReturnMethod · 0.85
GetConstructorDeclMethod · 0.85

Calls 7

SpacesFunction · 0.85
EndsWithFunction · 0.85
StrAppendFunction · 0.50
ConsumePrefixFunction · 0.50
sizeMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected