Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
Util.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef _UTIL_H
7#define _UTIL_H
8
9#include "Define.h"
10#include "Errors.h"
11#include "NetworkAddress.h"
12
13#include <algorithm>
14#include <list>
15#include <string>
16#include <vector>
17
18// Searcher for map of structs
19template<typename T, class S> struct Finder
20{
22 T S::* idMember_;
23
24 Finder(T val, T S::* idMember) : val_(val), idMember_(idMember) {}
25 bool operator()(const std::pair<int, S>& obj) { return obj.second.*idMember_ == val_; }
26};
27
29{
30public:
31 typedef std::vector<char const*> StorageType;
32
33 typedef StorageType::size_type size_type;
34
35 typedef StorageType::const_iterator const_iterator;
36 typedef StorageType::reference reference;
37 typedef StorageType::const_reference const_reference;
38
39public:
40 Tokenizer(const std::string& src, char const sep, uint32 vectorReserve = 0);
41 ~Tokenizer() { delete[] m_str; }
42
43 const_iterator begin() const { return m_storage.begin(); }
44 const_iterator end() const { return m_storage.end(); }
45
46 size_type size() const { return m_storage.size(); }
47
50
51private:
52 char* m_str;
54};
55
56void stripLineInvisibleChars(std::string& src);
57
58int64 MoneyStringToMoney(const std::string& moneyString);
59
60std::string secsToTimeString(uint64 timeInSecs, bool shortText = false, bool hoursOnly = false);
61uint32 TimeStringToSecs(const std::string& timestring);
62std::string TimeToTimestampStr(time_t t);
63
64/* Return a random number in the range 0 .. RAND32_MAX. */
66
67/* Return a random number in the range min..max */
68float frand(float min, float max);
69
70/* Return a random double from 0.0 to 1.0 (exclusive). Floats support only 7 valid decimal digits.
71 * A double supports up to 15 valid decimal digits and is used internally (RAND32_MAX has 10 digits).
72 * With an FPU, there is usually no difference in performance between float and double.
73*/
74double rand_norm(void);
75
76/* Return a random double from 0.0 to 99.9999999999999. Floats support only 7 valid decimal digits.
77 * A double supports up to 15 valid decimal digits and is used internally (RAND32_MAX has 10 digits).
78 * With an FPU, there is usually no difference in performance between float and double.
79*/
80double rand_chance(void);
81
82/* Return true if a random roll fits in the specified chance (range 0-100). */
83inline bool roll_chance_f(float chance)
84{
85 return chance > rand_chance();
86}
87
88/* Return true if a random roll fits in the specified chance (range 0-100). */
89inline bool roll_chance_i(int chance)
90{
91 return chance > std::rand() % 99;
92}
93
94inline void ApplyPercentModFloatVar(float& var, float val, bool apply)
95{
96 if (val == -100.0f) // prevent set var to zero
97 val = -99.99f;
98 var *= (apply ? (100.0f + val) / 100.0f : 100.0f / (100.0f + val));
99}
100
101// Percentage calculation
102template <class T, class U>
103inline T CalculatePct(T base, U pct)
104{
105 return T(base * static_cast<float>(pct) / 100.0f);
106}
107
108template <class T, class U>
109inline T AddPct(T& base, U pct)
110{
111 return base += CalculatePct(base, pct);
112}
113
114template <class T, class U>
115inline T ApplyPct(T& base, U pct)
116{
117 return base = CalculatePct(base, pct);
118}
119
120template <class T>
121inline T RoundToInterval(T& num, T floor, T ceil)
122{
123 return num = std::min(std::max(num, floor), ceil);
124}
125
126// UTF8 handling
127bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr);
128// in wsize==max size of buffer, out wsize==real string size
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)
131{
132 return Utf8toWStr(utf8str.c_str(), utf8str.size(), wstr, wsize);
133}
134
135bool WStrToUtf8(const std::wstring& wstr, std::string& utf8str);
136// size==real string size
137bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str);
138
139size_t utf8length(std::string& utf8str); // set string to "" if invalid utf8 sequence
140void utf8truncate(std::string& utf8str, size_t len);
141
142inline bool isBasicLatinCharacter(wchar_t wchar)
143{
144 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
145 return true;
146 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
147 return true;
148 return false;
149}
150
151inline bool isExtendedLatinCharacter(wchar_t wchar)
152{
153 if (isBasicLatinCharacter(wchar))
154 return true;
155 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
156 return true;
157 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
158 return true;
159 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
160 return true;
161 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
162 return true;
163 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
164 return true;
165 if (wchar >= 0x0100 && wchar <= 0x012F) // LATIN CAPITAL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK
166 return true;
167 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
168 return true;
169 return false;
170}
171
172inline bool isCyrillicCharacter(wchar_t wchar)
173{
174 if (wchar >= 0x0410 && wchar <= 0x044F) // CYRILLIC CAPITAL LETTER A - CYRILLIC SMALL LETTER YA
175 return true;
176 if (wchar == 0x0401 || wchar == 0x0451) // CYRILLIC CAPITAL LETTER IO, CYRILLIC SMALL LETTER IO
177 return true;
178 return false;
179}
180
181inline bool isEastAsianCharacter(wchar_t wchar)
182{
183 if (wchar >= 0x1100 && wchar <= 0x11F9) // Hangul Jamo
184 return true;
185 if (wchar >= 0x3041 && wchar <= 0x30FF) // Hiragana + Katakana
186 return true;
187 if (wchar >= 0x3131 && wchar <= 0x318E) // Hangul Compatibility Jamo
188 return true;
189 if (wchar >= 0x31F0 && wchar <= 0x31FF) // Katakana Phonetic Ext.
190 return true;
191 if (wchar >= 0x3400 && wchar <= 0x4DB5) // CJK Ideographs Ext. A
192 return true;
193 if (wchar >= 0x4E00 && wchar <= 0x9FC3) // Unified CJK Ideographs
194 return true;
195 if (wchar >= 0xAC00 && wchar <= 0xD7A3) // Hangul Syllables
196 return true;
197 if (wchar >= 0xFF01 && wchar <= 0xFFEE) // Halfwidth forms
198 return true;
199 return false;
200}
201
202inline bool isNumeric(wchar_t wchar)
203{
204 return (wchar >= L'0' && wchar <= L'9');
205}
206
207inline bool isNumeric(char c)
208{
209 return (c >= '0' && c <= '9');
210}
211
212inline bool isNumeric(char const* str)
213{
214 for (char const* c = str; *c; ++c)
215 if (!isNumeric(*c))
216 return false;
217
218 return true;
219}
220
221inline bool isNumericOrSpace(wchar_t wchar)
222{
223 return isNumeric(wchar) || wchar == L' ';
224}
225
226inline bool isBasicLatinString(const std::wstring& wstr, bool numericOrSpace)
227{
228 for (size_t i = 0; i < wstr.size(); ++i)
229 if (!isBasicLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
230 return false;
231 return true;
232}
233
234inline bool isExtendedLatinString(const std::wstring& wstr, bool numericOrSpace)
235{
236 for (size_t i = 0; i < wstr.size(); ++i)
237 if (!isExtendedLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
238 return false;
239 return true;
240}
241
242inline bool isCyrillicString(const std::wstring& wstr, bool numericOrSpace)
243{
244 for (size_t i = 0; i < wstr.size(); ++i)
245 if (!isCyrillicCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
246 return false;
247 return true;
248}
249
250inline bool isEastAsianString(const std::wstring& wstr, bool numericOrSpace)
251{
252 for (size_t i = 0; i < wstr.size(); ++i)
253 if (!isEastAsianCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
254 return false;
255 return true;
256}
257
258inline wchar_t wcharToUpper(wchar_t wchar)
259{
260 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
261 return wchar_t(uint16(wchar) - 0x0020);
262 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
263 return wchar_t(0x1E9E);
264 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
265 return wchar_t(uint16(wchar) - 0x0020);
266 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
267 return wchar_t(uint16(wchar) - 0x0020);
268 if (wchar >= 0x0101 && wchar <= 0x012F) // LATIN SMALL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK (only %2=1)
269 {
270 if (wchar % 2 == 1)
271 return wchar_t(uint16(wchar) - 0x0001);
272 }
273 if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
274 return wchar_t(uint16(wchar) - 0x0020);
275 if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
276 return wchar_t(0x0401);
277
278 return wchar;
279}
280
281inline wchar_t wcharToUpperOnlyLatin(wchar_t wchar)
282{
283 return isBasicLatinCharacter(wchar) ? wcharToUpper(wchar) : wchar;
284}
285
286inline wchar_t wcharToLower(wchar_t wchar)
287{
288 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
289 return wchar_t(uint16(wchar) + 0x0020);
290 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
291 return wchar_t(uint16(wchar) + 0x0020);
292 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
293 return wchar_t(uint16(wchar) + 0x0020);
294 if (wchar >= 0x0100 && wchar <= 0x012E) // LATIN CAPITAL LETTER A WITH MACRON - LATIN CAPITAL LETTER I WITH OGONEK (only %2=0)
295 {
296 if (wchar % 2 == 0)
297 return wchar_t(uint16(wchar) + 0x0001);
298 }
299 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
300 return wchar_t(0x00DF);
301 if (wchar == 0x0401) // CYRILLIC CAPITAL LETTER IO
302 return wchar_t(0x0451);
303 if (wchar >= 0x0410 && wchar <= 0x042F) // CYRILLIC CAPITAL LETTER A - CYRILLIC CAPITAL LETTER YA
304 return wchar_t(uint16(wchar) + 0x0020);
305
306 return wchar;
307}
308
309inline void wstrToUpper(std::wstring& str)
310{
311 std::transform(str.begin(), str.end(), str.begin(), wcharToUpper);
312}
313
314inline void wstrToLower(std::wstring& str)
315{
316 std::transform(str.begin(), str.end(), str.begin(), wcharToLower);
317}
318
319std::wstring GetMainPartOfName(std::wstring wname, uint32 declension);
320
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);
326
327bool IsIPAddress(char const* ipaddress);
328
330bool IsIPAddrInNetwork(Skyfire::Net::Address const& net, Skyfire::Net::Address const& addr, Skyfire::Net::Address const& subnetMask);
331
333std::string GetAddressString(Skyfire::Net::Address const& addr);
334
335uint32 CreatePIDFile(const std::string& filename);
336
337namespace SkyFire::Impl
338{
339 std::string ByteArrayToHexStr(uint8 const* bytes, size_t length, bool reverse = false);
340 void HexStrToByteArray(std::string const& str, uint8* out, size_t outlen, bool reverse = false);
341}
342
343template<typename Container>
344std::string ByteArrayToHexStr(Container const& c, bool reverse = false)
345{
346 return SkyFire::Impl::ByteArrayToHexStr(std::data(c), std::size(c), reverse);
347}
348
349template<size_t Size>
350void HexStrToByteArray(std::string const& str, std::array<uint8, Size>& buf, bool reverse = false)
351{
352 SkyFire::Impl::HexStrToByteArray(str, buf.data(), Size, reverse);
353}
354template<size_t Size>
355std::array<uint8, Size> HexStrToByteArray(std::string const& str, bool reverse = false)
356{
357 std::array<uint8, Size> arr;
358 HexStrToByteArray(str, arr, reverse);
359 return arr;
360}
361#endif
362
363//handler for operations on large flags
364#ifndef _FLAG96
365#define _FLAG96
366
367// simple class for not-modifyable list
368template <typename T>
370{
371 typedef typename std::list<T>::iterator ListIterator;
372private:
373 typename std::list<T> m_list;
374public:
376 {
377 m_list.push_back(t);
378 return *this;
379 }
381 {
382 m_list.remove(t);
383 return *this;
384 }
385 size_t size()
386 {
387 return m_list.size();
388 }
390 {
391 return m_list.begin();
392 }
394 {
395 return m_list.end();
396 }
397};
398
400{
401private:
403
404public:
405 flag128(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0, uint32 p4 = 0)
406 {
407 part[0] = p1;
408 part[1] = p2;
409 part[2] = p3;
410 part[3] = p4;
411 }
412
414 {
415 part[0] = (uint32)(p1 & UI64LIT(0x00000000FFFFFFFF));
416 part[1] = (uint32)((p1 >> 32) & UI64LIT(0x00000000FFFFFFFF));
417 part[0] = (uint32)(p2 & UI64LIT(0x00000000FFFFFFFF));
418 part[1] = (uint32)((p2 >> 32) & UI64LIT(0x00000000FFFFFFFF));
419 }
420
421 inline bool IsEqual(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0, uint32 p4 = 0) const
422 {
423 return (part[0] == p1 && part[1] == p2 && part[2] == p3 && part[3] == p4);
424 }
425
426 inline bool HasFlag(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0, uint32 p4 = 0) const
427 {
428 return (part[0] & p1 || part[1] & p2 || part[2] & p3 || part[3] & p4);
429 }
430
431 inline void Set(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0, uint32 p4 = 0)
432 {
433 part[0] = p1;
434 part[1] = p2;
435 part[2] = p3;
436 part[3] = p4;
437 }
438
439 inline bool operator <(const flag128& right) const
440 {
441 for (uint8 i = 4; i > 0; --i)
442 {
443 if (part[i - 1] < right.part[i - 1])
444 return true;
445 else if (part[i - 1] > right.part[i - 1])
446 return false;
447 }
448 return false;
449 }
450
451 inline bool operator ==(const flag128& right) const
452 {
453 return
454 (
455 part[0] == right.part[0] &&
456 part[1] == right.part[1] &&
457 part[2] == right.part[2] &&
458 part[3] == right.part[3]
459 );
460 }
461
462 inline bool operator !=(const flag128& right) const
463 {
464 return !this->operator ==(right);
465 }
466
467 inline flag128& operator =(const flag128& right)
468 {
469 part[0] = right.part[0];
470 part[1] = right.part[1];
471 part[2] = right.part[2];
472 part[3] = right.part[3];
473 return *this;
474 }
475
476 inline flag128 operator &(const flag128& right) const
477 {
478 return flag128(part[0] & right.part[0], part[1] & right.part[1],
479 part[2] & right.part[2], part[3] & right.part[3]);
480 }
481
482 inline flag128& operator &=(const flag128& right)
483 {
484 part[0] &= right.part[0];
485 part[1] &= right.part[1];
486 part[2] &= right.part[2];
487 part[3] &= right.part[3];
488 return *this;
489 }
490
491 inline flag128 operator |(const flag128& right) const
492 {
493 return flag128(part[0] | right.part[0], part[1] | right.part[1],
494 part[2] | right.part[2], part[3] | right.part[3]);
495 }
496
497 inline flag128& operator |=(const flag128& right)
498 {
499 part[0] |= right.part[0];
500 part[1] |= right.part[1];
501 part[2] |= right.part[2];
502 part[3] |= right.part[3];
503 return *this;
504 }
505
506 inline flag128 operator ~() const
507 {
508 return flag128(~part[0], ~part[1], ~part[2], ~part[3]);
509 }
510
511 inline flag128 operator ^(const flag128& right) const
512 {
513 return flag128(part[0] ^ right.part[0], part[1] ^ right.part[1],
514 part[2] ^ right.part[2], part[3] ^ right.part[3]);
515 }
516
517 inline flag128& operator ^=(const flag128& right)
518 {
519 part[0] ^= right.part[0];
520 part[1] ^= right.part[1];
521 part[2] ^= right.part[2];
522 part[3] ^= right.part[3];
523 return *this;
524 }
525
526 inline operator bool() const
527 {
528 return (part[0] != 0 || part[1] != 0 || part[2] != 0 || part[3] != 0);
529 }
530
531 inline bool operator !() const
532 {
533 return !this->operator bool();
534 }
535
537 {
538 return part[el];
539 }
540
541 inline const uint32& operator [](uint8 el) const
542 {
543 return part[el];
544 }
545};
546
548{
549private:
551
552public:
553 flag96(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0)
554 {
555 part[0] = p1;
556 part[1] = p2;
557 part[2] = p3;
558 }
559
561 {
562 part[0] = (uint32)(p1 & UI64LIT(0x00000000FFFFFFFF));
563 part[1] = (uint32)((p1 >> 32) & UI64LIT(0x00000000FFFFFFFF));
564 part[2] = p2;
565 }
566
567 inline bool IsEqual(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0) const
568 {
569 return (part[0] == p1 && part[1] == p2 && part[2] == p3);
570 }
571
572 inline bool HasFlag(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0) const
573 {
574 return (part[0] & p1 || part[1] & p2 || part[2] & p3);
575 }
576
577 inline void Set(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0)
578 {
579 part[0] = p1;
580 part[1] = p2;
581 part[2] = p3;
582 }
583
584 inline bool operator <(const flag96& right) const
585 {
586 for (uint8 i = 3; i > 0; --i)
587 {
588 if (part[i - 1] < right.part[i - 1])
589 return true;
590 else if (part[i - 1] > right.part[i - 1])
591 return false;
592 }
593 return false;
594 }
595
596 inline bool operator ==(const flag96& right) const
597 {
598 return
599 (
600 part[0] == right.part[0] &&
601 part[1] == right.part[1] &&
602 part[2] == right.part[2]
603 );
604 }
605
606 inline bool operator !=(const flag96& right) const
607 {
608 return !this->operator ==(right);
609 }
610
611 inline flag96& operator =(const flag96& right)
612 {
613 part[0] = right.part[0];
614 part[1] = right.part[1];
615 part[2] = right.part[2];
616 return *this;
617 }
618
619 inline flag96 operator &(const flag96& right) const
620 {
621 return flag96(part[0] & right.part[0], part[1] & right.part[1],
622 part[2] & right.part[2]);
623 }
624
625 inline flag96& operator &=(const flag96& right)
626 {
627 part[0] &= right.part[0];
628 part[1] &= right.part[1];
629 part[2] &= right.part[2];
630 return *this;
631 }
632
633 inline flag96 operator |(const flag96& right) const
634 {
635 return flag96(part[0] | right.part[0], part[1] | right.part[1],
636 part[2] | right.part[2]);
637 }
638
639 inline flag96& operator |=(const flag96& right)
640 {
641 part[0] |= right.part[0];
642 part[1] |= right.part[1];
643 part[2] |= right.part[2];
644 return *this;
645 }
646
647 inline flag96 operator ~() const
648 {
649 return flag96(~part[0], ~part[1], ~part[2]);
650 }
651
652 inline flag96 operator ^(const flag96& right) const
653 {
654 return flag96(part[0] ^ right.part[0], part[1] ^ right.part[1],
655 part[2] ^ right.part[2]);
656 }
657
658 inline flag96& operator ^=(const flag96& right)
659 {
660 part[0] ^= right.part[0];
661 part[1] ^= right.part[1];
662 part[2] ^= right.part[2];
663 return *this;
664 }
665
666 inline operator bool() const
667 {
668 return (part[0] != 0 || part[1] != 0 || part[2] != 0);
669 }
670
671 inline bool operator !() const
672 {
673 return !this->operator bool();
674 }
675
677 {
678 return part[el];
679 }
680
681 inline const uint32& operator [](uint8 el) const
682 {
683 return part[el];
684 }
685};
686
696
697template <class T>
698bool CompareValues(ComparisionType type, T val1, T val2)
699{
700 switch (type)
701 {
702 case COMP_TYPE_EQ:
703 return val1 == val2;
704 case COMP_TYPE_HIGH:
705 return val1 > val2;
706 case COMP_TYPE_LOW:
707 return val1 < val2;
709 return val1 >= val2;
710 case COMP_TYPE_LOW_EQ:
711 return val1 <= val2;
712 default:
713 // incorrect parameter
714 ASSERT(false);
715 return false;
716 }
717}
718
719#endif
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define UI64LIT(N)
Definition Define.h:65
std::uint64_t uint64
Definition Define.h:76
std::int64_t int64
Definition Define.h:72
std::uint16_t uint16
Definition Define.h:78
#define ASSERT
Definition Errors.h:29
bool isBasicLatinString(const std::wstring &wstr, bool numericOrSpace)
Definition Util.h:226
void HexStrToByteArray(std::string const &str, std::array< uint8, Size > &buf, bool reverse=false)
Definition Util.h:350
float frand(float min, float max)
Definition Util.cpp:39
wchar_t wcharToLower(wchar_t wchar)
Definition Util.h:286
wchar_t wcharToUpperOnlyLatin(wchar_t wchar)
Definition Util.h:281
bool isExtendedLatinCharacter(wchar_t wchar)
Definition Util.h:151
bool isCyrillicString(const std::wstring &wstr, bool numericOrSpace)
Definition Util.h:242
bool isExtendedLatinString(const std::wstring &wstr, bool numericOrSpace)
Definition Util.h:234
int32 rand32()
Definition Util.cpp:45
bool isEastAsianString(const std::wstring &wstr, bool numericOrSpace)
Definition Util.h:250
int64 MoneyStringToMoney(const std::string &moneyString)
Definition Util.cpp:150
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.
Definition Util.cpp:244
bool roll_chance_f(float chance)
Definition Util.h:83
bool roll_chance_i(int chance)
Definition Util.h:89
T AddPct(T &base, U pct)
Definition Util.h:109
bool consoleToUtf8(const std::string &conStr, std::string &utf8str)
Definition Util.cpp:458
std::string ByteArrayToHexStr(Container const &c, bool reverse=false)
Definition Util.h:344
void wstrToLower(std::wstring &str)
Definition Util.h:314
void stripLineInvisibleChars(std::string &src)
Definition Util.cpp:94
bool IsIPAddress(char const *ipaddress)
Check if the string is a valid ip address representation.
Definition Util.cpp:229
double rand_norm(void)
Definition Util.cpp:50
uint32 TimeStringToSecs(const std::string &timestring)
Definition Util.cpp:181
std::string TimeToTimestampStr(time_t t)
Definition Util.cpp:213
bool CompareValues(ComparisionType type, T val1, T val2)
Definition Util.h:698
bool isNumeric(wchar_t wchar)
Definition Util.h:202
std::string secsToTimeString(uint64 timeInSecs, bool shortText=false, bool hoursOnly=false)
Definition Util.cpp:127
wchar_t wcharToUpper(wchar_t wchar)
Definition Util.h:258
void utf8printf(FILE *out, const char *str,...)
Definition Util.cpp:489
T RoundToInterval(T &num, T floor, T ceil)
Definition Util.h:121
bool utf8ToConsole(const std::string &utf8str, std::string &conStr)
Definition Util.cpp:441
bool Utf8FitTo(const std::string &str, const std::wstring &search)
Definition Util.cpp:473
uint32 CreatePIDFile(const std::string &filename)
create PID file
Definition Util.cpp:253
bool Utf8toWStr(const std::string &utf8str, std::wstring &wstr)
Definition Util.cpp:333
bool isEastAsianCharacter(wchar_t wchar)
Definition Util.h:181
T ApplyPct(T &base, U pct)
Definition Util.h:115
void ApplyPercentModFloatVar(float &var, float val, bool apply)
Definition Util.h:94
T CalculatePct(T base, U pct)
Definition Util.h:103
size_t utf8length(std::string &utf8str)
Definition Util.cpp:271
bool isCyrillicCharacter(wchar_t wchar)
Definition Util.h:172
void utf8truncate(std::string &utf8str, size_t len)
Definition Util.cpp:284
bool WStrToUtf8(const std::wstring &wstr, std::string &utf8str)
Definition Util.cpp:371
void wstrToUpper(std::wstring &str)
Definition Util.h:309
double rand_chance(void)
Definition Util.cpp:55
std::string GetAddressString(Skyfire::Net::Address const &addr)
Transforms network address into string format "dotted_ip:port".
Definition Util.cpp:237
bool isNumericOrSpace(wchar_t wchar)
Definition Util.h:221
std::wstring GetMainPartOfName(std::wstring wname, uint32 declension)
Definition Util.cpp:396
void vutf8printf(FILE *out, const char *str, va_list *ap)
Definition Util.cpp:497
ComparisionType
Definition Util.h:688
@ COMP_TYPE_LOW
Definition Util.h:691
@ COMP_TYPE_MAX
Definition Util.h:694
@ COMP_TYPE_HIGH
Definition Util.h:690
@ COMP_TYPE_EQ
Definition Util.h:689
@ COMP_TYPE_HIGH_EQ
Definition Util.h:692
@ COMP_TYPE_LOW_EQ
Definition Util.h:693
bool isBasicLatinCharacter(wchar_t wchar)
Definition Util.h:142
std::list< T >::iterator ListIterator
Definition Util.h:371
HookList< T > & operator+=(T t)
Definition Util.h:375
size_t size()
Definition Util.h:385
std::list< T > m_list
Definition Util.h:373
ListIterator end()
Definition Util.h:393
ListIterator begin()
Definition Util.h:389
HookList< T > & operator-=(T t)
Definition Util.h:380
StorageType m_storage
Definition Util.h:53
char * m_str
Definition Util.h:52
~Tokenizer()
Definition Util.h:41
StorageType::reference reference
Definition Util.h:36
size_type size() const
Definition Util.h:46
StorageType::size_type size_type
Definition Util.h:33
std::vector< char const * > StorageType
Definition Util.h:31
StorageType::const_iterator const_iterator
Definition Util.h:35
Tokenizer(const std::string &src, char const sep, uint32 vectorReserve=0)
Definition Util.cpp:60
StorageType::const_reference const_reference
Definition Util.h:37
reference operator[](size_type i)
Definition Util.h:48
const_iterator end() const
Definition Util.h:44
const_iterator begin() const
Definition Util.h:43
bool operator!=(const flag128 &right) const
Definition Util.h:462
uint32 & operator[](uint8 el)
Definition Util.h:536
flag128 & operator^=(const flag128 &right)
Definition Util.h:517
uint32 part[4]
Definition Util.h:402
bool HasFlag(uint32 p1=0, uint32 p2=0, uint32 p3=0, uint32 p4=0) const
Definition Util.h:426
flag128(uint32 p1=0, uint32 p2=0, uint32 p3=0, uint32 p4=0)
Definition Util.h:405
flag128(uint64 p1, uint64 p2)
Definition Util.h:413
bool operator!() const
Definition Util.h:531
flag128 operator~() const
Definition Util.h:506
flag128 operator|(const flag128 &right) const
Definition Util.h:491
bool operator<(const flag128 &right) const
Definition Util.h:439
flag128 operator^(const flag128 &right) const
Definition Util.h:511
flag128 & operator&=(const flag128 &right)
Definition Util.h:482
flag128 & operator|=(const flag128 &right)
Definition Util.h:497
flag128 & operator=(const flag128 &right)
Definition Util.h:467
bool operator==(const flag128 &right) const
Definition Util.h:451
bool IsEqual(uint32 p1=0, uint32 p2=0, uint32 p3=0, uint32 p4=0) const
Definition Util.h:421
flag128 operator&(const flag128 &right) const
Definition Util.h:476
void Set(uint32 p1=0, uint32 p2=0, uint32 p3=0, uint32 p4=0)
Definition Util.h:431
bool operator<(const flag96 &right) const
Definition Util.h:584
bool HasFlag(uint32 p1=0, uint32 p2=0, uint32 p3=0) const
Definition Util.h:572
flag96 operator~() const
Definition Util.h:647
flag96 & operator&=(const flag96 &right)
Definition Util.h:625
bool IsEqual(uint32 p1=0, uint32 p2=0, uint32 p3=0) const
Definition Util.h:567
flag96(uint32 p1=0, uint32 p2=0, uint32 p3=0)
Definition Util.h:553
flag96 operator&(const flag96 &right) const
Definition Util.h:619
flag96 operator^(const flag96 &right) const
Definition Util.h:652
bool operator!=(const flag96 &right) const
Definition Util.h:606
bool operator==(const flag96 &right) const
Definition Util.h:596
flag96 & operator^=(const flag96 &right)
Definition Util.h:658
flag96(uint64 p1, uint32 p2)
Definition Util.h:560
uint32 part[3]
Definition Util.h:550
flag96 operator|(const flag96 &right) const
Definition Util.h:633
bool operator!() const
Definition Util.h:671
void Set(uint32 p1=0, uint32 p2=0, uint32 p3=0)
Definition Util.h:577
uint32 & operator[](uint8 el)
Definition Util.h:676
flag96 & operator=(const flag96 &right)
Definition Util.h:611
flag96 & operator|=(const flag96 &right)
Definition Util.h:639
std::string ByteArrayToHexStr(uint8 const *bytes, size_t length, bool reverse=false)
Definition Util.cpp:515
void HexStrToByteArray(std::string const &str, uint8 *out, size_t outlen, bool reverse=false)
Definition Util.cpp:539
bool operator()(const std::pair< int, S > &obj)
Definition Util.h:25
Finder(T val, T S::*idMember)
Definition Util.h:24
T val_
Definition Util.h:21
T S::* idMember_
Definition Util.h:22