Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
prism/engine/utility/include/string_utils.hpp

31 lines
1,023 B
C++
Raw Normal View History

2020-08-11 12:07:21 -04:00
#pragma once
#include <string>
#include <string_view>
#include <vector>
std::string remove_substring(const std::string_view string, const std::string_view substring);
std::string replace_substring(const std::string_view string, const std::string_view substring, const std::string_view replacement);
bool string_contains(const std::string_view a, const std::string_view b);
bool string_starts_with(const std::string_view haystack, const std::string_view needle);
std::vector<std::string> tokenize(const std::string_view string, const std::string_view& delimiters = ",");
namespace utility {
template<class Arg>
inline void format_internal_format(std::string& msg, const Arg& arg) {
auto pos = msg.find_first_of("{}");
msg.replace(pos, 2, arg);
}
template<class... Args>
std::string format(const std::string_view format, Args&&... args) {
auto msg = std::string(format);
((format_internal_format<Args>(msg, args)), ...);
return msg;
}
}