-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cpp
30 lines (27 loc) · 792 Bytes
/
Utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "Utils.h"
std::string trim(const std::string& value) {
std::string result = value;
if (value.starts_with(' ')) {
result.erase(0, result.find_first_not_of(' '));
}
if (value.ends_with(' ')) {
auto offset = result.find_first_of(' ');
result.erase(offset, result.size() - offset);
}
return result;
}
std::string truncateZero(const std::string& value) {
std::string result = value;
while ((result.find('.') != std::string::npos && result.back() == '0') || result.back() == '.') {
result.pop_back();
}
return result;
}
std::string fillSpaceLeft(const std::string& value, int requiredLength) {
std::string result = "";
int requiredSpace = requiredLength - value.size();
for (int i = 0; i < requiredSpace; i++) {
result.push_back(' ');
}
return result + value;
}