MCPcopy Create free account
hub / github.com/aardappel/treesheets / VectorOrObjectToString

Function VectorOrObjectToString

lobster/src/vmdata.cpp:321–360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319}
320
321void VectorOrObjectToString(VM &vm, ostringstream &ss, PrintPrefs &pp, char openb, char closeb,
322 intp len, intp width, const Value *elems, bool is_vector,
323 std::function<const TypeInfo &(intp)> getti) {
324 ss << openb;
325 if (pp.indent) ss << '\n';
326 auto start_size = ss.tellp();
327 pp.cur_indent += pp.indent;
328 auto Indent = [&]() {
329 for (int i = 0; i < pp.cur_indent; i++) ss << ' ';
330 };
331 for (intp i = 0; i < len; i++) {
332 if (i) {
333 ss << ',';
334 ss << (pp.indent ? '\n' : ' ');
335 }
336 if (pp.indent) Indent();
337 if ((int)ss.tellp() - start_size > pp.budget) {
338 ss << "....";
339 break;
340 }
341 auto &ti = getti(i);
342 if (pp.depth || !IsRef(ti.t)) {
343 PrintPrefs subpp(pp.depth - 1, pp.budget - (int)(ss.tellp() - start_size), true,
344 pp.decimals);
345 subpp.indent = pp.indent;
346 subpp.cur_indent = pp.cur_indent;
347 if (IsStruct(ti.t)) {
348 vm.StructToString(ss, subpp, ti, elems + i * width);
349 if (!is_vector) i += ti.len - 1;
350 } else {
351 elems[i].ToString(vm, ss, ti, subpp);
352 }
353 } else {
354 ss << "..";
355 }
356 }
357 pp.cur_indent -= pp.indent;
358 if (pp.indent) { ss << '\n'; Indent(); }
359 ss << closeb;
360}
361
362void LObject::ToString(VM &vm, ostringstream &ss, PrintPrefs &pp) {
363 if (CycleCheck(ss, pp)) return;

Callers 2

ToStringMethod · 0.85
StructToStringMethod · 0.85

Calls 5

IndentFunction · 0.85
IsRefFunction · 0.85
IsStructFunction · 0.50
StructToStringMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected