iw4x-client/src/Utils/Utils.hpp

59 lines
1.5 KiB
C++
Raw Normal View History

2015-12-23 08:45:53 -05:00
namespace Utils
{
const char *VA(const char *fmt, ...);
std::string StrToLower(std::string input);
2016-01-10 09:48:49 -05:00
bool EndsWith(const char* haystack, const char* needle);
2015-12-25 15:42:35 -05:00
std::vector<std::string> Explode(const std::string& str, char delim);
2015-12-24 11:30:36 -05:00
void Replace(std::string &string, std::string find, std::string replace);
2016-01-10 09:48:49 -05:00
bool StartsWith(std::string haystack, std::string needle);
2016-01-08 21:21:59 -05:00
unsigned int OneAtATime(const char *key, size_t len);
2016-01-01 14:01:19 -05:00
std::string &LTrim(std::string &s);
std::string &RTrim(std::string &s);
std::string &Trim(std::string &s);
2015-12-24 11:30:36 -05:00
2016-01-10 09:48:49 -05:00
std::string FormatTimeSpan(int milliseconds);
2016-01-04 05:32:05 -05:00
std::string ParseChallenge(std::string data);
2016-01-05 19:23:43 -05:00
bool FileExists(std::string file);
void WriteFile(std::string file, std::string data);
std::string ReadFile(std::string file);
2015-12-24 11:30:36 -05:00
class InfoString
{
public:
InfoString() {};
InfoString(std::string buffer) :InfoString() { this->Parse(buffer); };
2015-12-27 22:02:30 -05:00
InfoString(const InfoString &obj) { this->KeyValuePairs = obj.KeyValuePairs; };
2015-12-24 11:30:36 -05:00
void Set(std::string key, std::string value);
std::string Get(std::string key);
std::string Build();
2015-12-25 15:42:35 -05:00
void Dump();
2015-12-24 11:30:36 -05:00
private:
std::map<std::string, std::string> KeyValuePairs;
void Parse(std::string buffer);
};
2015-12-30 09:37:53 -05:00
2016-01-01 22:51:08 -05:00
template <typename T> void Merge(std::vector<T> &target, T* source, size_t length)
{
if (source)
{
for (size_t i = 0; i < length; i++)
{
target.push_back(source[i]);
}
}
}
2015-12-30 09:37:53 -05:00
template <typename T> void Merge(std::vector<T> &target, std::vector<T> &source)
{
for (auto &entry : source)
{
target.push_back(entry);
}
}
2015-12-23 08:45:53 -05:00
}