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
253inline wchar_t wcharToUpper(wchar_t wchar)
254{
255 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
256 return wchar_t(uint16(wchar)-0x0020);
257 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
258 return wchar_t(0x1E9E);
259 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
260 return wchar_t(uint16(wchar)-0x0020);
261 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
262 return wchar_t(uint16(wchar)-0x0020);
263 if (wchar >= 0x0101 && wchar <= 0x012F) // LATIN SMALL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK (only %2=1)
264 {
265 if (wchar % 2 == 1)
266 return wchar_t(uint16(wchar)-0x0001);
267 }
268 if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
269 return wchar_t(uint16(wchar)-0x0020);
270 if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
271 return wchar_t(0x0401);
272 if (wchar == 0x0153) // LATIN SMALL LIGATURE OE
273 return wchar_t(0x0152);
274 if (wchar == 0x00FF) // LATIN SMALL LETTER Y WITH DIAERESIS
275 return wchar_t(0x0178);
276
277 return wchar;
278}
279
280inline wchar_t wcharToUpperOnlyLatin(wchar_t wchar)
281{
282 return isBasicLatinCharacter(wchar) ? wcharToUpper(wchar) : wchar;
283}
284
285inline wchar_t wcharToLower(wchar_t wchar)
286{
287 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
288 return wchar_t(uint16(wchar)+0x0020);
289 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
290 return wchar_t(uint16(wchar)+0x0020);
291 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
292 return wchar_t(uint16(wchar)+0x0020);
293 if (wchar >= 0x0100 && wchar <= 0x012E) // LATIN CAPITAL LETTER A WITH MACRON - LATIN CAPITAL LETTER I WITH OGONEK (only %2=0)
294 {
295 if (wchar % 2 == 0)
296 return wchar_t(uint16(wchar)+0x0001);
297 }
298 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
299 return wchar_t(0x00DF);
300 if (wchar == 0x0401) // CYRILLIC CAPITAL LETTER IO
301 return wchar_t(0x0451);
302 if (wchar == 0x0152) // LATIN CAPITAL LIGATURE OE
303 return wchar_t(0x0153);
304 if (wchar == 0x0178) // LATIN CAPITAL LETTER Y WITH DIAERESIS
305 return wchar_t(0x00FF);
306 if (wchar >= 0x0410 && wchar <= 0x042F) // CYRILLIC CAPITAL LETTER A - CYRILLIC CAPITAL LETTER YA
307 return wchar_t(uint16(wchar)+0x0020);
308
309 return wchar;
310}
311
312inline bool isLower(wchar_t wchar)
313{
314 if (wchar >= L'a' && wchar <= L'z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
315 return true;
316 if (wchar >= 0x00E0 && wchar <= 0x00FF) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER Y WITH DIAERESIS
317 return true;
318 if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
319 return true;
320 if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
321 return true;
322 return false;
323}
324
325inline bool isUpper(wchar_t wchar)
326{
327 return !isLower(wchar);
328}
329
330inline char charToUpper(char c) { return std::toupper(c); }
331inline char charToLower(char c) { return std::tolower(c); }
332
333TC_COMMON_API void wstrToUpper(std::wstring& str);
334TC_COMMON_API void wstrToLower(std::wstring& str);
335TC_COMMON_API void strToUpper(std::string& str);
336TC_COMMON_API void strToLower(std::string& str);
337
338TC_COMMON_API std::wstring wstrCaseAccentInsensitiveParse(std::wstring_view wstr, LocaleConstant locale);
339
340TC_COMMON_API std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension);
341
342TC_COMMON_API bool utf8ToConsole(std::string_view utf8str, std::string& conStr);
343TC_COMMON_API bool consoleToUtf8(std::string_view conStr, std::string& utf8str);
344TC_COMMON_API bool Utf8FitTo(std::string_view str, std::wstring_view search);
345TC_COMMON_API void utf8printf(FILE* out, const char *str, ...);
346TC_COMMON_API void vutf8printf(FILE* out, const char *str, va_list* ap);
347TC_COMMON_API bool Utf8ToUpperOnlyLatin(std::string& utf8String);
348
349#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
350TC_COMMON_API bool ReadWinConsole(std::string& str, size_t size = 256);
351TC_COMMON_API bool WriteWinConsole(std::string_view str, bool error = false);
352#endif
353
355
356TC_COMMON_API bool IsIPAddress(char const* ipaddress);
357
358TC_COMMON_API uint32 CreatePIDFile(std::string const& filename);
360
361namespace Trinity::Impl
362{
363 TC_COMMON_API std::string ByteArrayToHexStr(uint8 const* bytes, size_t length, bool reverse = false);
364 TC_COMMON_API void HexStrToByteArray(std::string_view str, uint8* out, size_t outlen, bool reverse = false);
365}
366
367template <typename Container>
368std::string ByteArrayToHexStr(Container const& c, bool reverse = false)
369{
370 return Trinity::Impl::ByteArrayToHexStr(std::data(c), std::size(c), reverse);
371}
372
373template <size_t Size>
374void HexStrToByteArray(std::string_view str, std::array<uint8, Size>& buf, bool reverse = false)
375{
376 Trinity::Impl::HexStrToByteArray(str, buf.data(), Size, reverse);
377}
378template <size_t Size>
379std::array<uint8, Size> HexStrToByteArray(std::string_view str, bool reverse = false)
380{
381 std::array<uint8, Size> arr;
382 HexStrToByteArray(str, arr, reverse);
383 return arr;
384}
385
386inline std::vector<uint8> HexStrToByteVector(std::string_view str, bool reverse = false)
387{
388 std::vector<uint8> buf;
389 size_t const sz = (str.size() / 2);
390 buf.resize(sz);
391 Trinity::Impl::HexStrToByteArray(str, buf.data(), sz, reverse);
392 return buf;
393}
394
395TC_COMMON_API float DegToRad(float degrees);
396
397TC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2);
398inline bool StringStartsWith(std::string_view haystack, std::string_view needle) { return (haystack.substr(0, needle.length()) == needle); }
399inline bool StringStartsWithI(std::string_view haystack, std::string_view needle) { return StringEqualI(haystack.substr(0, needle.length()), needle); }
400TC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle);
401template <typename T>
402inline bool ValueContainsStringI(std::pair<T, std::string_view> const& haystack, std::string_view needle)
403{
404 return StringContainsStringI(haystack.second, needle);
405}
406TC_COMMON_API bool StringCompareLessI(std::string_view a, std::string_view b);
407
409{
410 bool operator()(std::string_view a, std::string_view b) const { return StringCompareLessI(a, b); }
411};
412
413// simple class for not-modifyable list
414template <typename T>
415class HookList final
416{
417 private:
418 typedef std::vector<T> ContainerType;
419
421
422 public:
423 typedef typename ContainerType::const_iterator const_iterator;
424 typedef typename ContainerType::iterator iterator;
425
427 {
428 _container.push_back(std::move(t));
429 return *this;
430 }
431
432 size_t size() const
433 {
434 return _container.size();
435 }
436
438 {
439 return _container.begin();
440 }
441
443 {
444 return _container.end();
445 }
446
448 {
449 return _container.begin();
450 }
451
453 {
454 return _container.end();
455 }
456};
457
459{
467
468template <class T>
469bool CompareValues(ComparisionType type, T val1, T val2)
470{
471 switch (type)
472 {
473 case COMP_TYPE_EQ:
474 return val1 == val2;
475 case COMP_TYPE_HIGH:
476 return val1 > val2;
477 case COMP_TYPE_LOW:
478 return val1 < val2;
480 return val1 >= val2;
481 case COMP_TYPE_LOW_EQ:
482 return val1 <= val2;
483 default:
484 // incorrect parameter
485 ABORT();
486 return false;
487 }
488}
489
490template<typename E>
491constexpr typename std::underlying_type<E>::type AsUnderlyingType(E enumValue)
492{
493 static_assert(std::is_enum<E>::value, "AsUnderlyingType can only be used with enums");
494 return static_cast<typename std::underlying_type<E>::type>(enumValue);
495}
496
497template<typename Ret, typename T1, typename... T>
498Ret* Coalesce(T1* first, T*... rest)
499{
500 if constexpr (sizeof...(T) > 0)
501 return (first ? static_cast<Ret*>(first) : Coalesce<Ret>(rest...));
502 else
503 return static_cast<Ret*>(first);
504}
505
506namespace Trinity
507{
508namespace Impl
509{
510 TC_COMMON_API std::string GetTypeName(std::type_info const&);
511}
512
513template <typename T>
514std::string GetTypeName() { return Impl::GetTypeName(typeid(T)); }
515template <typename T>
516std::string GetTypeName(T&& v)
517{
518 if constexpr (std::is_same_v<std::remove_cv_t<T>, std::type_info>)
519 return Impl::GetTypeName(v);
520 else
521 return Impl::GetTypeName(typeid(v));
522}
523}
524
525template<typename T>
527{
528 constexpr /*implicit*/ NonDefaultConstructible(T value) : Value(std::move(value))
529 {
530 }
531
533};
534
535#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:374
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:891
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
wchar_t wcharToLower(wchar_t wchar)
Definition: Util.h:285
bool isCyrillicString(std::wstring_view wstr, bool numericOrSpace)
Definition: Util.h:229
TC_COMMON_API float DegToRad(float degrees)
Definition: Util.cpp:912
float GetPctOf(T value, T max)
Definition: Util.h:78
bool isChineseCharacter(wchar_t wchar)
Definition: Util.h:176
wchar_t wcharToUpperOnlyLatin(wchar_t wchar)
Definition: Util.h:280
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:398
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:368
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:469
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:498
std::vector< uint8 > HexStrToByteVector(std::string_view str, bool reverse=false)
Definition: Util.h:386
TC_COMMON_API std::string TimeToHumanReadable(time_t t)
Definition: Util.cpp:303
wchar_t wcharToUpper(wchar_t wchar)
Definition: Util.h:253
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:839
TC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle)
Definition: Util.cpp:896
TC_COMMON_API bool WriteWinConsole(std::string_view str, bool error=false)
Definition: Util.cpp:826
char charToLower(char c)
Definition: Util.h:331
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:402
TC_COMMON_API bool WStrToUtf8(std::wstring_view wstr, std::string &utf8str)
Definition: Util.cpp:456
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:491
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:399
char charToUpper(char c)
Definition: Util.h:330
bool isLower(wchar_t wchar)
Definition: Util.h:312
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:902
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
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
TC_COMMON_API size_t utf8length(std::string &utf8str)
Definition: Util.cpp:349
bool isUpper(wchar_t wchar)
Definition: Util.h:325
ComparisionType
Definition: Util.h:459
@ COMP_TYPE_LOW
Definition: Util.h:462
@ COMP_TYPE_MAX
Definition: Util.h:465
@ COMP_TYPE_HIGH
Definition: Util.h:461
@ COMP_TYPE_EQ
Definition: Util.h:460
@ COMP_TYPE_HIGH_EQ
Definition: Util.h:463
@ COMP_TYPE_LOW_EQ
Definition: Util.h:464
bool isBasicLatinCharacter(wchar_t wchar)
Definition: Util.h:124
Definition: Util.h:416
HookList< T > & operator+=(T &&t)
Definition: Util.h:426
iterator end()
Definition: Util.h:442
size_t size() const
Definition: Util.h:432
std::vector< T > ContainerType
Definition: Util.h:418
ContainerType::const_iterator const_iterator
Definition: Util.h:423
const_iterator end() const
Definition: Util.h:452
const_iterator begin() const
Definition: Util.h:447
ContainerType::iterator iterator
Definition: Util.h:424
ContainerType _container
Definition: Util.h:420
iterator begin()
Definition: Util.h:437
TC_COMMON_API void HexStrToByteArray(std::string_view str, uint8 *out, size_t outlen, bool reverse=false)
Definition: Util.cpp:871
TC_COMMON_API std::string ByteArrayToHexStr(uint8 const *bytes, size_t length, bool reverse=false)
Definition: Util.cpp:849
TC_COMMON_API std::string GetTypeName(std::type_info const &)
Definition: Util.cpp:907
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:514
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:796
STL namespace.
constexpr NonDefaultConstructible(T value)
Definition: Util.h:528
bool operator()(std::string_view a, std::string_view b) const
Definition: Util.h:410