2012-03-24 23:39:19 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2013-04-18 11:52:18 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
2012-03-24 23:39:19 +01:00
|
|
|
|
2012-06-03 19:01:08 +02:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2012-04-27 00:48:30 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning (disable:4996)
|
2014-11-25 00:30:13 -08:00
|
|
|
#define strncasecmp _strnicmp
|
2020-08-10 01:43:40 -07:00
|
|
|
#define strcasecmp _stricmp
|
2019-09-28 09:22:38 -07:00
|
|
|
#else
|
|
|
|
#include <strings.h>
|
2012-04-27 00:48:30 +02:00
|
|
|
#endif
|
|
|
|
|
2012-03-31 11:16:13 +02:00
|
|
|
// Dumb wrapper around itoa, providing a buffer. Declare this on the stack.
|
2012-03-24 23:39:19 +01:00
|
|
|
class ITOA {
|
|
|
|
public:
|
2012-05-08 22:04:24 +02:00
|
|
|
char buffer[16];
|
|
|
|
const char *p(int i) {
|
|
|
|
sprintf(buffer, "%i", i);
|
|
|
|
return &buffer[0];
|
|
|
|
}
|
2012-03-24 23:39:19 +01:00
|
|
|
};
|
2012-03-31 11:16:13 +02:00
|
|
|
|
2017-02-10 00:01:56 +01:00
|
|
|
// Useful for shaders with error messages..
|
|
|
|
std::string LineNumberString(const std::string &str);
|
|
|
|
|
2012-03-31 11:16:13 +02:00
|
|
|
// Other simple string utilities.
|
|
|
|
|
2013-03-30 12:56:39 +01:00
|
|
|
inline bool startsWith(const std::string &str, const std::string &what) {
|
2013-06-04 22:05:17 +02:00
|
|
|
if (str.size() < what.size())
|
|
|
|
return false;
|
2013-03-30 12:56:39 +01:00
|
|
|
return str.substr(0, what.size()) == what;
|
|
|
|
}
|
|
|
|
|
2012-03-24 23:39:19 +01:00
|
|
|
inline bool endsWith(const std::string &str, const std::string &what) {
|
2013-06-04 22:05:17 +02:00
|
|
|
if (str.size() < what.size())
|
|
|
|
return false;
|
2012-05-08 22:04:24 +02:00
|
|
|
return str.substr(str.size() - what.size()) == what;
|
2012-03-31 11:16:13 +02:00
|
|
|
}
|
2012-03-27 22:54:58 +02:00
|
|
|
|
2014-11-25 00:30:13 -08:00
|
|
|
// Only use on strings where you're only concerned about ASCII.
|
|
|
|
inline bool startsWithNoCase(const std::string &str, const std::string &what) {
|
|
|
|
if (str.size() < what.size())
|
|
|
|
return false;
|
|
|
|
return strncasecmp(str.c_str(), what.c_str(), what.size()) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool endsWithNoCase(const std::string &str, const std::string &what) {
|
|
|
|
if (str.size() < what.size())
|
|
|
|
return false;
|
|
|
|
const size_t offset = str.size() - what.size();
|
|
|
|
return strncasecmp(str.c_str() + offset, what.c_str(), what.size()) == 0;
|
|
|
|
}
|
|
|
|
|
2015-09-06 19:08:32 +02:00
|
|
|
void DataToHexString(const uint8_t *data, size_t size, std::string *output);
|
2012-06-03 19:01:08 +02:00
|
|
|
inline void StringToHexString(const std::string &data, std::string *output) {
|
|
|
|
DataToHexString((uint8_t *)(&data[0]), data.size(), output);
|
|
|
|
}
|
|
|
|
|
2013-04-18 11:52:18 +02:00
|
|
|
std::string StringFromFormat(const char* format, ...);
|
|
|
|
std::string StringFromInt(int value);
|
|
|
|
std::string StringFromBool(bool value);
|
|
|
|
|
|
|
|
std::string ArrayToString(const uint8_t *data, uint32_t size, int line_len = 20, bool spaces = true);
|
|
|
|
|
|
|
|
std::string StripSpaces(const std::string &s);
|
|
|
|
std::string StripQuotes(const std::string &s);
|
|
|
|
|
|
|
|
void SplitString(const std::string& str, const char delim, std::vector<std::string>& output);
|
|
|
|
|
2017-03-05 23:26:53 -05:00
|
|
|
void GetQuotedStrings(const std::string& str, std::vector<std::string>& output);
|
2017-03-11 00:23:49 -05:00
|
|
|
|
2013-06-09 13:39:16 +02:00
|
|
|
std::string ReplaceAll(std::string input, const std::string& src, const std::string& dest);
|
2013-04-18 11:52:18 +02:00
|
|
|
|
2013-11-19 00:33:18 +08:00
|
|
|
// Compare two strings, ignore the difference between the ignorestr1 and the ignorestr2 in str1 and str2.
|
2013-11-18 23:45:44 +08:00
|
|
|
int strcmpIgnore(std::string str1, std::string str2, std::string ignorestr1, std::string ignorestr2);
|
|
|
|
|
2014-12-15 00:00:16 +01:00
|
|
|
void StringTrimEndNonAlphaNum(char *str);
|
|
|
|
void SkipSpace(const char **ptr);
|
|
|
|
void StringUpper(char *str);
|
|
|
|
void StringUpper(char *str, int len);
|