19template<
typename T,
class S>
struct Finder
40 Tokenizer(
const std::string& src,
char const sep,
uint32 vectorReserve = 0);
68float frand(
float min,
float max);
91 return chance > std::rand() % 99;
98 var *= (apply ? (100.0f + val) / 100.0f : 100.0f / (100.0f + val));
102template <
class T,
class U>
105 return T(base *
static_cast<float>(pct) / 100.0f);
108template <
class T,
class U>
114template <
class T,
class U>
123 return num = std::min(std::max(num, floor), ceil);
127bool Utf8toWStr(
const std::string& utf8str, std::wstring& wstr);
129bool Utf8toWStr(
char const* utf8str,
size_t csize,
wchar_t* wstr,
size_t& wsize);
130inline bool Utf8toWStr(
const std::string& utf8str,
wchar_t* wstr,
size_t& wsize)
132 return Utf8toWStr(utf8str.c_str(), utf8str.size(), wstr, wsize);
135bool WStrToUtf8(
const std::wstring& wstr, std::string& utf8str);
137bool WStrToUtf8(
wchar_t* wstr,
size_t size, std::string& utf8str);
144 if (wchar >= L
'a' && wchar <= L
'z')
146 if (wchar >= L
'A' && wchar <= L
'Z')
155 if (wchar >= 0x00C0 && wchar <= 0x00D6)
157 if (wchar >= 0x00D8 && wchar <= 0x00DE)
161 if (wchar >= 0x00E0 && wchar <= 0x00F6)
163 if (wchar >= 0x00F8 && wchar <= 0x00FE)
165 if (wchar >= 0x0100 && wchar <= 0x012F)
174 if (wchar >= 0x0410 && wchar <= 0x044F)
176 if (wchar == 0x0401 || wchar == 0x0451)
183 if (wchar >= 0x1100 && wchar <= 0x11F9)
185 if (wchar >= 0x3041 && wchar <= 0x30FF)
187 if (wchar >= 0x3131 && wchar <= 0x318E)
189 if (wchar >= 0x31F0 && wchar <= 0x31FF)
191 if (wchar >= 0x3400 && wchar <= 0x4DB5)
193 if (wchar >= 0x4E00 && wchar <= 0x9FC3)
195 if (wchar >= 0xAC00 && wchar <= 0xD7A3)
197 if (wchar >= 0xFF01 && wchar <= 0xFFEE)
204 return (wchar >= L
'0' && wchar <= L
'9');
209 return (c >=
'0' && c <=
'9');
214 for (
char const* c = str; *c; ++c)
223 return isNumeric(wchar) || wchar == L
' ';
228 for (
size_t i = 0; i < wstr.size(); ++i)
236 for (
size_t i = 0; i < wstr.size(); ++i)
244 for (
size_t i = 0; i < wstr.size(); ++i)
252 for (
size_t i = 0; i < wstr.size(); ++i)
260 if (wchar >= L
'a' && wchar <= L
'z')
261 return wchar_t(
uint16(wchar) - 0x0020);
263 return wchar_t(0x1E9E);
264 if (wchar >= 0x00E0 && wchar <= 0x00F6)
265 return wchar_t(
uint16(wchar) - 0x0020);
266 if (wchar >= 0x00F8 && wchar <= 0x00FE)
267 return wchar_t(
uint16(wchar) - 0x0020);
268 if (wchar >= 0x0101 && wchar <= 0x012F)
271 return wchar_t(
uint16(wchar) - 0x0001);
273 if (wchar >= 0x0430 && wchar <= 0x044F)
274 return wchar_t(
uint16(wchar) - 0x0020);
276 return wchar_t(0x0401);
288 if (wchar >= L
'A' && wchar <= L
'Z')
289 return wchar_t(
uint16(wchar) + 0x0020);
290 if (wchar >= 0x00C0 && wchar <= 0x00D6)
291 return wchar_t(
uint16(wchar) + 0x0020);
292 if (wchar >= 0x00D8 && wchar <= 0x00DE)
293 return wchar_t(
uint16(wchar) + 0x0020);
294 if (wchar >= 0x0100 && wchar <= 0x012E)
297 return wchar_t(
uint16(wchar) + 0x0001);
300 return wchar_t(0x00DF);
302 return wchar_t(0x0451);
303 if (wchar >= 0x0410 && wchar <= 0x042F)
304 return wchar_t(
uint16(wchar) + 0x0020);
311 std::transform(str.begin(), str.end(), str.begin(),
wcharToUpper);
316 std::transform(str.begin(), str.end(), str.begin(),
wcharToLower);
321bool utf8ToConsole(
const std::string& utf8str, std::string& conStr);
322bool consoleToUtf8(
const std::string& conStr, std::string& utf8str);
323bool Utf8FitTo(
const std::string& str,
const std::wstring& search);
324void utf8printf(FILE* out,
const char* str, ...);
325void vutf8printf(FILE* out,
const char* str, va_list* ap);
343template<
typename Container>
350void HexStrToByteArray(std::string
const& str, std::array<uint8, Size>& buf,
bool reverse =
false)
357 std::array<uint8, Size> arr;
441 for (
uint8 i = 4; i > 0; --i)
443 if (
part[i - 1] < right.
part[i - 1])
445 else if (
part[i - 1] > right.
part[i - 1])
526 inline operator bool()
const
533 return !this->
operator bool();
569 return (
part[0] == p1 &&
part[1] == p2 &&
part[2] == p3);
586 for (
uint8 i = 3; i > 0; --i)
588 if (
part[i - 1] < right.
part[i - 1])
590 else if (
part[i - 1] > right.
part[i - 1])
666 inline operator bool()
const
673 return !this->
operator bool();
bool isBasicLatinString(const std::wstring &wstr, bool numericOrSpace)
void HexStrToByteArray(std::string const &str, std::array< uint8, Size > &buf, bool reverse=false)
float frand(float min, float max)
wchar_t wcharToLower(wchar_t wchar)
wchar_t wcharToUpperOnlyLatin(wchar_t wchar)
bool isExtendedLatinCharacter(wchar_t wchar)
bool isCyrillicString(const std::wstring &wstr, bool numericOrSpace)
bool isExtendedLatinString(const std::wstring &wstr, bool numericOrSpace)
bool isEastAsianString(const std::wstring &wstr, bool numericOrSpace)
int64 MoneyStringToMoney(const std::string &moneyString)
bool IsIPAddrInNetwork(Skyfire::Net::Address const &net, Skyfire::Net::Address const &addr, Skyfire::Net::Address const &subnetMask)
Checks if address belongs to the a network with specified submask.
bool roll_chance_f(float chance)
bool roll_chance_i(int chance)
bool consoleToUtf8(const std::string &conStr, std::string &utf8str)
std::string ByteArrayToHexStr(Container const &c, bool reverse=false)
void wstrToLower(std::wstring &str)
void stripLineInvisibleChars(std::string &src)
bool IsIPAddress(char const *ipaddress)
Check if the string is a valid ip address representation.
uint32 TimeStringToSecs(const std::string ×tring)
std::string TimeToTimestampStr(time_t t)
bool CompareValues(ComparisionType type, T val1, T val2)
bool isNumeric(wchar_t wchar)
std::string secsToTimeString(uint64 timeInSecs, bool shortText=false, bool hoursOnly=false)
wchar_t wcharToUpper(wchar_t wchar)
void utf8printf(FILE *out, const char *str,...)
T RoundToInterval(T &num, T floor, T ceil)
bool utf8ToConsole(const std::string &utf8str, std::string &conStr)
bool Utf8FitTo(const std::string &str, const std::wstring &search)
uint32 CreatePIDFile(const std::string &filename)
create PID file
bool Utf8toWStr(const std::string &utf8str, std::wstring &wstr)
bool isEastAsianCharacter(wchar_t wchar)
T ApplyPct(T &base, U pct)
void ApplyPercentModFloatVar(float &var, float val, bool apply)
T CalculatePct(T base, U pct)
size_t utf8length(std::string &utf8str)
bool isCyrillicCharacter(wchar_t wchar)
void utf8truncate(std::string &utf8str, size_t len)
bool WStrToUtf8(const std::wstring &wstr, std::string &utf8str)
void wstrToUpper(std::wstring &str)
std::string GetAddressString(Skyfire::Net::Address const &addr)
Transforms network address into string format "dotted_ip:port".
bool isNumericOrSpace(wchar_t wchar)
std::wstring GetMainPartOfName(std::wstring wname, uint32 declension)
void vutf8printf(FILE *out, const char *str, va_list *ap)
bool isBasicLatinCharacter(wchar_t wchar)
std::list< T >::iterator ListIterator
HookList< T > & operator+=(T t)
HookList< T > & operator-=(T t)
StorageType::reference reference
StorageType::size_type size_type
std::vector< char const * > StorageType
StorageType::const_iterator const_iterator
Tokenizer(const std::string &src, char const sep, uint32 vectorReserve=0)
StorageType::const_reference const_reference
reference operator[](size_type i)
const_iterator end() const
const_iterator begin() const
bool operator!=(const flag128 &right) const
uint32 & operator[](uint8 el)
flag128 & operator^=(const flag128 &right)
bool HasFlag(uint32 p1=0, uint32 p2=0, uint32 p3=0, uint32 p4=0) const
flag128(uint32 p1=0, uint32 p2=0, uint32 p3=0, uint32 p4=0)
flag128(uint64 p1, uint64 p2)
flag128 operator~() const
flag128 operator|(const flag128 &right) const
bool operator<(const flag128 &right) const
flag128 operator^(const flag128 &right) const
flag128 & operator&=(const flag128 &right)
flag128 & operator|=(const flag128 &right)
flag128 & operator=(const flag128 &right)
bool operator==(const flag128 &right) const
bool IsEqual(uint32 p1=0, uint32 p2=0, uint32 p3=0, uint32 p4=0) const
flag128 operator&(const flag128 &right) const
void Set(uint32 p1=0, uint32 p2=0, uint32 p3=0, uint32 p4=0)
bool operator<(const flag96 &right) const
bool HasFlag(uint32 p1=0, uint32 p2=0, uint32 p3=0) const
flag96 & operator&=(const flag96 &right)
bool IsEqual(uint32 p1=0, uint32 p2=0, uint32 p3=0) const
flag96(uint32 p1=0, uint32 p2=0, uint32 p3=0)
flag96 operator&(const flag96 &right) const
flag96 operator^(const flag96 &right) const
bool operator!=(const flag96 &right) const
bool operator==(const flag96 &right) const
flag96 & operator^=(const flag96 &right)
flag96(uint64 p1, uint32 p2)
flag96 operator|(const flag96 &right) const
void Set(uint32 p1=0, uint32 p2=0, uint32 p3=0)
uint32 & operator[](uint8 el)
flag96 & operator=(const flag96 &right)
flag96 & operator|=(const flag96 &right)
std::string ByteArrayToHexStr(uint8 const *bytes, size_t length, bool reverse=false)
void HexStrToByteArray(std::string const &str, uint8 *out, size_t outlen, bool reverse=false)
bool operator()(const std::pair< int, S > &obj)
Finder(T val, T S::*idMember)