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;
52 inline std::vector<std::string_view>
Tokenize(
char const* str,
char sep,
bool keepEmpty) {
return Tokenize(std::string_view(str ? str :
""), sep, keepEmpty); }
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);
71template <
class T,
class U>
74 return T(base *
static_cast<float>(pct) / 100.0f);
81 return float(
static_cast<float>(value) /
static_cast<float>(max) * 100.0f);
84template <
class T,
class U>
90template <
class T,
class U>
99 return num = std::min(std::max(num, floor), ceil);
111inline bool Utf8toWStr(std::string_view utf8str,
wchar_t* wstr,
size_t& wsize)
113 return Utf8toWStr(utf8str.data(), utf8str.size(), wstr, wsize);
126 if (wchar >= L
'a' && wchar <= L
'z')
128 if (wchar >= L
'A' && wchar <= L
'Z')
137 if (wchar >= 0x00C0 && wchar <= 0x00D6)
139 if (wchar >= 0x00D8 && wchar <= 0x00DE)
143 if (wchar >= 0x00E0 && wchar <= 0x00F6)
145 if (wchar >= 0x00F8 && wchar <= 0x00FE)
147 if (wchar >= 0x0100 && wchar <= 0x012F)
156 if (wchar >= 0x0410 && wchar <= 0x044F)
158 if (wchar == 0x0401 || wchar == 0x0451)
165 if (wchar >= 0x1100 && wchar <= 0x11F9)
167 if (wchar >= 0x3131 && wchar <= 0x318E)
169 if (wchar >= 0xAC00 && wchar <= 0xD7A3)
171 if (wchar >= 0xFF01 && wchar <= 0xFFEE)
178 if (wchar >= 0x4E00 && wchar <= 0x9FFF)
180 if (wchar >= 0x3400 && wchar <= 0x4DBF)
182 if (wchar >= 0x3100 && wchar <= 0x312C)
184 if (wchar >= 0xF900 && wchar <= 0xFAFF)
191 return (wchar >= L
'0' && wchar <=L
'9');
196 return (c >=
'0' && c <=
'9');
201 for (
char const* c = str; *c; ++c)
210 return isNumeric(wchar) || wchar == L
' ';
215 for (
wchar_t c : wstr)
223 for (
wchar_t c : wstr)
231 for (
wchar_t c : wstr)
239 for (
wchar_t c : wstr)
247 for (
wchar_t c : wstr)
257 if (wchar >= L
'a' && wchar <= L
'z')
258 return wchar_t(
uint16(wchar) - 0x0020);
260 return wchar_t(0x1E9E);
261 if (wchar >= 0x00E0 && wchar <= 0x00F6)
262 return wchar_t(
uint16(wchar) - 0x0020);
263 if (wchar >= 0x00F8 && wchar <= 0x00FE)
264 return wchar_t(
uint16(wchar) - 0x0020);
265 if (wchar >= 0x0101 && wchar <= 0x012F)
268 return wchar_t(
uint16(wchar) - 0x0001);
270 if (wchar >= 0x0430 && wchar <= 0x044F)
271 return wchar_t(
uint16(wchar) - 0x0020);
273 return wchar_t(0x0401);
275 return wchar_t(0x0152);
277 return wchar_t(0x0178);
295 if (wchar >= L
'A' && wchar <= L
'Z')
296 return wchar_t(
uint16(wchar)+0x0020);
297 if (wchar >= 0x00C0 && wchar <= 0x00D6)
298 return wchar_t(
uint16(wchar)+0x0020);
299 if (wchar >= 0x00D8 && wchar <= 0x00DE)
300 return wchar_t(
uint16(wchar)+0x0020);
301 if (wchar >= 0x0100 && wchar <= 0x012E)
304 return wchar_t(
uint16(wchar)+0x0001);
307 return wchar_t(0x00DF);
309 return wchar_t(0x0451);
311 return wchar_t(0x0153);
313 return wchar_t(0x00FF);
314 if (wchar >= 0x0410 && wchar <= 0x042F)
315 return wchar_t(
uint16(wchar)+0x0020);
323 if (wchar >= L
'a' && wchar <= L
'z')
325 if (wchar >= 0x00E0 && wchar <= 0x00FF)
327 if (wchar >= 0x0430 && wchar <= 0x044F)
341 char operator()(
char c)
const {
return std::toupper(
static_cast<unsigned char>(c)); }
346 char operator()(
char c)
const {
return std::tolower(
static_cast<unsigned char>(c)); }
365#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
383template <
typename Container>
389template <
size_t Size>
394template <
size_t Size>
397 std::array<uint8, Size> arr;
404 std::vector<uint8> buf;
405 size_t const sz = (str.size() / 2);
414inline bool StringStartsWith(std::string_view haystack, std::string_view needle) {
return (haystack.substr(0, needle.length()) == needle); }
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);
513template<
typename Ret,
typename T1,
typename... T>
516 if constexpr (
sizeof...(T) > 0)
517 return (first ?
static_cast<Ret*
>(first) : Coalesce<Ret>(rest...));
519 return static_cast<Ret*
>(first);
534 if constexpr (std::is_same_v<std::remove_cv_t<T>, std::type_info>)
std::optional< T > Optional
Optional helper class to wrap optional values within.
TC_COMMON_API Optional< int64 > MoneyStringToMoney(std::string const &moneyString)
void HexStrToByteArray(std::string_view str, std::array< uint8, Size > &buf, bool reverse=false)
TC_COMMON_API bool ReadWinConsole(std::string &str, size_t size=256)
TC_COMMON_API std::wstring GetMainPartOfName(std::wstring const &wname, uint32 declension)
bool isKoreanString(std::wstring_view wstr, bool numericOrSpace)
TC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2)
TC_COMMON_API bool IsIPAddress(char const *ipaddress)
Check if the string is a valid ip address representation.
bool isCyrillicString(std::wstring_view wstr, bool numericOrSpace)
TC_COMMON_API float DegToRad(float degrees)
float GetPctOf(T value, T max)
struct WcharToUpperOnlyLatin wcharToUpperOnlyLatin
bool isChineseCharacter(wchar_t wchar)
bool isExtendedLatinCharacter(wchar_t wchar)
TC_COMMON_API void wstrToLower(std::wstring &str)
bool isKoreanCharacter(wchar_t wchar)
TC_COMMON_API std::wstring wstrCaseAccentInsensitiveParse(std::wstring_view wstr, LocaleConstant locale)
TC_COMMON_API void utf8truncate(std::string &utf8str, size_t len)
bool StringStartsWith(std::string_view haystack, std::string_view needle)
TC_COMMON_API void vutf8printf(FILE *out, const char *str, va_list *ap)
std::string ByteArrayToHexStr(Container const &c, bool reverse=false)
bool isChineseString(std::wstring_view wstr, bool numericOrSpace)
bool CompareValues(ComparisionType type, T val1, T val2)
bool isNumeric(wchar_t wchar)
TC_COMMON_API bool Utf8toWStr(std::string_view utf8str, std::wstring &wstr)
bool isBasicLatinString(std::wstring_view wstr, bool numericOrSpace)
TC_COMMON_API uint32 GetPID()
TC_COMMON_API void utf8printf(FILE *out, const char *str,...)
Ret * Coalesce(T1 *first, T *... rest)
std::vector< uint8 > HexStrToByteVector(std::string_view str, bool reverse=false)
TC_COMMON_API std::string TimeToHumanReadable(time_t t)
T RoundToInterval(T &num, T floor, T ceil)
TC_COMMON_API Optional< std::size_t > RemoveCRLF(std::string &str)
TC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle)
TC_COMMON_API bool WriteWinConsole(std::string_view str, bool error=false)
TC_COMMON_API std::string TimeToTimestampStr(time_t t)
TC_COMMON_API time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime=true)
bool ValueContainsStringI(std::pair< T, std::string_view > const &haystack, std::string_view needle)
TC_COMMON_API bool WStrToUtf8(std::wstring_view wstr, std::string &utf8str)
struct WcharToLower wcharToLower
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
TC_COMMON_API tm TimeBreakdown(time_t t)
TC_COMMON_API uint32 TimeStringToSecs(std::string const ×tring)
TC_COMMON_API bool utf8ToConsole(std::string_view utf8str, std::string &conStr)
TC_COMMON_API std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat=TimeFormat::FullText, bool hoursOnly=false)
TC_COMMON_API uint32 CreatePIDFile(std::string const &filename)
create PID file
TC_COMMON_API void strToUpper(std::string &str)
bool StringStartsWithI(std::string_view haystack, std::string_view needle)
bool isLower(wchar_t wchar)
bool isExtendedLatinString(std::wstring_view wstr, bool numericOrSpace)
T ApplyPct(T &base, U pct)
TC_COMMON_API void strToLower(std::string &str)
TC_COMMON_API bool Utf8ToUpperOnlyLatin(std::string &utf8String)
TC_COMMON_API bool StringCompareLessI(std::string_view a, std::string_view b)
struct CharToUpper charToUpper
T CalculatePct(T base, U pct)
bool isCyrillicCharacter(wchar_t wchar)
TC_COMMON_API bool Utf8FitTo(std::string_view str, std::wstring_view search)
struct CharToLower charToLower
TC_COMMON_API void wstrToUpper(std::wstring &str)
TC_COMMON_API bool consoleToUtf8(std::string_view conStr, std::string &utf8str)
bool isNumericOrSpace(wchar_t wchar)
struct WcharToUpper wcharToUpper
TC_COMMON_API size_t utf8length(std::string &utf8str)
bool isUpper(wchar_t wchar)
bool isBasicLatinCharacter(wchar_t wchar)
HookList< T > & operator+=(T &&t)
std::vector< T > ContainerType
ContainerType::const_iterator const_iterator
const_iterator end() const
const_iterator begin() const
ContainerType::iterator iterator
TC_COMMON_API void HexStrToByteArray(std::string_view str, uint8 *out, size_t outlen, bool reverse=false)
TC_COMMON_API std::string ByteArrayToHexStr(uint8 const *bytes, size_t length, bool reverse=false)
TC_COMMON_API std::string GetTypeName(std::type_info const &)
TC_COMMON_API void VerifyOsVersion()
TC_COMMON_API std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
std::string GetTypeName()
bool Size(ContainerUnorderedMap< TypeList< H, T >, KEY_TYPE > const &elements, std::size_t *size, SPECIFIC_TYPE *obj)
constexpr std::size_t size()
char operator()(char c) const
char operator()(char c) const
constexpr NonDefaultConstructible(T value)
bool operator()(std::string_view a, std::string_view b) const
wchar_t operator()(wchar_t wchar) const
wchar_t operator()(wchar_t wchar) const
wchar_t operator()(wchar_t wchar) const