2016-01-22 05:59:43 -05:00
|
|
|
#define ARR_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
|
|
|
|
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 <rim(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-24 06:19:34 -05:00
|
|
|
template <typename T> void Merge(std::vector<T>* target, T* source, size_t length)
|
2016-01-01 22:51:08 -05:00
|
|
|
{
|
|
|
|
if (source)
|
|
|
|
{
|
2016-01-24 13:58:13 -05:00
|
|
|
for (size_t i = 0; i < length; ++i)
|
2016-01-01 22:51:08 -05:00
|
|
|
{
|
2016-01-24 06:19:34 -05:00
|
|
|
target->push_back(source[i]);
|
2016-01-01 22:51:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-24 06:19:34 -05:00
|
|
|
template <typename T> void Merge(std::vector<T>* target, std::vector<T> source)
|
2015-12-30 09:37:53 -05:00
|
|
|
{
|
|
|
|
for (auto &entry : source)
|
|
|
|
{
|
2016-01-24 06:19:34 -05:00
|
|
|
target->push_back(entry);
|
2015-12-30 09:37:53 -05:00
|
|
|
}
|
|
|
|
}
|
2015-12-23 08:45:53 -05:00
|
|
|
}
|