This commit is contained in:
Mars 2024-06-08 14:10:59 -04:00
parent a743cdabe5
commit bd402f57f5
Signed by: pupbrained
GPG key ID: 874E22DF2F9DFCB5
276 changed files with 37936 additions and 22932 deletions

View file

@ -5,24 +5,22 @@
#include <vector>
namespace rfl {
namespace internal {
namespace strings {
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;
}
/// 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
} // namespace strings
} // namespace internal
} // namespace rfl
#endif

View file

@ -5,24 +5,24 @@
#include <vector>
namespace rfl {
namespace internal {
namespace strings {
namespace internal {
namespace strings {
inline std::string replace_all(const std::string& _str,
const std::string& _from,
const std::string& _to) {
auto str = _str;
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;
}
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
} // namespace strings
} // namespace internal
} // namespace rfl
#endif

View file

@ -5,25 +5,25 @@
#include <vector>
namespace rfl {
namespace internal {
namespace strings {
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;
}
/// 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
} // namespace strings
} // namespace internal
} // namespace rfl
#endif