TrinityCore
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 <typeinfo>
29#include <utility>
30#include <vector>
31
33
34enum class TimeFormat : uint8
35{
36 FullText, // 1 Days 2 Hours 3 Minutes 4 Seconds
37 ShortText, // 1d 2h 3m 4s
38 Numeric // 1:2:3:4
39};
40
41namespace Trinity
42{
44
45 TC_COMMON_API std::vector<std::string_view> Tokenize(std::string_view str, char sep, bool keepEmpty);
46
47 /* this would return string_view into temporary otherwise */
48 std::vector<std::string_view> Tokenize(std::string&&, char, bool) = delete;
49 std::vector<std::string_view> Tokenize(std::string const&&, char, bool) = delete;
50
51 /* the delete overload means we need to make this explicit */
52 inline std::vector<std::string_view> Tokenize(char const* str, char sep, bool keepEmpty) { return Tokenize(std::string_view(str ? str : ""), sep, keepEmpty); }
53}
54
55TC_COMMON_API Optional<int64> MoneyStringToMoney(std::string const& moneyString);
56
57#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
58TC_COMMON_API struct tm* localtime_r(time_t const* time, struct tm *result);
59TC_COMMON_API struct tm* gmtime_r(time_t const* time, struct tm *result);
60TC_COMMON_API time_t timegm(struct tm* tm);
61#endif
62TC_COMMON_API time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime = true);
63TC_COMMON_API tm TimeBreakdown(time_t t);
64
65TC_COMMON_API std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat = TimeFormat::FullText, bool hoursOnly = false);
66TC_COMMON_API uint32 TimeStringToSecs(std::string const& timestring);
67TC_COMMON_API std::string TimeToTimestampStr(time_t t);
68TC_COMMON_API std::string TimeToHumanReadable(time_t t);
69
70// Percentage calculation
71template <class T, class U>
72inline T CalculatePct(T base, U pct)
73{
74 return T(base * static_cast<float>(pct) / 100.0f);
75}
76
77template <class T>
78inline float GetPctOf(T value, T max)
79{
80 ASSERT(max);
81 return float(static_cast<float>(value) / static_cast<float>(max) * 100.0f);
82}
83
84template <class T, class U>
85inline T AddPct(T &base, U pct)
86{
87 return base += CalculatePct(base, pct);
88}
89
90template <class T, class U>
91inline T ApplyPct(T &base, U pct)
92{
93 return base = CalculatePct(base, pct);
94}
95
96template <class T>
97inline T RoundToInterval(T& num, T floor, T ceil)
98{
99 return num = std::min(std::max(num, floor), ceil);
100}
101
102template <class T>
103inline T square(T x) { return x*x; }
104
105// UTF8 handling
106TC_COMMON_API bool Utf8toWStr(std::string_view utf8str, std::wstring& wstr);
107
108// in wsize==max size of buffer, out wsize==real string size
109TC_COMMON_API bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize);
110
111inline bool Utf8toWStr(std::string_view utf8str, wchar_t* wstr, size_t& wsize)
112{
113 return Utf8toWStr(utf8str.data(), utf8str.size(), wstr, wsize);
114}
115
116TC_COMMON_API bool WStrToUtf8(std::wstring_view wstr, std::string& utf8str);
117// size==real string size
118TC_COMMON_API bool WStrToUtf8(wchar_t const* wstr, size_t size, std::string& utf8str);
119
120// set string to "" if invalid utf8 sequence
121TC_COMMON_API size_t utf8length(std::string& utf8str);
122TC_COMMON_API void utf8truncate(std::string& utf8str, size_t len);
123
124inline bool isBasicLatinCharacter(wchar_t wchar)
125{
126 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
127 return true;
128 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
129 return true;
130 return false;
131}
132
133inline bool isExtendedLatinCharacter(wchar_t wchar)
134{
135 if (isBasicLatinCharacter(wchar))
136 return true;
137 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
138 return true;
139 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
140 return true;
141 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
142 return true;
143 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
144 return true;
145 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
146 return true;
147 if (wchar >= 0x0100 && wchar <= 0x012F) // LATIN CAPITAL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK
148 return true;
149 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
150 return true;
151 return false;
152}
153
154inline bool isCyrillicCharacter(wchar_t wchar)
155{
156 if (wchar >= 0x0410 && wchar <= 0x044F) // CYRILLIC CAPITAL LETTER A - CYRILLIC SMALL LETTER YA
157 return true;
158 if (wchar == 0x0401 || wchar == 0x0451) // CYRILLIC CAPITAL LETTER IO, CYRILLIC SMALL LETTER IO
159 return true;
160 return false;
161}
162
163inline bool isKoreanCharacter(wchar_t wchar)
164{
165 if (wchar >= 0x1100 && wchar <= 0x11F9) // Hangul Jamo
166 return true;
167 if (wchar >= 0x3131 && wchar <= 0x318E) // Hangul Compatibility Jamo
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 isChineseCharacter(wchar_t wchar)
177{
178 if (wchar >= 0x4E00 && wchar <= 0x9FFF) // Unified CJK Ideographs
179 return true;
180 if (wchar >= 0x3400 && wchar <= 0x4DBF) // CJK Ideographs Ext. A
181 return true;
182 if (wchar >= 0x3100 && wchar <= 0x312C) // Bopomofo
183 return true;
184 if (wchar >= 0xF900 && wchar <= 0xFAFF) // CJK Compatibility Ideographs
185 return true;
186 return false;
187}
188
189inline bool isNumeric(wchar_t wchar)
190{
191 return (wchar >= L'0' && wchar <=L'9');
192}
193
194inline bool isNumeric(char c)
195{
196 return (c >= '0' && c <='9');
197}
198
199inline bool isNumeric(char const* str)
200{
201 for (char const* c = str; *c; ++c)
202 if (!isNumeric(*c))
203 return false;
204
205 return true;
206}
207
208inline bool isNumericOrSpace(wchar_t wchar)
209{
210 return isNumeric(wchar) || wchar == L' ';
211}
212
213inline bool isBasicLatinString(std::wstring_view wstr, bool numericOrSpace)
214{
215 for (wchar_t c : wstr)
216 if (!isBasicLatinCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
217 return false;
218 return true;
219}
220
221inline bool isExtendedLatinString(std::wstring_view wstr, bool numericOrSpace)
222{
223 for (wchar_t c : wstr)
224 if (!isExtendedLatinCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
225 return false;
226 return true;
227}
228
229inline bool isCyrillicString(std::wstring_view wstr, bool numericOrSpace)
230{
231 for (wchar_t c : wstr)
232 if (!isCyrillicCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
233 return false;
234 return true;
235}
236
237inline bool isKoreanString(std::wstring_view wstr, bool numericOrSpace)
238{
239 for (wchar_t c : wstr)
240 if (!isKoreanCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
241 return false;
242 return true;
243}
244
245inline bool isChineseString(std::wstring_view wstr, bool numericOrSpace)
246{
247 for (wchar_t c : wstr)
248 if (!isChineseCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
249 return false;
250 return true;
251}
252
254{
255 wchar_t operator()(wchar_t wchar) const
256 {
257 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
258 return wchar_t(uint16(wchar) - 0x0020);
259 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
260 return wchar_t(0x1E9E);
261 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
262 return wchar_t(uint16(wchar) - 0x0020);
263 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
264 return wchar_t(uint16(wchar) - 0x0020);
265 if (wchar >= 0x0101 && wchar <= 0x012F) // LATIN SMALL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK (only %2=1)
266 {
267 if (wchar % 2 == 1)
268 return wchar_t(uint16(wchar) - 0x0001);
269 }
270 if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
271 return wchar_t(uint16(wchar) - 0x0020);
272 if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
273 return wchar_t(0x0401);
274 if (wchar == 0x0153) // LATIN SMALL LIGATURE OE
275 return wchar_t(0x0152);
276 if (wchar == 0x00FF) // LATIN SMALL LETTER Y WITH DIAERESIS
277 return wchar_t(0x0178);
278
279 return wchar;
280 }
281} inline constexpr wcharToUpper;
282
284{
285 wchar_t operator()(wchar_t wchar) const
286 {
287 return isBasicLatinCharacter(wchar) ? wcharToUpper(wchar) : wchar;
288 }
289} inline constexpr wcharToUpperOnlyLatin;
290
292{
293 wchar_t operator()(wchar_t wchar) const
294 {
295 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
296 return wchar_t(uint16(wchar)+0x0020);
297 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
298 return wchar_t(uint16(wchar)+0x0020);
299 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
300 return wchar_t(uint16(wchar)+0x0020);
301 if (wchar >= 0x0100 && wchar <= 0x012E) // LATIN CAPITAL LETTER A WITH MACRON - LATIN CAPITAL LETTER I WITH OGONEK (only %2=0)
302 {
303 if (wchar % 2 == 0)
304 return wchar_t(uint16(wchar)+0x0001);
305 }
306 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
307 return wchar_t(0x00DF);
308 if (wchar == 0x0401) // CYRILLIC CAPITAL LETTER IO
309 return wchar_t(0x0451);
310 if (wchar == 0x0152) // LATIN CAPITAL LIGATURE OE
311 return wchar_t(0x0153);
312 if (wchar == 0x0178) // LATIN CAPITAL LETTER Y WITH DIAERESIS
313 return wchar_t(0x00FF);
314 if (wchar >= 0x0410 && wchar <= 0x042F) // CYRILLIC CAPITAL LETTER A - CYRILLIC CAPITAL LETTER YA
315 return wchar_t(uint16(wchar)+0x0020);
316
317 return wchar;
318 }
319} inline constexpr wcharToLower;
320
321inline bool isLower(wchar_t wchar)
322{
323 if (wchar >= L'a' && wchar <= L'z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
324 return true;
325 if (wchar >= 0x00E0 && wchar <= 0x00FF) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER Y WITH DIAERESIS
326 return true;
327 if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
328 return true;
329 if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
330 return true;
331 return false;
332}
333
334inline bool isUpper(wchar_t wchar)
335{
336 return !isLower(wchar);
337}
338
340{
341 char operator()(char c) const { return std::toupper(static_cast<unsigned char>(c)); }
342} inline constexpr charToUpper;
343
345{
346 char operator()(char c) const { return std::tolower(static_cast<unsigned char>(c)); }
347} inline constexpr charToLower;
348
349TC_COMMON_API void wstrToUpper(std::wstring& str);
350TC_COMMON_API void wstrToLower(std::wstring& str);
351TC_COMMON_API void strToUpper(std::string& str);
352TC_COMMON_API void strToLower(std::string& str);
353
354TC_COMMON_API std::wstring wstrCaseAccentInsensitiveParse(std::wstring_view wstr, LocaleConstant locale);
355
356TC_COMMON_API std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension);
357
358TC_COMMON_API bool utf8ToConsole(std::string_view utf8str, std::string& conStr);
359TC_COMMON_API bool consoleToUtf8(std::string_view conStr, std::string& utf8str);
360TC_COMMON_API bool Utf8FitTo(std::string_view str, std::wstring_view search);
361TC_COMMON_API void utf8printf(FILE* out, const char *str, ...);
362TC_COMMON_API void vutf8printf(FILE* out, const char *str, va_list* ap);
363TC_COMMON_API bool Utf8ToUpperOnlyLatin(std::string& utf8String);
364
365#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
366TC_COMMON_API bool ReadWinConsole(std::string& str, size_t size = 256);
367TC_COMMON_API bool WriteWinConsole(std::string_view str, bool error = false);
368#endif
369
371
372TC_COMMON_API bool IsIPAddress(char const* ipaddress);
373
374TC_COMMON_API uint32 CreatePIDFile(std::string const& filename);
376
377namespace Trinity::Impl
378{
379 TC_COMMON_API std::string ByteArrayToHexStr(uint8 const* bytes, size_t length, bool reverse = false);
380 TC_COMMON_API void HexStrToByteArray(std::string_view str, uint8* out, size_t outlen, bool reverse = false);
381}
382
383template <typename Container>
384std::string ByteArrayToHexStr(Container const& c, bool reverse = false)
385{
386 return Trinity::Impl::ByteArrayToHexStr(std::data(c), std::size(c), reverse);
387}
388
389template <size_t Size>
390void HexStrToByteArray(std::string_view str, std::array<uint8, Size>& buf, bool reverse = false)
391{
392 Trinity::Impl::HexStrToByteArray(str, buf.data(), Size, reverse);
393}
394template <size_t Size>
395std::array<uint8, Size> HexStrToByteArray(std::string_view str, bool reverse = false)
396{
397 std::array<uint8, Size> arr;
398 HexStrToByteArray(str, arr, reverse);
399 return arr;
400}
401
402inline std::vector<uint8> HexStrToByteVector(std::string_view str, bool reverse = false)
403{
404 std::vector<uint8> buf;
405 size_t const sz = (str.size() / 2);
406 buf.resize(sz);
407 Trinity::Impl::HexStrToByteArray(str, buf.data(), sz, reverse);
408 return buf;
409}
410
411TC_COMMON_API float DegToRad(float degrees);
412
413TC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2);
414inline bool StringStartsWith(std::string_view haystack, std::string_view needle) { return (haystack.substr(0, needle.length()) == needle); }
415inline bool StringStartsWithI(std::string_view haystack, std::string_view needle) { return StringEqualI(haystack.substr(0, needle.length()), needle); }
416TC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle);
417template <typename T>
418inline bool ValueContainsStringI(std::pair<T, std::string_view> const& haystack, std::string_view needle)
419{
420 return StringContainsStringI(haystack.second, needle);
421}
422TC_COMMON_API bool StringCompareLessI(std::string_view a, std::string_view b);
423
425{
426 bool operator()(std::string_view a, std::string_view b) const { return StringCompareLessI(a, b); }
427};
428
429// simple class for not-modifyable list
430template <typename T>
431class HookList final
432{
433 private:
434 typedef std::vector<T> ContainerType;
435
437
438 public:
439 typedef typename ContainerType::const_iterator const_iterator;
440 typedef typename ContainerType::iterator iterator;
441
443 {
444 _container.push_back(std::move(t));
445 return *this;
446 }
447
448 size_t size() const
449 {
450 return _container.size();
451 }
452
454 {
455 return _container.begin();
456 }
457
459 {
460 return _container.end();
461 }
462
464 {
465 return _container.begin();
466 }
467
469 {
470 return _container.end();
471 }
472};
473
475{
483
484template <class T>
485bool CompareValues(ComparisionType type, T val1, T val2)
486{
487 switch (type)
488 {
489 case COMP_TYPE_EQ:
490 return val1 == val2;
491 case COMP_TYPE_HIGH:
492 return val1 > val2;
493 case COMP_TYPE_LOW:
494 return val1 < val2;
496 return val1 >= val2;
497 case COMP_TYPE_LOW_EQ:
498 return val1 <= val2;
499 default:
500 // incorrect parameter
501 ABORT();
502 return false;
503 }
504}
505
506template<typename E>
507constexpr typename std::underlying_type<E>::type AsUnderlyingType(E enumValue)
508{
509 static_assert(std::is_enum<E>::value, "AsUnderlyingType can only be used with enums");
510 return static_cast<typename std::underlying_type<E>::type>(enumValue);
511}
512
513template<typename Ret, typename T1, typename... T>
514Ret* Coalesce(T1* first, T*... rest)
515{
516 if constexpr (sizeof...(T) > 0)
517 return (first ? static_cast<Ret*>(first) : Coalesce<Ret>(rest...));
518 else
519 return static_cast<Ret*>(first);
520}
521
522namespace Trinity
523{
524namespace Impl
525{
526 TC_COMMON_API std::string GetTypeName(std::type_info const&);
527}
528
529template <typename T>
530std::string GetTypeName() { return Impl::GetTypeName(typeid(T)); }
531template <typename T>
532std::string GetTypeName(T&& v)
533{
534 if constexpr (std::is_same_v<std::remove_cv_t<T>, std::type_info>)
535 return Impl::GetTypeName(v);
536 else
537 return Impl::GetTypeName(typeid(v));
538}
539}
540
541template<typename T>
543{
544 constexpr /*implicit*/ NonDefaultConstructible(T value) : Value(std::move(value))
545 {
546 }
547
549};
550
551#endif
LocaleConstant
Definition: Common.h:48
uint8_t uint8
Definition: Define.h:144
#define TC_COMMON_API
Definition: Define.h:99
uint64_t uint64
Definition: Define.h:141
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
#define ABORT
Definition: Errors.h:74
#define ASSERT
Definition: Errors.h:68
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
TC_COMMON_API Optional< int64 > MoneyStringToMoney(std::string const &moneyString)
Definition: Util.cpp:216
void HexStrToByteArray(std::string_view str, std::array< uint8, Size > &buf, bool reverse=false)
Definition: Util.h:390
TC_COMMON_API bool ReadWinConsole(std::string &str, size_t size=256)
Definition: Util.cpp:807
TC_COMMON_API std::wstring GetMainPartOfName(std::wstring const &wname, uint32 declension)
Definition: Util.cpp:669
bool isKoreanString(std::wstring_view wstr, bool numericOrSpace)
Definition: Util.h:237
TC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2)
Definition: Util.cpp:892
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:103
bool isCyrillicString(std::wstring_view wstr, bool numericOrSpace)
Definition: Util.h:229
TC_COMMON_API float DegToRad(float degrees)
Definition: Util.cpp:913
float GetPctOf(T value, T max)
Definition: Util.h:78
struct WcharToUpperOnlyLatin wcharToUpperOnlyLatin
bool isChineseCharacter(wchar_t wchar)
Definition: Util.h:176
bool isExtendedLatinCharacter(wchar_t wchar)
Definition: Util.h:133
TC_COMMON_API void wstrToLower(std::wstring &str)
Definition: Util.cpp:480
bool isKoreanCharacter(wchar_t wchar)
Definition: Util.h:163
TC_COMMON_API std::wstring wstrCaseAccentInsensitiveParse(std::wstring_view wstr, LocaleConstant locale)
Definition: Util.cpp:484
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:414
TC_COMMON_API void vutf8printf(FILE *out, const char *str, va_list *ap)
Definition: Util.cpp:774
T AddPct(T &base, U pct)
Definition: Util.h:85
std::string ByteArrayToHexStr(Container const &c, bool reverse=false)
Definition: Util.h:384
TimeFormat
Definition: Util.h:35
bool isChineseString(std::wstring_view wstr, bool numericOrSpace)
Definition: Util.h:245
bool CompareValues(ComparisionType type, T val1, T val2)
Definition: Util.h:485
bool isNumeric(wchar_t wchar)
Definition: Util.h:189
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:213
TC_COMMON_API uint32 GetPID()
Definition: Util.cpp:338
TC_COMMON_API void utf8printf(FILE *out, const char *str,...)
Definition: Util.cpp:766
Ret * Coalesce(T1 *first, T *... rest)
Definition: Util.h:514
std::vector< uint8 > HexStrToByteVector(std::string_view str, bool reverse=false)
Definition: Util.h:402
TC_COMMON_API std::string TimeToHumanReadable(time_t t)
Definition: Util.cpp:303
T RoundToInterval(T &num, T floor, T ceil)
Definition: Util.h:97
TC_COMMON_API Optional< std::size_t > RemoveCRLF(std::string &str)
Definition: Util.cpp:840
TC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle)
Definition: Util.cpp:897
TC_COMMON_API bool WriteWinConsole(std::string_view str, bool error=false)
Definition: Util.cpp:826
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:418
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:507
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:718
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:415
bool isLower(wchar_t wchar)
Definition: Util.h:321
bool isExtendedLatinString(std::wstring_view wstr, bool numericOrSpace)
Definition: Util.h:221
T ApplyPct(T &base, U pct)
Definition: Util.h:91
TC_COMMON_API void strToLower(std::string &str)
Definition: Util.cpp:482
TC_COMMON_API bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:795
TC_COMMON_API bool StringCompareLessI(std::string_view a, std::string_view b)
Definition: Util.cpp:903
struct CharToUpper charToUpper
T CalculatePct(T base, U pct)
Definition: Util.h:72
bool isCyrillicCharacter(wchar_t wchar)
Definition: Util.h:154
TC_COMMON_API bool Utf8FitTo(std::string_view str, std::wstring_view search)
Definition: Util.cpp:750
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:735
bool isNumericOrSpace(wchar_t wchar)
Definition: Util.h:208
struct WcharToUpper wcharToUpper
TC_COMMON_API size_t utf8length(std::string &utf8str)
Definition: Util.cpp:349
bool isUpper(wchar_t wchar)
Definition: Util.h:334
ComparisionType
Definition: Util.h:475
@ COMP_TYPE_LOW
Definition: Util.h:478
@ COMP_TYPE_MAX
Definition: Util.h:481
@ COMP_TYPE_HIGH
Definition: Util.h:477
@ COMP_TYPE_EQ
Definition: Util.h:476
@ COMP_TYPE_HIGH_EQ
Definition: Util.h:479
@ COMP_TYPE_LOW_EQ
Definition: Util.h:480
bool isBasicLatinCharacter(wchar_t wchar)
Definition: Util.h:124
Definition: Util.h:432
HookList< T > & operator+=(T &&t)
Definition: Util.h:442
iterator end()
Definition: Util.h:458
size_t size() const
Definition: Util.h:448
std::vector< T > ContainerType
Definition: Util.h:434
ContainerType::const_iterator const_iterator
Definition: Util.h:439
const_iterator end() const
Definition: Util.h:468
const_iterator begin() const
Definition: Util.h:463
ContainerType::iterator iterator
Definition: Util.h:440
ContainerType _container
Definition: Util.h:436
iterator begin()
Definition: Util.h:453
TC_COMMON_API void HexStrToByteArray(std::string_view str, uint8 *out, size_t outlen, bool reverse=false)
Definition: Util.cpp:872
TC_COMMON_API std::string ByteArrayToHexStr(uint8 const *bytes, size_t length, bool reverse=false)
Definition: Util.cpp:850
TC_COMMON_API std::string GetTypeName(std::type_info const &)
Definition: Util.cpp:908
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:530
bool Size(ContainerUnorderedMap< TypeList< H, T >, KEY_TYPE > const &elements, std::size_t *size, SPECIFIC_TYPE *obj)
constexpr std::size_t size()
Definition: UpdateField.h:805
STL namespace.
char operator()(char c) const
Definition: Util.h:346
char operator()(char c) const
Definition: Util.h:341
constexpr NonDefaultConstructible(T value)
Definition: Util.h:544
bool operator()(std::string_view a, std::string_view b) const
Definition: Util.h:426
wchar_t operator()(wchar_t wchar) const
Definition: Util.h:293
wchar_t operator()(wchar_t wchar) const
Definition: Util.h:285
wchar_t operator()(wchar_t wchar) const
Definition: Util.h:255