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

Function PBTxtFromMultiline

tensorflow/core/framework/op_gen_lib.cc:198–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196}
197
198string PBTxtFromMultiline(StringPiece multiline_pbtxt) {
199 string pbtxt;
200 // Probably big enough, since the input and output are about the
201 // same size, but just a guess.
202 pbtxt.reserve(multiline_pbtxt.size() * (33. / 32));
203 StringPiece line;
204 while (!multiline_pbtxt.empty()) {
205 // Split multiline_pbtxt into its first line and everything after.
206 if (!SplitAt('\n', &multiline_pbtxt, &line)) {
207 strings::StrAppend(&pbtxt, line);
208 break;
209 }
210
211 string end;
212 auto colon = line.find(':');
213 if (!FindMultiline(line, colon, &end)) {
214 // Normal case: not a multi-line string, just output the line as-is.
215 strings::StrAppend(&pbtxt, line, "\n");
216 continue;
217 }
218
219 // Multi-line case:
220 // something: <<END
221 // xx
222 // yy
223 // END
224 // Should be converted to:
225 // something: "xx\nyy"
226
227 // Output everything up to the colon (" something:").
228 strings::StrAppend(&pbtxt, line.substr(0, colon + 1));
229
230 // Add every line to unescaped until we see the "END" string.
231 string unescaped;
232 bool first = true;
233 while (!multiline_pbtxt.empty()) {
234 SplitAt('\n', &multiline_pbtxt, &line);
235 if (absl::ConsumePrefix(&line, end)) break;
236 if (first) {
237 first = false;
238 } else {
239 unescaped.push_back('\n');
240 }
241 strings::StrAppend(&unescaped, line);
242 line = StringPiece();
243 }
244
245 // Escape what we extracted and then output it in quotes.
246 strings::StrAppend(&pbtxt, " \"", absl::CEscape(unescaped), "\"", line,
247 "\n");
248 }
249 return pbtxt;
250}
251
252static void StringReplace(const string& from, const string& to, string* s) {
253 // Split *s into pieces delimited by `from`.

Callers 5

RunFunction · 0.85
LoadApiDefMethod · 0.85
TESTFunction · 0.85
GetGoldenApiDefsFunction · 0.85

Calls 10

SplitAtFunction · 0.85
FindMultilineFunction · 0.85
CEscapeFunction · 0.85
StrAppendFunction · 0.50
ConsumePrefixFunction · 0.50
reserveMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45
push_backMethod · 0.45

Tested by 3

TESTFunction · 0.68
GetGoldenApiDefsFunction · 0.68