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 <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
102// UTF8 handling
103TC_COMMON_API bool Utf8toWStr(std::string_view utf8str, std::wstring& wstr);
104
105// in wsize==max size of buffer, out wsize==real string size
106TC_COMMON_API bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize);
107
108inline bool Utf8toWStr(std::string_view utf8str, wchar_t* wstr, size_t& wsize)
109{
110 return Utf8toWStr(utf8str.data(), utf8str.size(), wstr, wsize);
111}
112
113TC_COMMON_API bool WStrToUtf8(std::wstring_view wstr, std::string& utf8str);
114// size==real string size
115TC_COMMON_API bool WStrToUtf8(wchar_t const* wstr, size_t size, std::string& utf8str);
116
117// set string to "" if invalid utf8 sequence
118TC_COMMON_API size_t utf8length(std::string& utf8str);
119TC_COMMON_API void utf8truncate(std::string& utf8str, size_t len);
120
121inline bool isBasicLatinCharacter(wchar_t wchar)
122{
123 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
124 return true;
125 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
126 return true;
127 return false;
128}
129
130inline bool isExtendedLatinCharacter(wchar_t wchar)
131{
132 if (isBasicLatinCharacter(wchar))
133 return true;
134 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
135 return true;
136 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
137 return true;
138 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
139 return true;
140 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
141 return true;
142 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
143 return true;
144 if (wchar >= 0x0100 && wchar <= 0x012F) // LATIN CAPITAL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK
145 return true;
146 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
147 return true;
148 return false;
149}
150
151inline bool isLatin1Character(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 <= 0x00DD) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER Y WITH ACUTE
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 <= 0x00FD) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER Y WITH ACUTE
164 return true;
165 if (wchar == 0x00FF) // LATIN SMALL LETTER Y WITH DIAERESIS
166 return true;
167 if (wchar == 0x0178) // LATIN CAPITAL LETTER Y WITH DIAERESIS
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 isKoreanCharacter(wchar_t wchar)
182{
183 if (wchar >= 0x1100 && wchar <= 0x11F9) // Hangul Jamo
184 return true;
185 if (wchar >= 0x3131 && wchar <= 0x318E) // Hangul Compatibility Jamo
186 return true;
187 if (wchar >= 0xAC00 && wchar <= 0xD7A3) // Hangul Syllables
188 return true;
189 if (wchar >= 0xFF01 && wchar <= 0xFFEE) // Halfwidth forms
190 return true;
191 return false;
192}
193
194inline bool isChineseCharacter(wchar_t wchar)
195{
196 if (wchar >= 0x4E00 && wchar <= 0x9FFF) // Unified CJK Ideographs
197 return true;
198 if (wchar >= 0x3400 && wchar <= 0x4DBF) // CJK Ideographs Ext. A
199 return true;
200 if (wchar >= 0x3100 && wchar <= 0x312C) // Bopomofo
201 return true;
202 if (wchar >= 0xF900 && wchar <= 0xFAFF) // CJK Compatibility Ideographs
203 return true;
204 return false;
205}
206
207inline bool isNumeric(wchar_t wchar)
208{
209 return (wchar >= L'0' && wchar <=L'9');
210}
211
212inline bool isNumeric(char c)
213{
214 return (c >= '0' && c <='9');
215}
216
217inline bool isNumeric(char const* str)
218{
219 for (char const* c = str; *c; ++c)
220 if (!isNumeric(*c))
221 return false;
222
223 return true;
224}
225
226inline bool isNumericOrSpace(wchar_t wchar)
227{
228 return isNumeric(wchar) || wchar == L' ';
229}
230
231inline bool isBasicLatinString(std::wstring_view wstr, bool numericOrSpace)
232{
233 for (wchar_t c : wstr)
234 if (!isBasicLatinCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
235 return false;
236 return true;
237}
238
239inline bool isExtendedLatinString(std::wstring_view wstr, bool numericOrSpace)
240{
241 for (wchar_t c : wstr)
242 if (!isExtendedLatinCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
243 return false;
244 return true;
245}
246
247inline bool isCyrillicString(std::wstring_view wstr, bool numericOrSpace)
248{
249 for (wchar_t c : wstr)
250 if (!isCyrillicCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
251 return false;
252 return true;
253}
254
255inline bool isKoreanString(std::wstring_view wstr, bool numericOrSpace)
256{
257 for (wchar_t c : wstr)
258 if (!isKoreanCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
259 return false;
260 return true;
261}
262
263inline bool isChineseString(std::wstring_view wstr, bool numericOrSpace)
264{
265 for (wchar_t c : wstr)
266 if (!isChineseCharacter(c) && (!numericOrSpace || !isNumericOrSpace(c)))
267 return false;
268 return true;
269}
270
272{
273 wchar_t operator()(wchar_t wchar) const
274 {
275 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
276 return wchar_t(uint16(wchar) - 0x0020);
277 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
278 return wchar_t(0x1E9E);
279 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
280 return wchar_t(uint16(wchar) - 0x0020);
281 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
282 return wchar_t(uint16(wchar) - 0x0020);
283 if (wchar >= 0x0101 && wchar <= 0x012F) // LATIN SMALL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK (only %2=1)
284 {
285 if (wchar % 2 == 1)
286 return wchar_t(uint16(wchar) - 0x0001);
287 }
288 if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
289 return wchar_t(uint16(wchar) - 0x0020);
290 if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
291 return wchar_t(0x0401);
292 if (wchar == 0x0153) // LATIN SMALL LIGATURE OE
293 return wchar_t(0x0152);
294 if (wchar == 0x00FF) // LATIN SMALL LETTER Y WITH DIAERESIS
295 return wchar_t(0x0178);
296
297 return wchar;
298 }
299} inline constexpr wcharToUpper;
300
302{
303 wchar_t operator()(wchar_t wchar) const
304 {
305 return isBasicLatinCharacter(wchar) ? wcharToUpper(wchar) : wchar;
306 }
307} inline constexpr wcharToUpperOnlyLatin;
308
310{
311 wchar_t operator()(wchar_t wchar) const
312 {
313 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
314 return wchar_t(uint16(wchar)+0x0020);
315 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
316 return wchar_t(uint16(wchar)+0x0020);
317 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
318 return wchar_t(uint16(wchar)+0x0020);
319 if (wchar >= 0x0100 && wchar <= 0x012E) // LATIN CAPITAL LETTER A WITH MACRON - LATIN CAPITAL LETTER I WITH OGONEK (only %2=0)
320 {
321 if (wchar % 2 == 0)
322 return wchar_t(uint16(wchar)+0x0001);
323 }
324 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
325 return wchar_t(0x00DF);
326 if (wchar == 0x0401) // CYRILLIC CAPITAL LETTER IO
327 return wchar_t(0x0451);
328 if (wchar == 0x0152) // LATIN CAPITAL LIGATURE OE
329 return wchar_t(0x0153);
330 if (wchar == 0x0178) // LATIN CAPITAL LETTER Y WITH DIAERESIS
331 return wchar_t(0x00FF);
332 if (wchar >= 0x0410 && wchar <= 0x042F) // CYRILLIC CAPITAL LETTER A - CYRILLIC CAPITAL LETTER YA
333 return wchar_t(uint16(wchar)+0x0020);
334
335 return wchar;
336 }
337} inline constexpr wcharToLower;
338
339inline bool isLower(wchar_t wchar)
340{
341 if (wchar >= L'a' && wchar <= L'z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
342 return true;
343 if (wchar >= 0x00E0 && wchar <= 0x00FF) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER Y WITH DIAERESIS
344 return true;
345 if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
346 return true;
347 if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
348 return true;
349 return false;
350}
351
352inline bool isUpper(wchar_t wchar)
353{
354 return !isLower(wchar);
355}
356
358{
359 char operator()(char c) const { return std::toupper(static_cast<unsigned char>(c)); }
360} inline constexpr charToUpper;
361
363{
364 char operator()(char c) const { return std::tolower(static_cast<unsigned char>(c)); }
365} inline constexpr charToLower;
366
367TC_COMMON_API void wstrToUpper(std::wstring& str);
368TC_COMMON_API void wstrToLower(std::wstring& str);
369TC_COMMON_API void strToUpper(std::string& str);
370TC_COMMON_API void strToLower(std::string& str);
371
375template <typename Iterator>
377{
378 Iterator End;
379 constexpr bool operator==(Iterator itr) const;
380};
381
386{
387 template <typename Iterator>
388 inline constexpr bool operator==(Iterator itr) const { return *itr == static_cast<std::iter_value_t<Iterator>>(0); }
389
393 template <typename Iterator>
394 inline constexpr CStringBoundedSentinel<Iterator> Checked(Iterator end) const { return { .End = end }; }
395} inline constexpr CStringSentinel;
396
397template <typename Iterator>
398inline constexpr bool CStringBoundedSentinel<Iterator>::operator==(Iterator itr) const
399{
400 return itr == End || itr == CStringSentinel;
401}
402
403TC_COMMON_API std::wstring wstrCaseAccentInsensitiveParse(std::wstring_view wstr, LocaleConstant locale);
404
405TC_COMMON_API std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension);
406
407TC_COMMON_API bool utf8ToConsole(std::string_view utf8str, std::string& conStr);
408TC_COMMON_API bool consoleToUtf8(std::string_view conStr, std::string& utf8str);
409TC_COMMON_API bool Utf8FitTo(std::string_view str, std::wstring_view search);
410TC_COMMON_API void utf8printf(FILE* out, const char *str, ...);
411TC_COMMON_API void vutf8printf(FILE* out, const char *str, va_list* ap);
412TC_COMMON_API bool Utf8ToUpperOnlyLatin(std::string& utf8String);
413
414#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
415TC_COMMON_API bool ReadWinConsole(std::string& str, size_t size = 256);
416TC_COMMON_API bool WriteWinConsole(std::string_view str, bool error = false);
417#endif
418
420
421TC_COMMON_API uint32 CreatePIDFile(std::string const& filename);
423
424namespace Trinity::Impl
425{
426 TC_COMMON_API std::string ByteArrayToHexStr(uint8 const* bytes, size_t length, bool reverse = false);
427 TC_COMMON_API void HexStrToByteArray(std::string_view str, uint8* out, size_t outlen, bool reverse = false);
428}
429
430template <typename Container>
431std::string ByteArrayToHexStr(Container const& c, bool reverse = false)
432{
433 return Trinity::Impl::ByteArrayToHexStr(std::data(c), std::size(c), reverse);
434}
435
436template <size_t Size>
437void HexStrToByteArray(std::string_view str, std::array<uint8, Size>& buf, bool reverse = false)
438{
439 Trinity::Impl::HexStrToByteArray(str, buf.data(), Size, reverse);
440}
441template <size_t Size>
442std::array<uint8, Size> HexStrToByteArray(std::string_view str, bool reverse = false)
443{
444 std::array<uint8, Size> arr;
445 HexStrToByteArray(str, arr, reverse);
446 return arr;
447}
448
449inline std::vector<uint8> HexStrToByteVector(std::string_view str, bool reverse = false)
450{
451 std::vector<uint8> buf;
452 size_t const sz = (str.size() / 2);
453 buf.resize(sz);
454 Trinity::Impl::HexStrToByteArray(str, buf.data(), sz, reverse);
455 return buf;
456}
457
458TC_COMMON_API float DegToRad(float degrees);
459
460TC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2);
461inline bool StringStartsWith(std::string_view haystack, std::string_view needle) { return haystack.starts_with(needle); }
462inline bool StringStartsWithI(std::string_view haystack, std::string_view needle) { return StringEqualI(haystack.substr(0, needle.length()), needle); }
463
464TC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle);
465
467{
468 bool operator()(std::string_view haystack, std::string_view needle) const { return StringContainsStringI(haystack, needle); }
469};
470
471TC_COMMON_API bool StringCompareLessI(std::string_view a, std::string_view b);
472
474{
475 bool operator()(std::string_view a, std::string_view b) const { return StringCompareLessI(a, b); }
476};
477
478TC_COMMON_API void StringReplaceAll(std::string* str, std::string_view text, std::string_view replacement);
479
480[[nodiscard]] inline std::string StringReplaceAll(std::string_view str, std::string_view text, std::string_view replacement)
481{
482 std::string result(str);
483 StringReplaceAll(&result, text, replacement);
484 return result;
485}
486
487// simple class for not-modifyable list
488template <typename T>
490{
491 private:
492 typedef std::vector<T> ContainerType;
493
495
496 public:
497 typedef typename ContainerType::const_iterator const_iterator;
498 typedef typename ContainerType::iterator iterator;
499
501 {
502 _container.emplace_back(std::move(t));
503 return *this;
504 }
505
506 size_t size() const
507 {
508 return _container.size();
509 }
510
512 {
513 return _container.begin();
514 }
515
517 {
518 return _container.end();
519 }
520
522 {
523 return _container.begin();
524 }
525
527 {
528 return _container.end();
529 }
530};
531
541
542template <class T>
543bool CompareValues(ComparisionType type, T val1, T val2)
544{
545 switch (type)
546 {
547 case COMP_TYPE_EQ:
548 return val1 == val2;
549 case COMP_TYPE_HIGH:
550 return val1 > val2;
551 case COMP_TYPE_LOW:
552 return val1 < val2;
554 return val1 >= val2;
555 case COMP_TYPE_LOW_EQ:
556 return val1 <= val2;
557 default:
558 // incorrect parameter
559 ABORT();
560 return false;
561 }
562}
563
564template<typename E>
565constexpr typename std::underlying_type<E>::type AsUnderlyingType(E enumValue)
566{
567 static_assert(std::is_enum<E>::value, "AsUnderlyingType can only be used with enums");
568 return static_cast<typename std::underlying_type<E>::type>(enumValue);
569}
570
571template<typename Ret, typename T1, typename... T>
572constexpr Ret* Coalesce(T1* first, T*... rest)
573{
574 if constexpr (sizeof...(T) > 0)
575 return (first ? static_cast<Ret*>(first) : Coalesce<Ret>(rest...));
576 else
577 return static_cast<Ret*>(first);
578}
579
580namespace Trinity
581{
582namespace Impl
583{
584 TC_COMMON_API std::string GetTypeName(std::type_info const&);
585}
586
587template <typename T>
588std::string GetTypeName() { return Impl::GetTypeName(typeid(T)); }
589template <typename T>
590std::string GetTypeName(T&& v)
591{
592 if constexpr (std::is_same_v<std::remove_cvref_t<T>, std::type_info>)
593 return Impl::GetTypeName(v);
594 else
595 return Impl::GetTypeName(typeid(v));
596}
597}
598
599template<typename T>
601{
602 constexpr /*implicit*/ NonDefaultConstructible(T value) : Value(std::move(value))
603 {
604 }
605
607};
608
609#endif
LocaleConstant
Definition Common.h:51
uint8_t uint8
Definition Define.h:156
#define TC_COMMON_API
Definition Define.h:99
uint64_t uint64
Definition Define.h:153
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
#define ABORT
Definition Errors.h:87
#define ASSERT
Definition Errors.h:80
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:180
void HexStrToByteArray(std::string_view str, std::array< uint8, Size > &buf, bool reverse=false)
Definition Util.h:437
TC_COMMON_API bool ReadWinConsole(std::string &str, size_t size=256)
Definition Util.cpp:764
TC_COMMON_API std::wstring GetMainPartOfName(std::wstring const &wname, uint32 declension)
Definition Util.cpp:622
bool isKoreanString(std::wstring_view wstr, bool numericOrSpace)
Definition Util.h:255
TC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2)
Definition Util.cpp:849
bool isCyrillicString(std::wstring_view wstr, bool numericOrSpace)
Definition Util.h:247
TC_COMMON_API float DegToRad(float degrees)
Definition Util.cpp:880
float GetPctOf(T value, T max)
Definition Util.h:78
struct WcharToUpperOnlyLatin wcharToUpperOnlyLatin
constexpr Ret * Coalesce(T1 *first, T *... rest)
Definition Util.h:572
bool isChineseCharacter(wchar_t wchar)
Definition Util.h:194
bool isExtendedLatinCharacter(wchar_t wchar)
Definition Util.h:130
TC_COMMON_API void wstrToLower(std::wstring &str)
Definition Util.cpp:433
bool isKoreanCharacter(wchar_t wchar)
Definition Util.h:181
TC_COMMON_API std::wstring wstrCaseAccentInsensitiveParse(std::wstring_view wstr, LocaleConstant locale)
Definition Util.cpp:437
TC_COMMON_API void utf8truncate(std::string &utf8str, size_t len)
Definition Util.cpp:315
bool StringStartsWith(std::string_view haystack, std::string_view needle)
Definition Util.h:461
TC_COMMON_API void vutf8printf(FILE *out, const char *str, va_list *ap)
Definition Util.cpp:731
T AddPct(T &base, U pct)
Definition Util.h:85
std::string ByteArrayToHexStr(Container const &c, bool reverse=false)
Definition Util.h:431
TimeFormat
Definition Util.h:35
bool isChineseString(std::wstring_view wstr, bool numericOrSpace)
Definition Util.h:263
bool CompareValues(ComparisionType type, T val1, T val2)
Definition Util.h:543
bool isNumeric(wchar_t wchar)
Definition Util.h:207
TC_COMMON_API bool Utf8toWStr(std::string_view utf8str, std::wstring &wstr)
Definition Util.cpp:370
bool isBasicLatinString(std::wstring_view wstr, bool numericOrSpace)
Definition Util.h:231
TC_COMMON_API uint32 GetPID()
Definition Util.cpp:291
TC_COMMON_API void utf8printf(FILE *out, const char *str,...)
Definition Util.cpp:723
std::vector< uint8 > HexStrToByteVector(std::string_view str, bool reverse=false)
Definition Util.h:449
TC_COMMON_API std::string TimeToHumanReadable(time_t t)
Definition Util.cpp:267
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:797
TC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle)
Definition Util.cpp:854
TC_COMMON_API void StringReplaceAll(std::string *str, std::string_view text, std::string_view replacement)
Definition Util.cpp:865
TC_COMMON_API bool WriteWinConsole(std::string_view str, bool error=false)
Definition Util.cpp:783
TC_COMMON_API std::string TimeToTimestampStr(time_t t)
Definition Util.cpp:254
TC_COMMON_API time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime=true)
Definition Util.cpp:101
TC_COMMON_API bool WStrToUtf8(std::wstring_view wstr, std::string &utf8str)
Definition Util.cpp:409
struct WcharToLower wcharToLower
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition Util.h:565
TC_COMMON_API tm TimeBreakdown(time_t t)
Definition Util.cpp:94
TC_COMMON_API uint32 TimeStringToSecs(std::string const &timestring)
Definition Util.cpp:222
TC_COMMON_API bool utf8ToConsole(std::string_view utf8str, std::string &conStr)
Definition Util.cpp:675
TC_COMMON_API std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat=TimeFormat::FullText, bool hoursOnly=false)
Definition Util.cpp:116
TC_COMMON_API uint32 CreatePIDFile(std::string const &filename)
create PID file
Definition Util.cpp:277
bool isLatin1Character(wchar_t wchar)
Definition Util.h:151
TC_COMMON_API void strToUpper(std::string &str)
Definition Util.cpp:434
bool StringStartsWithI(std::string_view haystack, std::string_view needle)
Definition Util.h:462
bool isLower(wchar_t wchar)
Definition Util.h:339
bool isExtendedLatinString(std::wstring_view wstr, bool numericOrSpace)
Definition Util.h:239
T ApplyPct(T &base, U pct)
Definition Util.h:91
TC_COMMON_API void strToLower(std::string &str)
Definition Util.cpp:435
TC_COMMON_API bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition Util.cpp:752
TC_COMMON_API bool StringCompareLessI(std::string_view a, std::string_view b)
Definition Util.cpp:860
struct CStringSentinel_T CStringSentinel
struct CharToUpper charToUpper
T CalculatePct(T base, U pct)
Definition Util.h:72
bool isCyrillicCharacter(wchar_t wchar)
Definition Util.h:172
TC_COMMON_API bool Utf8FitTo(std::string_view str, std::wstring_view search)
Definition Util.cpp:707
struct CharToLower charToLower
TC_COMMON_API void wstrToUpper(std::wstring &str)
Definition Util.cpp:432
TC_COMMON_API bool consoleToUtf8(std::string_view conStr, std::string &utf8str)
Definition Util.cpp:692
bool isNumericOrSpace(wchar_t wchar)
Definition Util.h:226
struct WcharToUpper wcharToUpper
TC_COMMON_API size_t utf8length(std::string &utf8str)
Definition Util.cpp:302
bool isUpper(wchar_t wchar)
Definition Util.h:352
ComparisionType
Definition Util.h:533
@ COMP_TYPE_LOW
Definition Util.h:536
@ COMP_TYPE_MAX
Definition Util.h:539
@ COMP_TYPE_HIGH
Definition Util.h:535
@ COMP_TYPE_EQ
Definition Util.h:534
@ COMP_TYPE_HIGH_EQ
Definition Util.h:537
@ COMP_TYPE_LOW_EQ
Definition Util.h:538
bool isBasicLatinCharacter(wchar_t wchar)
Definition Util.h:121
HookList< T > & operator+=(T &&t)
Definition Util.h:500
iterator end()
Definition Util.h:516
size_t size() const
Definition Util.h:506
std::vector< T > ContainerType
Definition Util.h:492
ContainerType::const_iterator const_iterator
Definition Util.h:497
const_iterator end() const
Definition Util.h:526
const_iterator begin() const
Definition Util.h:521
ContainerType::iterator iterator
Definition Util.h:498
ContainerType _container
Definition Util.h:494
iterator begin()
Definition Util.h:511
TC_COMMON_API void HexStrToByteArray(std::string_view str, uint8 *out, size_t outlen, bool reverse=false)
Definition Util.cpp:829
TC_COMMON_API std::string ByteArrayToHexStr(uint8 const *bytes, size_t length, bool reverse=false)
Definition Util.cpp:807
TC_COMMON_API std::string GetTypeName(std::type_info const &)
Definition Util.cpp:875
TC_COMMON_API void VerifyOsVersion()
Definition Util.cpp:35
TC_COMMON_API std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition Util.cpp:57
std::string GetTypeName()
Definition Util.h:588
STL namespace.
constexpr bool operator==(Iterator itr) const
Definition Util.h:398
constexpr bool operator==(Iterator itr) const
Definition Util.h:388
constexpr CStringBoundedSentinel< Iterator > Checked(Iterator end) const
Definition Util.h:394
char operator()(char c) const
Definition Util.h:364
char operator()(char c) const
Definition Util.h:359
constexpr NonDefaultConstructible(T value)
Definition Util.h:602
bool operator()(std::string_view a, std::string_view b) const
Definition Util.h:475
bool operator()(std::string_view haystack, std::string_view needle) const
Definition Util.h:468
wchar_t operator()(wchar_t wchar) const
Definition Util.h:311
wchar_t operator()(wchar_t wchar) const
Definition Util.h:303
wchar_t operator()(wchar_t wchar) const
Definition Util.h:273