2023-04-28 14:50:58 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-05-16 09:18:06 +03:00
|
|
|
#include <utility>
|
2023-04-28 14:50:58 +03:00
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
2023-05-16 09:18:06 +03:00
|
|
|
#include <algorithm>
|
2023-04-28 14:50:58 +03:00
|
|
|
|
2023-04-28 16:08:05 +03:00
|
|
|
inline std::vector<std::string> split_string(const std::string& in, const std::string& delimiter) {
|
2023-04-28 14:50:58 +03:00
|
|
|
std::vector<std::string> result{};
|
|
|
|
|
size_t last{0}, next;
|
|
|
|
|
while ((next = in.find(delimiter, last)) != std::string::npos) {
|
|
|
|
|
result.push_back(in.substr(last, next - last));
|
|
|
|
|
last = next + delimiter.size();
|
|
|
|
|
}
|
|
|
|
|
result.push_back(in.substr(last));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 16:08:05 +03:00
|
|
|
inline std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ") {
|
2023-04-28 14:50:58 +03:00
|
|
|
str.erase(0, str.find_first_not_of(chars));
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 16:08:05 +03:00
|
|
|
inline std::string ltrim(std::string&& str, const std::string& chars = "\t\n\v\f\r ") {
|
2023-04-28 14:50:58 +03:00
|
|
|
str.erase(0, str.find_first_not_of(chars));
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 16:08:05 +03:00
|
|
|
inline std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ") {
|
2023-04-28 14:50:58 +03:00
|
|
|
str.erase(str.find_last_not_of(chars) + 1);
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 16:08:05 +03:00
|
|
|
inline std::string rtrim(std::string&& str, const std::string& chars = "\t\n\v\f\r ") {
|
2023-04-28 14:50:58 +03:00
|
|
|
str.erase(str.find_last_not_of(chars) + 1);
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 16:08:05 +03:00
|
|
|
inline std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ") {
|
2023-04-28 14:50:58 +03:00
|
|
|
return ltrim(rtrim(str, chars), chars);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 16:08:05 +03:00
|
|
|
inline std::string trim(std::string&& str, const std::string& chars = "\t\n\v\f\r ") {
|
2023-04-28 14:50:58 +03:00
|
|
|
return ltrim(rtrim(str, chars), chars);
|
2023-05-16 09:18:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline std::string& to_upper(std::string& str) {
|
|
|
|
|
std::transform(str.begin(), str.end(), str.begin(),
|
|
|
|
|
[](unsigned char c) { return std::toupper(c); });
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline std::string& to_lower(std::string& str) {
|
|
|
|
|
std::transform(str.begin(), str.end(), str.begin(),
|
|
|
|
|
[](unsigned char c) { return std::tolower(c); });
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline std::string to_upper(std::string&& str) {
|
|
|
|
|
auto result = str;
|
|
|
|
|
return to_upper(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline std::string to_lower(std::string&& str) {
|
|
|
|
|
auto result = str;
|
|
|
|
|
return to_lower(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool string_contains(const std::string& str, const std::string& needle) {
|
|
|
|
|
return str.find(needle) != std::string::npos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline std::string remove_spaces(std::string str) {
|
|
|
|
|
str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool starts_with(const std::string& line, const std::string& prefix) {
|
|
|
|
|
return line.rfind(prefix, 0) == 0;
|
|
|
|
|
}
|