working commit

This commit is contained in:
2026-05-15 15:30:29 +02:00
parent 879481feab
commit 886684e224
28 changed files with 629 additions and 81 deletions
+39
View File
@@ -0,0 +1,39 @@
#include <expected>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <cstring>
std::vector<std::string> split(std::string s, std::string delimiters) {
std::vector<std::string> tokens;
size_t last = 0, next = 0;
while ((next = s.find_first_of(delimiters, last)) != std::string::npos) {
if (next != last) tokens.push_back(s.substr(last, next - last));
last = next + 1;
}
if (last < s.length()) tokens.push_back(s.substr(last));
return tokens;
}
std::string trim(std::string& source) {
auto line = source;
std::string whitespaces(" \t\n\r\f\v");
line.erase(0, line.find_first_not_of(whitespaces));
line.erase(line.find_last_not_of(whitespaces) + 1);
return line;
}
std::expected<int, std::string> strtoint (std::string source) {
std::size_t pos{};
int res;
try {
res = std::stoi(source, &pos);
} catch (std::invalid_argument const& ex) {
return std::unexpected(std::format("invalid argument:{}", ex.what()));
} catch (std::out_of_range const& ex) {
return std::unexpected(std::format("out of range", ex.what()));
}
return res;
}