MCPcopy Create free account
hub / github.com/Cantera/cantera / stringColumn

Function stringColumn

src/base/SolutionArray.cpp:377–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

375}
376
377vector<string> stringColumn(string name, const vector<string>& comp,
378 int rows, int width)
379{
380 // extract data for processing
381 vector<string> data;
382 string notation = fmt::format("{{:{}}}", width);
383 size_t maxLen = 3; // minimum column width is 3
384 int csize = static_cast<int>(comp.size());
385 int dots = csize + 1;
386 if (csize <= rows) {
387 for (const auto& val : comp) {
388 data.push_back(val);
389 maxLen = std::max(maxLen,
390 boost::trim_copy(fmt::format(fmt::runtime(notation), val)).size());
391 }
392 } else {
393 dots = (rows + 1) / 2;
394 for (int row = 0; row < dots; row++) {
395 data.push_back(comp[row]);
396 maxLen = std::max(maxLen,
397 boost::trim_copy(
398 fmt::format(fmt::runtime(notation), comp[row])).size());
399 }
400 for (int row = csize - rows / 2; row < csize; row++) {
401 data.push_back(comp[row]);
402 maxLen = std::max(maxLen,
403 boost::trim_copy(
404 fmt::format(fmt::runtime(notation), comp[row])).size());
405 }
406 }
407
408 // assemble output
409 notation = fmt::format(" {{:>{}}}", maxLen);
410 vector<string> col = {fmt::format(fmt::runtime(notation), name)};
411 int count = 0;
412 for (const auto& val : data) {
413 col.push_back(fmt::format(fmt::runtime(notation), val));
414 count++;
415 if (count == dots) {
416 col.push_back(fmt::format(fmt::runtime(notation), "..."));
417 }
418 }
419 return col;
420}
421
422vector<string> formatColumn(string name, const AnyValue& comp, int rows, int width)
423{

Callers 1

formatColumnFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected