parent
df538935a5
commit
2508d4cd51
2 changed files with 56 additions and 34 deletions
@ -0,0 +1,47 @@ |
||||
#include "util.h" |
||||
|
||||
vector<size_t> findAll(const string& data, const string& toSearch){ |
||||
vector<size_t> indices; |
||||
|
||||
size_t pos = data.find(toSearch); |
||||
|
||||
while (pos != string::npos){ |
||||
indices.push_back(pos); |
||||
|
||||
pos = data.find(toSearch, pos + toSearch.size()); |
||||
} |
||||
|
||||
return indices; |
||||
} |
||||
|
||||
void removeAll(string& data, const string& toRemove) { |
||||
vector<size_t> indices = findAll(data, toRemove); |
||||
std::sort(indices.rbegin(), indices.rend()); |
||||
for (size_t &i : indices) |
||||
data.erase(i, toRemove.size()); |
||||
} |
||||
|
||||
vector<string> split(const string& data, const char c){ |
||||
vector<string> parts; |
||||
size_t start = 0; |
||||
for (size_t i : findAll(data, std::string(1, c))){ |
||||
parts.push_back(data.substr(start, i - start)); |
||||
start = i + 1; |
||||
} |
||||
parts.push_back(data.substr(start)); |
||||
return parts; |
||||
} |
||||
|
||||
bool isDigit(char c, uint8_t& result){ |
||||
auto val = c - '0'; |
||||
if (val >= 0 && val < 10){ |
||||
result = val; |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
bool isDigit(char c){ |
||||
auto val = c - '0'; |
||||
return val >= 0 && val < 10; |
||||
} |
Loading…
Reference in new issue