lots of stuff

This commit is contained in:
Mars 2024-05-31 22:59:00 -04:00
parent e8fb8ec19f
commit 791e237470
Signed by: pupbrained
GPG key ID: 874E22DF2F9DFCB5
224 changed files with 19811 additions and 129 deletions

View file

@ -0,0 +1,28 @@
#ifndef RFL_INTERNAL_STRINGS_JOIN_HPP_
#define RFL_INTERNAL_STRINGS_JOIN_HPP_
#include <string>
#include <vector>
namespace rfl {
namespace internal {
namespace strings {
/// Joins a string using the delimiter
inline std::string join(const std::string& _delimiter,
const std::vector<std::string>& _strings) {
if (_strings.size() == 0) {
return "";
}
auto res = _strings[0];
for (size_t i = 1; i < _strings.size(); ++i) {
res += _delimiter + _strings[i];
}
return res;
}
} // namespace strings
} // namespace internal
} // namespace rfl
#endif

View file

@ -0,0 +1,28 @@
#ifndef RFL_INTERNAL_STRINGS_REPLACE_ALL_HPP_
#define RFL_INTERNAL_STRINGS_REPLACE_ALL_HPP_
#include <string>
#include <vector>
namespace rfl {
namespace internal {
namespace strings {
inline std::string replace_all(const std::string& _str,
const std::string& _from,
const std::string& _to) {
auto str = _str;
size_t pos = 0;
while ((pos = str.find(_from, pos)) != std::string::npos) {
str.replace(pos, _from.length(), _to);
pos += _to.length();
}
return str;
}
} // namespace strings
} // namespace internal
} // namespace rfl
#endif

View file

@ -0,0 +1,29 @@
#ifndef RFL_INTERNAL_STRINGS_SPLIT_HPP_
#define RFL_INTERNAL_STRINGS_SPLIT_HPP_
#include <string>
#include <vector>
namespace rfl {
namespace internal {
namespace strings {
/// Splits a string alongside the delimiter
inline std::vector<std::string> split(const std::string& _str,
const std::string& _delimiter) {
auto str = _str;
size_t pos = 0;
std::vector<std::string> result;
while ((pos = str.find(_delimiter)) != std::string::npos) {
result.emplace_back(str.substr(0, pos));
str.erase(0, pos + _delimiter.length());
}
result.emplace_back(std::move(str));
return result;
}
} // namespace strings
} // namespace internal
} // namespace rfl
#endif