48 std::istringstream iss(inputTable);
50 vector<vector<string>> tableData;
53 while (std::getline(iss, line)) {
54 std::istringstream lineStream(line);
56 vector<string> rowData;
58 while (std::getline(lineStream, cell,
'|')) {
61 rowData.push_back(cell);
65 if (!rowData.empty()) {
66 tableData.push_back(std::move(rowData));
71 vector<size_t> columnWidths(tableData[0].size(), 0);
72 for (
const auto &row : tableData) {
73 if (columnWidths.size() < row.size()) {
74 columnWidths.resize(row.size(), 0);
77 for (
size_t i = 0; i < row.size(); ++i) {
78 columnWidths[i] = std::max(columnWidths[i], row[i].size());
83 std::ostringstream formattedTable;
84 for (
size_t rowNumber = 0; rowNumber < tableData.size(); ++rowNumber) {
85 const auto &row = tableData[rowNumber];
87 formattedTable <<
"|";
89 for (
size_t i = 0; i < row.size(); ++i) {
95 formattedTable <<
" " << std::setw(columnWidths[i]) << std::left << row[i]
98 formattedTable <<
"\n";
101 return formattedTable.str();