TrinityCore
Loading...
Searching...
No Matches
Util.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef _UTIL_H
19#define _UTIL_H
20
21#include "Define.h"
22#include "Errors.h"
23#include "Optional.h"
24
25#include <array>
26#include <string>
27#include <string_view>
28#include <sstream>
29#include <typeinfo>
30#include <utility>
31#include <vector>
32
33enum class TimeFormat : uint8
34{
35 FullText, // 1 Days 2 Hours 3 Minutes 4 Seconds
36 ShortText, // 1d 2h 3m 4s
37 Numeric // 1:2:3:4
38};
39
40namespace Trinity
41{
43
44 TC_COMMON_API std::vector<std::string_view> Tokenize(std::string_view str, char sep, bool keepEmpty);
45
46 /* this would return string_view into temporary otherwise */
47 std::vector<std::string_view> Tokenize(std::string&&, char, bool) = delete;
48 std::vector<std::string_view> Tokenize(std::string const&&, char, bool) = delete;
49
50 /* the delete overload means we need to make this explicit */
51 inline std::vector<std::string_view> Tokenize(char const* str, char sep, bool keepEmpty) { return Tokenize(std::string_view(str ? str : ""), sep, keepEmpty); }
52}
53
54TC_COMMON_API Optional<int32> MoneyStringToMoney(std::string const& moneyString);
55
56#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
57TC_COMMON_API struct tm* localtime_r(time_t const* time, struct tm *result);
58TC_COMMON_API struct tm* gmtime_r(time_t const* time, struct tm *result);
59TC_COMMON_API time_t timegm(struct tm* tm);
60#endif
61TC_COMMON_API time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime = true);
62TC_COMMON_API tm TimeBreakdown(time_t t);
63
64TC_COMMON_API std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat = TimeFormat::FullText, bool hoursOnly = false);
65TC_COMMON_API uint32 TimeStringToSecs(std::string const& timestring);
66TC_COMMON_API std::string TimeToTimestampStr(time_t t);
67TC_COMMON_API std::string TimeToHumanReadable(time_t t);
68
69// Percentage calculation
70template <class T, class U>
71inline T CalculatePct(T base, U pct)
72{
73 return T(base * static_cast<float>(pct) / 100.0f);
74}
75
76template <class T, class U>
77inline T AddPct(T &base, U pct)
78{
79 return base += CalculatePct(base, pct);
80}
81
82template <class T, class U>
83inline T ApplyPct(T &base, U pct)
84{
85 return base = CalculatePct(base, pct);
86}
87
88template <class T>
89inline T RoundToInterval(T& num, T floor, T ceil)
90{
91 return num = std::min(std::max(num, floor), ceil);
92}
93
94template <class T>
95inline T square(T x) { return x*x; }
96
97// UTF8 handling
98TC_COMMON_API bool Utf8toWStr(std::string_view utf8str, std::wstring& wstr);
99
100// in wsize==max size of buffer, out wsize==real string size
101TC_COMMON_API bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize);
102
103inline bool Utf8toWStr(std::string_view utf8str, wchar_t* wstr, size_t& wsize)
104{
105 return Utf8toWStr(utf8str.data(), utf8str.size(), wstr, wsize);
106}
107
108TC_COMMON_API bool WStrToUtf8(std::wstring_view wstr, std::string& utf8str);
109// size==real string size
110TC_COMMON_API bool WStrToUtf8(wchar_t const* wstr, size_t size, std::string& utf8str);
111
112// set string to "" if invalid utf8 sequence
113TC_COMMON_API size_t utf8length(std::string& utf8str);
114TC_COMMON_API void utf8truncate(std::string& utf8str, size_t len);
115
116inline bool isBasicLatinCharacter(wchar_t wchar)
117{
118 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
119 return true;
120 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
121 return true;
122 return false;
123}
124
125inline bool isExtendedLatinCharacter(wchar_t wchar)
126{
127 if (isBasicLatinCharacter(wchar))
128 return true;
129 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
130 return true;
131 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
132 return true;
133 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
134 return true;
135 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
136 return true;
137 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
138 return true;
139 if (wchar >= 0x0100 && wchar <= 0x012F) // LATIN CAPITAL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK
140 return true;
141 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
142 return true;
143 return false;
144}
145
146inline bool isCyrillicCharacter(wchar_t wchar)
147{
148 if (wchar >= 0x0410 && wchar <= 0x044F) // CYRILLIC CAPITAL LETTER A - CYRILLIC SMALL LETTER YA
149 return true;
150 if (wchar == 0x0401 || wchar == 0x0451) // CYRILLIC CAPITAL LETTER IO, CYRILLIC SMALL LETTER IO
151 return true;
152 return false;
153}
154
155inline bool isEastAsianCharacter(wchar_t wchar)
156{
157 if (wchar >= 0x1100 && wchar <= 0x11F9) // Hangul Jamo
158 return true;
159 if (wchar >= 0x3041 && wchar <= 0x30FF) // Hiragana + Katakana
160 return true;
161 if (wchar >= 0x3131 && wchar <= 0x318E) // Hangul Compatibility Jamo
162 return true;
163 if (wchar >= 0x31F0 && wchar <= 0x31FF) // Katakana Phonetic Ext.
164 return true;
165 if (wchar >= 0x3400 && wchar <= 0x4DB5) // CJK Ideographs Ext. A
166 return true;
167 if (wchar >= 0x4E00 && wchar <= 0x9FC3) // Unified CJK Ideographs
168 return true;
169 if (wchar >= 0xAC00 && wchar <= 0xD7A3) // Hangul Syllables
170 return true;
171 if (wchar >= 0xFF01 && wchar <= 0xFFEE) // Halfwidth forms
172 return true;
173 return false;
174}
175
176inline bool isNumeric(wchar_t wchar)
177{
178 return (wchar >= L'0' && wchar <=L'9');
179}
180
181inline bool isNumeric(char c)
182{
183 return (c >= '0' && c <='9');
184}
185
186inline bool isNumeric(char const* str)
187{
188 for (char const* c = str; *c; ++c)
189 if (!isNumeric(*c))
190 return false;
191
192 return true;
193}
194
195inline bool isNumericOrSpace(wchar_t wchar)
196{
197 return isNumeric(wchar) || wchar == L' ';
198}
199
200inline bool isBasicLatinString(std::wstring_view wstr, bool numericOrSpace)
201{
202 for (wchar_t c : wstr)
203 if (!isBasicLatinCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
204 return false;
205 return true;
206}
207
208inline bool isExtendedLatinString(std::wstring_view wstr, bool numericOrSpace)
209{
210 for (wchar_t c : wstr)
211 if (!isExtendedLatinCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
212 return false;
213 return true;
214}
215
216inline bool isCyrillicString(std::wstring_view wstr, bool numericOrSpace)
217{
218 for (wchar_t c : wstr)
219 if (!isCyrillicCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
220 return false;
221 return true;
222}
223
224inline bool isEastAsianString(std::wstring_view wstr, bool numericOrSpace)
225{
226 for (wchar_t c : wstr)
227 if (!isEastAsianCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
228 return false;
229 return true;
230}
231
233{
234 wchar_t operator()(wchar_t wchar) const
235 {
236 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
237 return wchar_t(uint16(wchar) - 0x0020);
238 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
239 return wchar_t(0x1E9E);
240 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
241 return wchar_t(uint16(wchar) - 0x0020);
242 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
243 return wchar_t(uint16(wchar) - 0x0020);
244 if (wchar >= 0x0101 && wchar <= 0x012F) // LATIN SMALL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK (only %2=1)
245 {
246 if (wchar % 2 == 1)
247 return wchar_t(uint16(wchar) - 0x0001);
248 }
249 if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
250 return wchar_t(uint16(wchar) - 0x0020);
251 if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
252 return wchar_t(0x0401);
253
254 return wchar;
255 }
256} inline constexpr wcharToUpper;
257
259{
260 wchar_t operator()(wchar_t wchar) const
261 {
262 return isBasicLatinCharacter(wchar) ? wcharToUpper(wchar) : wchar;
263 }
264} inline constexpr wcharToUpperOnlyLatin;
265
267{
268 wchar_t operator()(wchar_t wchar) const
269 {
270 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
271 return wchar_t(uint16(wchar)+0x0020);
272 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
273 return wchar_t(uint16(wchar)+0x0020);
274 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
275 return wchar_t(uint16(wchar)+0x0020);
276 if (wchar >= 0x0100 && wchar <= 0x012E) // LATIN CAPITAL LETTER A WITH MACRON - LATIN CAPITAL LETTER I WITH OGONEK (only %2=0)
277 {
278 if (wchar % 2 == 0)
279 return wchar_t(uint16(wchar)+0x0001);
280 }
281 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
282 return wchar_t(0x00DF);
283 if (wchar == 0x0401) // CYRILLIC CAPITAL LETTER IO
284 return wchar_t(0x0451);
285 if (wchar >= 0x0410 && wchar <= 0x042F) // CYRILLIC CAPITAL LETTER A - CYRILLIC CAPITAL LETTER YA
286 return wchar_t(uint16(wchar)+0x0020);
287
288 return wchar;
289 }
290} inline constexpr wcharToLower;
291
293{
294 char operator()(char c) const { return std::toupper(static_cast<unsigned char>(c)); }
295} inline constexpr charToUpper;
296
298{
299 char operator()(char c) const { return std::tolower(static_cast<unsigned char>(c)); }
300} inline constexpr charToLower;
301
302TC_COMMON_API void wstrToUpper(std::wstring& str);
303TC_COMMON_API void wstrToLower(std::wstring& str);
304TC_COMMON_API void strToUpper(std::string& str);
305TC_COMMON_API void strToLower(std::string& str);
306
307TC_COMMON_API std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension);
308
309TC_COMMON_API bool utf8ToConsole(std::string_view utf8str, std::string& conStr);
310TC_COMMON_API bool consoleToUtf8(std::string_view conStr, std::string& utf8str);
311TC_COMMON_API bool Utf8FitTo(std::string_view str, std::wstring_view search);
312TC_COMMON_API void utf8printf(FILE* out, const char *str, ...);
313TC_COMMON_API void vutf8printf(FILE* out, const char *str, va_list* ap);
314TC_COMMON_API bool Utf8ToUpperOnlyLatin(std::string& utf8String);
315
316#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
317TC_COMMON_API bool ReadWinConsole(std::string& str, size_t size = 256);
318TC_COMMON_API bool WriteWinConsole(std::string_view str, bool error = false);
319#endif
320
322
323TC_COMMON_API bool IsIPAddress(char const* ipaddress);
324
325TC_COMMON_API uint32 CreatePIDFile(std::string const& filename);
327
328namespace Trinity::Impl
329{
330 TC_COMMON_API std::string ByteArrayToHexStr(uint8 const* bytes, size_t length, bool reverse = false);
331 TC_COMMON_API void HexStrToByteArray(std::string_view str, uint8* out, size_t outlen, bool reverse = false);
332}
333
334template <typename Container>
335std::string ByteArrayToHexStr(Container const& c, bool reverse = false)
336{
337 return Trinity::Impl::ByteArrayToHexStr(std::data(c), std::size(c), reverse);
338}
339
340template <size_t Size>
341void HexStrToByteArray(std::string_view str, std::array<uint8, Size>& buf, bool reverse = false)
342{
343 Trinity::Impl::HexStrToByteArray(str, buf.data(), Size, reverse);
344}
345template <size_t Size>
346std::array<uint8, Size> HexStrToByteArray(std::string_view str, bool reverse = false)
347{
348 std::array<uint8, Size> arr;
349 HexStrToByteArray(str, arr, reverse);
350 return arr;
351}
352
353inline std::vector<uint8> HexStrToByteVector(std::string_view str, bool reverse = false)
354{
355 std::vector<uint8> buf;
356 size_t const sz = (str.size() / 2);
357 buf.resize(sz);
358 Trinity::Impl::HexStrToByteArray(str, buf.data(), sz, reverse);
359 return buf;
360}
361
362TC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2);
363inline bool StringStartsWith(std::string_view haystack, std::string_view needle) { return (haystack.substr(0, needle.length()) == needle); }
364inline bool StringStartsWithI(std::string_view haystack, std::string_view needle) { return StringEqualI(haystack.substr(0, needle.length()), needle); }
365TC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle);
366template <typename T>
367inline bool ValueContainsStringI(std::pair<T, std::string_view> const& haystack, std::string_view needle)
368{
369 return StringContainsStringI(haystack.second, needle);
370}
371TC_COMMON_API bool StringCompareLessI(std::string_view a, std::string_view b);
372
374 bool operator()(std::string_view a, std::string_view b) const { return StringCompareLessI(a, b); }
375};
376
377// simple class for not-modifyable list
378template <typename T>
379class HookList final
380{
381 private:
382 typedef std::vector<T> ContainerType;
383
385
386 public:
387 typedef typename ContainerType::iterator iterator;
388
390 {
391 _container.push_back(std::move(t));
392 return *this;
393 }
394
395 size_t size() const
396 {
397 return _container.size();
398 }
399
401 {
402 return _container.begin();
403 }
404
406 {
407 return _container.end();
408 }
409};
410
412{
413private:
414 uint32 part[3];
415
416public:
417 flag96(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0)
418 {
419 part[0] = p1;
420 part[1] = p2;
421 part[2] = p3;
422 }
423
424 inline bool IsEqual(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0) const
425 {
426 return (part[0] == p1 && part[1] == p2 && part[2] == p3);
427 }
428
429 inline bool HasFlag(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0) const
430 {
431 return (part[0] & p1 || part[1] & p2 || part[2] & p3);
432 }
433
434 inline void Set(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0)
435 {
436 part[0] = p1;
437 part[1] = p2;
438 part[2] = p3;
439 }
440
441 inline bool operator==(flag96 const& right) const
442 {
443 return
444 (
445 part[0] == right.part[0] &&
446 part[1] == right.part[1] &&
447 part[2] == right.part[2]
448 );
449 }
450
451 inline bool operator!=(flag96 const& right) const
452 {
453 return !(*this == right);
454 }
455
456 inline flag96 operator&(flag96 const& right) const
457 {
458 return flag96(part[0] & right.part[0], part[1] & right.part[1], part[2] & right.part[2]);
459 }
460
461 inline flag96& operator&=(flag96 const& right)
462 {
463 part[0] &= right.part[0];
464 part[1] &= right.part[1];
465 part[2] &= right.part[2];
466 return *this;
467 }
468
469 inline flag96 operator|(flag96 const& right) const
470 {
471 return flag96(part[0] | right.part[0], part[1] | right.part[1], part[2] | right.part[2]);
472 }
473
474 inline flag96& operator |=(flag96 const& right)
475 {
476 part[0] |= right.part[0];
477 part[1] |= right.part[1];
478 part[2] |= right.part[2];
479 return *this;
480 }
481
482 inline flag96 operator~() const
483 {
484 return flag96(~part[0], ~part[1], ~part[2]);
485 }
486
487 inline flag96 operator^(flag96 const& right) const
488 {
489 return flag96(part[0] ^ right.part[0], part[1] ^ right.part[1], part[2] ^ right.part[2]);
490 }
491
492 inline flag96& operator^=(flag96 const& right)
493 {
494 part[0] ^= right.part[0];
495 part[1] ^= right.part[1];
496 part[2] ^= right.part[2];
497 return *this;
498 }
499
500 inline operator bool() const
501 {
502 return (part[0] != 0 || part[1] != 0 || part[2] != 0);
503 }
504
505 inline bool operator !() const
506 {
507 return !(bool(*this));
508 }
509
511 {
512 return part[el];
513 }
514
515 inline uint32 const& operator [](uint8 el) const
516 {
517 return part[el];
518 }
519};
520
530
531template <class T>
532bool CompareValues(ComparisionType type, T val1, T val2)
533{
534 switch (type)
535 {
536 case COMP_TYPE_EQ:
537 return val1 == val2;
538 case COMP_TYPE_HIGH:
539 return val1 > val2;
540 case COMP_TYPE_LOW:
541 return val1 < val2;
543 return val1 >= val2;
544 case COMP_TYPE_LOW_EQ:
545 return val1 <= val2;
546 default:
547 // incorrect parameter
548 ABORT();
549 return false;
550 }
551}
552
553template<typename E>
554constexpr typename std::underlying_type<E>::type AsUnderlyingType(E enumValue)
555{
556 static_assert(std::is_enum<E>::value, "AsUnderlyingType can only be used with enums");
557 return static_cast<typename std::underlying_type<E>::type>(enumValue);
558}
559
560template<typename Ret, typename T1, typename... T>
561Ret* Coalesce(T1* first, T*... rest)
562{
563 if constexpr (sizeof...(T) > 0)
564 return (first ? static_cast<Ret*>(first) : Coalesce<Ret>(rest...));
565 else
566 return static_cast<Ret*>(first);
567}
568
569namespace Trinity
570{
571namespace Impl
572{
573 TC_COMMON_API std::string GetTypeName(std::type_info const&);
574}
575
576template <typename T>
577std::string GetTypeName() { return Impl::GetTypeName(typeid(T)); }
578template <typename T>
579std::string GetTypeName(T&& v)
580{
581 if constexpr (std::is_same_v<std::remove_cv_t<T>, std::type_info>)
582 return Impl::GetTypeName(v);
583 else
584 return Impl::GetTypeName(typeid(v));
585}
586}
587
588#endif
uint8_t uint8
Definition Define.h:135
#define TC_COMMON_API
Definition Define.h:96
uint64_t uint64
Definition Define.h:132
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
constexpr T & operator|=(T &left, T right)
Definition EnumFlag.h:53
#define ABORT
Definition Errors.h:74
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
void HexStrToByteArray(std::string_view str, std::array< uint8, Size > &buf, bool reverse=false)
Definition Util.h:341
TC_COMMON_API bool ReadWinConsole(std::string &str, size_t size=256)
Definition Util.cpp:622
TC_COMMON_API std::wstring GetMainPartOfName(std::wstring const &wname, uint32 declension)
Definition Util.cpp:484
TC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2)
Definition Util.cpp:706
TC_COMMON_API bool IsIPAddress(char const *ipaddress)
Check if the string is a valid ip address representation.
Definition Util.cpp:313
T square(T x)
Definition Util.h:95
bool isCyrillicString(std::wstring_view wstr, bool numericOrSpace)
Definition Util.h:216
struct WcharToUpperOnlyLatin wcharToUpperOnlyLatin
bool isExtendedLatinCharacter(wchar_t wchar)
Definition Util.h:125
TC_COMMON_API void wstrToLower(std::wstring &str)
Definition Util.cpp:480
TC_COMMON_API void utf8truncate(std::string &utf8str, size_t len)
Definition Util.cpp:362
bool StringStartsWith(std::string_view haystack, std::string_view needle)
Definition Util.h:363
TC_COMMON_API void vutf8printf(FILE *out, const char *str, va_list *ap)
Definition Util.cpp:589
T AddPct(T &base, U pct)
Definition Util.h:77
std::string ByteArrayToHexStr(Container const &c, bool reverse=false)
Definition Util.h:335
TimeFormat
Definition Util.h:34
bool CompareValues(ComparisionType type, T val1, T val2)
Definition Util.h:532
bool isNumeric(wchar_t wchar)
Definition Util.h:176
TC_COMMON_API bool Utf8toWStr(std::string_view utf8str, std::wstring &wstr)
Definition Util.cpp:417
bool isBasicLatinString(std::wstring_view wstr, bool numericOrSpace)
Definition Util.h:200
TC_COMMON_API uint32 GetPID()
Definition Util.cpp:338
TC_COMMON_API void utf8printf(FILE *out, const char *str,...)
Definition Util.cpp:581
Ret * Coalesce(T1 *first, T *... rest)
Definition Util.h:561
std::vector< uint8 > HexStrToByteVector(std::string_view str, bool reverse=false)
Definition Util.h:353
TC_COMMON_API std::string TimeToHumanReadable(time_t t)
Definition Util.cpp:303
T RoundToInterval(T &num, T floor, T ceil)
Definition Util.h:89
TC_COMMON_API Optional< std::size_t > RemoveCRLF(std::string &str)
Definition Util.cpp:654
TC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle)
Definition Util.cpp:711
TC_COMMON_API bool WriteWinConsole(std::string_view str, bool error=false)
Definition Util.cpp:641
bool isEastAsianString(std::wstring_view wstr, bool numericOrSpace)
Definition Util.h:224
TC_COMMON_API std::string TimeToTimestampStr(time_t t)
Definition Util.cpp:290
TC_COMMON_API time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime=true)
Definition Util.cpp:100
bool ValueContainsStringI(std::pair< T, std::string_view > const &haystack, std::string_view needle)
Definition Util.h:367
TC_COMMON_API bool WStrToUtf8(std::wstring_view wstr, std::string &utf8str)
Definition Util.cpp:456
struct WcharToLower wcharToLower
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition Util.h:554
TC_COMMON_API tm TimeBreakdown(time_t t)
Definition Util.cpp:93
TC_COMMON_API uint32 TimeStringToSecs(std::string const &timestring)
Definition Util.cpp:258
TC_COMMON_API bool utf8ToConsole(std::string_view utf8str, std::string &conStr)
Definition Util.cpp:533
TC_COMMON_API std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat=TimeFormat::FullText, bool hoursOnly=false)
Definition Util.cpp:115
TC_COMMON_API uint32 CreatePIDFile(std::string const &filename)
create PID file
Definition Util.cpp:324
TC_COMMON_API void strToUpper(std::string &str)
Definition Util.cpp:481
bool StringStartsWithI(std::string_view haystack, std::string_view needle)
Definition Util.h:364
bool isEastAsianCharacter(wchar_t wchar)
Definition Util.h:155
bool isExtendedLatinString(std::wstring_view wstr, bool numericOrSpace)
Definition Util.h:208
T ApplyPct(T &base, U pct)
Definition Util.h:83
TC_COMMON_API Optional< int32 > MoneyStringToMoney(std::string const &moneyString)
Definition Util.cpp:216
TC_COMMON_API void strToLower(std::string &str)
Definition Util.cpp:482
TC_COMMON_API bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition Util.cpp:610
TC_COMMON_API bool StringCompareLessI(std::string_view a, std::string_view b)
Definition Util.cpp:717
struct CharToUpper charToUpper
T CalculatePct(T base, U pct)
Definition Util.h:71
bool isCyrillicCharacter(wchar_t wchar)
Definition Util.h:146
TC_COMMON_API bool Utf8FitTo(std::string_view str, std::wstring_view search)
Definition Util.cpp:565
struct CharToLower charToLower
TC_COMMON_API void wstrToUpper(std::wstring &str)
Definition Util.cpp:479
TC_COMMON_API bool consoleToUtf8(std::string_view conStr, std::string &utf8str)
Definition Util.cpp:550
bool isNumericOrSpace(wchar_t wchar)
Definition Util.h:195
struct WcharToUpper wcharToUpper
TC_COMMON_API size_t utf8length(std::string &utf8str)
Definition Util.cpp:349
ComparisionType
Definition Util.h:522
@ COMP_TYPE_LOW
Definition Util.h:525
@ COMP_TYPE_MAX
Definition Util.h:528
@ COMP_TYPE_HIGH
Definition Util.h:524
@ COMP_TYPE_EQ
Definition Util.h:523
@ COMP_TYPE_HIGH_EQ
Definition Util.h:526
@ COMP_TYPE_LOW_EQ
Definition Util.h:527
bool isBasicLatinCharacter(wchar_t wchar)
Definition Util.h:116
HookList< T > & operator+=(T &&t)
Definition Util.h:389
iterator end()
Definition Util.h:405
size_t size() const
Definition Util.h:395
std::vector< T > ContainerType
Definition Util.h:382
ContainerType::iterator iterator
Definition Util.h:387
ContainerType _container
Definition Util.h:384
iterator begin()
Definition Util.h:400
Definition Util.h:412
flag96 & operator&=(flag96 const &right)
Definition Util.h:461
bool operator!=(flag96 const &right) const
Definition Util.h:451
bool HasFlag(uint32 p1=0, uint32 p2=0, uint32 p3=0) const
Definition Util.h:429
flag96 operator~() const
Definition Util.h:482
flag96 operator^(flag96 const &right) const
Definition Util.h:487
bool IsEqual(uint32 p1=0, uint32 p2=0, uint32 p3=0) const
Definition Util.h:424
flag96(uint32 p1=0, uint32 p2=0, uint32 p3=0)
Definition Util.h:417
bool operator==(flag96 const &right) const
Definition Util.h:441
flag96 operator&(flag96 const &right) const
Definition Util.h:456
uint32 part[3]
Definition Util.h:414
void Set(uint32 p1=0, uint32 p2=0, uint32 p3=0)
Definition Util.h:434
flag96 operator|(flag96 const &right) const
Definition Util.h:469
uint32 & operator[](uint8 el)
Definition Util.h:510
flag96 & operator^=(flag96 const &right)
Definition Util.h:492
TC_COMMON_API void HexStrToByteArray(std::string_view str, uint8 *out, size_t outlen, bool reverse=false)
Definition Util.cpp:686
TC_COMMON_API std::string ByteArrayToHexStr(uint8 const *bytes, size_t length, bool reverse=false)
Definition Util.cpp:664
TC_COMMON_API std::string GetTypeName(std::type_info const &)
Definition Util.cpp:722
TC_COMMON_API void VerifyOsVersion()
Definition Util.cpp:34
TC_COMMON_API std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition Util.cpp:56
std::string GetTypeName()
Definition Util.h:577
char operator()(char c) const
Definition Util.h:299
char operator()(char c) const
Definition Util.h:294
bool operator()(std::string_view a, std::string_view b) const
Definition Util.h:374
wchar_t operator()(wchar_t wchar) const
Definition Util.h:268
wchar_t operator()(wchar_t wchar) const
Definition Util.h:260
wchar_t operator()(wchar_t wchar) const
Definition Util.h:234