lots of stuff
This commit is contained in:
parent
e8fb8ec19f
commit
791e237470
224 changed files with 19811 additions and 129 deletions
28
include/rfl/internal/strings/join.hpp
Normal file
28
include/rfl/internal/strings/join.hpp
Normal 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
|
28
include/rfl/internal/strings/replace_all.hpp
Normal file
28
include/rfl/internal/strings/replace_all.hpp
Normal 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
|
29
include/rfl/internal/strings/split.hpp
Normal file
29
include/rfl/internal/strings/split.hpp
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue