38 "K",
"M",
"B",
"t",
"q",
"Q",
"s",
"S",
"o",
"n",
"d",
"U"};
46 inline std::string
formatNum(
int precision, int64_t amount) {
53 return std::to_string(amount);
59 return std::to_string(amount);
63 if (amount > std::pow(1000,
i + 2)) {
67 double r = amount / std::pow(1000,
i + 1);
68 result = std::to_string(r);
73 case 1: result = result.substr(0, 1) +
"00";
break;
74 case 2: result = result.substr(0, 2) +
"0";
break;
75 case 3: result = result.substr(0, 3);
break;
76 default: result = result.substr(0, precision + 1);
80 case 1: result = result.substr(0, 1) +
"0";
break;
81 case 2: result = result.substr(0, 2);
break;
82 default: result = result.substr(0, precision + 1);
86 case 1: result = result.substr(0, 1);
break;
87 default: result = result.substr(0, precision + 1);
94 return std::to_string(amount);
98 if (kbytes < 1024L * 2) {
99 return std::to_string(kbytes) +
"kB";
100 }
else if (kbytes < 1024L * 1024 * 2) {
101 return std::to_string(kbytes / 1024) +
"MB";
102 }
else if (kbytes < 1024L * 1024 * 1024 * 2) {
103 return std::to_string(kbytes / (1024 * 1024)) +
"GB";
105 return std::to_string(kbytes / (1024 * 1024 * 1024)) +
"TB";
108 inline std::string
formatTime(std::chrono::microseconds number) {
109 uint64_t sec = number.count() / 1000000;
111 uint64_t min = std::floor(sec / 60);
113 uint64_t hours = std::floor(min / 60);
115 uint64_t days = std::floor(hours / 24);
116 return std::to_string(days) +
"D";
118 return std::to_string(hours) +
"h";
122 uint64_t temp = std::floor((sec - (min * 60.0)) * 10.0 / 6.0);
123 return std::to_string(min) +
"." + std::to_string(temp).substr(0, 1) +
"m";
125 return std::to_string(min) +
"m";
126 }
else if (sec >= 10) {
127 return std::to_string(sec) +
"s";
128 }
else if (number.count() >= 1000000) {
129 std::string temp = std::to_string(number.count() / 100);
130 return temp.substr(0, 1) +
"." + temp.substr(1, 2) +
"s";
131 }
else if (number.count() >= 100000) {
132 std::string temp = std::to_string(number.count() / 1000);
133 return "." + temp.substr(0, 3) +
"s";
134 }
else if (number.count() >= 10000) {
135 std::string temp = std::to_string(number.count() / 1000);
136 return ".0" + temp.substr(0, 2) +
"s";
137 }
else if (number.count() >= 1000) {
138 std::string temp = std::to_string(number.count() / 1000);
139 return ".00" + temp.substr(0, 1) +
"s";
146 std::vector<std::vector<std::string>> result;
147 for (
auto& row : table.
getRows()) {
148 std::vector<std::string> result_row;
149 for (
auto& cell : row->getCells()) {
150 if (cell !=
nullptr) {
151 result_row.push_back(cell->toString(precision));
153 result_row.push_back(
"-");
156 result.push_back(result_row);
162 inline std::vector<std::string>
split(std::string toSplit, std::string delimiter) {
163 std::vector<std::string> elements;
164 std::string::size_type lastPos = 0;
165 auto pos = toSplit.find(delimiter, lastPos);
167 while (pos != std::string::npos) {
169 std::string newElement = toSplit.substr(lastPos, pos - lastPos);
170 elements.push_back(newElement);
172 lastPos = pos + delimiter.size();
173 pos = toSplit.find(delimiter, lastPos);
175 if (lastPos < toSplit.size()) {
176 elements.push_back(toSplit.substr(lastPos));
183 std::string whitespace =
" \t";
184 size_t first =
str.find_first_not_of(whitespace);
185 if (first != std::string::npos) {
187 size_t last =
str.find_last_not_of(whitespace);
197 struct stat buffer = {};
198 if (stat(name.c_str(), &buffer) == 0) {
199 if ((buffer.st_mode & S_IFMT) != 0) {
207 if (val.size() < 2) {
211 size_t start_pos = 0;
212 while ((start_pos = val.find(
'\\', start_pos)) != std::string::npos) {
213 val.erase(start_pos, 1);
214 if (start_pos < val.size()) {
215 if (val[start_pos] ==
'n' || val[start_pos] ==
't') {
216 val.replace(start_pos, 1,
" ");
221 if (val.at(0) ==
'"' && val.at(val.size() - 1) ==
'"') {
222 val = val.substr(1, val.size() - 2);
225 std::replace(val.begin(), val.end(),
'\n',
' ');
226 std::replace(val.begin(), val.end(),
'\t',
' ');
233 if (value.size() >= 2) {
234 if (value.at(0) ==
'"' && value.at(value.size() - 1) ==
'"') {
235 value = value.substr(1, value.size() - 2);
239 size_t start_pos = 0;
240 while ((start_pos = value.find(
'\\', start_pos)) != std::string::npos) {
241 value.replace(start_pos, 1,
"\\\\");
245 while ((start_pos = value.find(
'"', start_pos)) != std::string::npos) {
246 value.replace(start_pos, 1,
"\\\"");
254 if (std::isnan(val)) {
257 std::ostringstream
ss;
258 ss << std::scientific << std::setprecision(6) << val;