TrinityCore
Util.h File Reference
#include "Define.h"
#include "Errors.h"
#include "Optional.h"
#include <array>
#include <string>
#include <string_view>
#include <typeinfo>
#include <utility>
#include <vector>
+ Include dependency graph for Util.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  StringCompareLessI_T
 
class  HookList< T >
 
struct  NonDefaultConstructible< T >
 

Namespaces

namespace  Trinity
 
namespace  Trinity::Impl
 

Enumerations

enum class  TimeFormat : uint8 { FullText , ShortText , Numeric }
 
enum  ComparisionType {
  COMP_TYPE_EQ = 0 , COMP_TYPE_HIGH , COMP_TYPE_LOW , COMP_TYPE_HIGH_EQ ,
  COMP_TYPE_LOW_EQ , COMP_TYPE_MAX
}
 

Functions

TC_COMMON_API void Trinity::VerifyOsVersion ()
 
TC_COMMON_API std::vector< std::string_view > Trinity::Tokenize (std::string_view str, char sep, bool keepEmpty)
 
std::vector< std::string_view > Trinity::Tokenize (std::string &&, char, bool)=delete
 
std::vector< std::string_view > Trinity::Tokenize (std::string const &&, char, bool)=delete
 
std::vector< std::string_view > Trinity::Tokenize (char const *str, char sep, bool keepEmpty)
 
TC_COMMON_API Optional< int64MoneyStringToMoney (std::string const &moneyString)
 
TC_COMMON_API time_t GetLocalHourTimestamp (time_t time, uint8 hour, bool onlyAfterTime=true)
 
TC_COMMON_API tm TimeBreakdown (time_t t)
 
TC_COMMON_API std::string secsToTimeString (uint64 timeInSecs, TimeFormat timeFormat=TimeFormat::FullText, bool hoursOnly=false)
 
TC_COMMON_API uint32 TimeStringToSecs (std::string const &timestring)
 
TC_COMMON_API std::string TimeToTimestampStr (time_t t)
 
TC_COMMON_API std::string TimeToHumanReadable (time_t t)
 
template<class T , class U >
CalculatePct (T base, U pct)
 
template<class T >
float GetPctOf (T value, T max)
 
template<class T , class U >
AddPct (T &base, U pct)
 
template<class T , class U >
ApplyPct (T &base, U pct)
 
template<class T >
RoundToInterval (T &num, T floor, T ceil)
 
template<class T >
square (T x)
 
TC_COMMON_API bool Utf8toWStr (std::string_view utf8str, std::wstring &wstr)
 
TC_COMMON_API bool Utf8toWStr (char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
 
bool Utf8toWStr (std::string_view utf8str, wchar_t *wstr, size_t &wsize)
 
TC_COMMON_API bool WStrToUtf8 (std::wstring_view wstr, std::string &utf8str)
 
TC_COMMON_API bool WStrToUtf8 (wchar_t const *wstr, size_t size, std::string &utf8str)
 
TC_COMMON_API size_t utf8length (std::string &utf8str)
 
TC_COMMON_API void utf8truncate (std::string &utf8str, size_t len)
 
bool isBasicLatinCharacter (wchar_t wchar)
 
bool isExtendedLatinCharacter (wchar_t wchar)
 
bool isCyrillicCharacter (wchar_t wchar)
 
bool isKoreanCharacter (wchar_t wchar)
 
bool isChineseCharacter (wchar_t wchar)
 
bool isNumeric (wchar_t wchar)
 
bool isNumeric (char c)
 
bool isNumeric (char const *str)
 
bool isNumericOrSpace (wchar_t wchar)
 
bool isBasicLatinString (std::wstring_view wstr, bool numericOrSpace)
 
bool isExtendedLatinString (std::wstring_view wstr, bool numericOrSpace)
 
bool isCyrillicString (std::wstring_view wstr, bool numericOrSpace)
 
bool isKoreanString (std::wstring_view wstr, bool numericOrSpace)
 
bool isChineseString (std::wstring_view wstr, bool numericOrSpace)
 
wchar_t wcharToUpper (wchar_t wchar)
 
wchar_t wcharToUpperOnlyLatin (wchar_t wchar)
 
wchar_t wcharToLower (wchar_t wchar)
 
bool isLower (wchar_t wchar)
 
bool isUpper (wchar_t wchar)
 
char charToUpper (char c)
 
char charToLower (char c)
 
TC_COMMON_API void wstrToUpper (std::wstring &str)
 
TC_COMMON_API void wstrToLower (std::wstring &str)
 
TC_COMMON_API void strToUpper (std::string &str)
 
TC_COMMON_API void strToLower (std::string &str)
 
TC_COMMON_API std::wstring wstrCaseAccentInsensitiveParse (std::wstring_view wstr, LocaleConstant locale)
 
TC_COMMON_API std::wstring GetMainPartOfName (std::wstring const &wname, uint32 declension)
 
TC_COMMON_API bool utf8ToConsole (std::string_view utf8str, std::string &conStr)
 
TC_COMMON_API bool consoleToUtf8 (std::string_view conStr, std::string &utf8str)
 
TC_COMMON_API bool Utf8FitTo (std::string_view str, std::wstring_view search)
 
TC_COMMON_API void utf8printf (FILE *out, const char *str,...)
 
TC_COMMON_API void vutf8printf (FILE *out, const char *str, va_list *ap)
 
TC_COMMON_API bool Utf8ToUpperOnlyLatin (std::string &utf8String)
 
TC_COMMON_API bool ReadWinConsole (std::string &str, size_t size=256)
 
TC_COMMON_API bool WriteWinConsole (std::string_view str, bool error=false)
 
TC_COMMON_API Optional< std::size_t > RemoveCRLF (std::string &str)
 
TC_COMMON_API bool IsIPAddress (char const *ipaddress)
 Check if the string is a valid ip address representation. More...
 
TC_COMMON_API uint32 CreatePIDFile (std::string const &filename)
 create PID file More...
 
TC_COMMON_API uint32 GetPID ()
 
TC_COMMON_API std::string Trinity::Impl::ByteArrayToHexStr (uint8 const *bytes, size_t length, bool reverse=false)
 
TC_COMMON_API void Trinity::Impl::HexStrToByteArray (std::string_view str, uint8 *out, size_t outlen, bool reverse=false)
 
template<typename Container >
std::string ByteArrayToHexStr (Container const &c, bool reverse=false)
 
template<size_t Size>
void HexStrToByteArray (std::string_view str, std::array< uint8, Size > &buf, bool reverse=false)
 
template<size_t Size>
std::array< uint8, Size > HexStrToByteArray (std::string_view str, bool reverse=false)
 
std::vector< uint8HexStrToByteVector (std::string_view str, bool reverse=false)
 
TC_COMMON_API float DegToRad (float degrees)
 
TC_COMMON_API bool StringEqualI (std::string_view str1, std::string_view str2)
 
bool StringStartsWith (std::string_view haystack, std::string_view needle)
 
bool StringStartsWithI (std::string_view haystack, std::string_view needle)
 
TC_COMMON_API bool StringContainsStringI (std::string_view haystack, std::string_view needle)
 
template<typename T >
bool ValueContainsStringI (std::pair< T, std::string_view > const &haystack, std::string_view needle)
 
TC_COMMON_API bool StringCompareLessI (std::string_view a, std::string_view b)
 
template<class T >
bool CompareValues (ComparisionType type, T val1, T val2)
 
template<typename E >
constexpr std::underlying_type< E >::type AsUnderlyingType (E enumValue)
 
template<typename Ret , typename T1 , typename... T>
Ret * Coalesce (T1 *first, T *... rest)
 
TC_COMMON_API std::string Trinity::Impl::GetTypeName (std::type_info const &)
 
template<typename T >
std::string Trinity::GetTypeName ()
 
template<typename T >
std::string Trinity::GetTypeName (T &&v)
 

Enumeration Type Documentation

◆ ComparisionType

Enumerator
COMP_TYPE_EQ 
COMP_TYPE_HIGH 
COMP_TYPE_LOW 
COMP_TYPE_HIGH_EQ 
COMP_TYPE_LOW_EQ 
COMP_TYPE_MAX 

Definition at line 458 of file Util.h.

◆ TimeFormat

enum class TimeFormat : uint8
strong
Enumerator
FullText 
ShortText 
Numeric 

Definition at line 34 of file Util.h.

Function Documentation

◆ AddPct()

template<class T , class U >
T AddPct ( T &  base,
pct 
)
inline

Definition at line 85 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ApplyPct()

template<class T , class U >
T ApplyPct ( T &  base,
pct 
)
inline

Definition at line 91 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AsUnderlyingType()

template<typename E >
constexpr std::underlying_type< E >::type AsUnderlyingType ( enumValue)
constexpr

Definition at line 491 of file Util.h.

+ Here is the caller graph for this function:

◆ ByteArrayToHexStr()

template<typename Container >
std::string ByteArrayToHexStr ( Container const &  c,
bool  reverse = false 
)

Definition at line 368 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CalculatePct()

template<class T , class U >
T CalculatePct ( base,
pct 
)
inline

Definition at line 72 of file Util.h.

+ Here is the caller graph for this function:

◆ charToLower()

char charToLower ( char  c)
inline

Definition at line 331 of file Util.h.

+ Here is the caller graph for this function:

◆ charToUpper()

char charToUpper ( char  c)
inline

Definition at line 330 of file Util.h.

+ Here is the caller graph for this function:

◆ Coalesce()

template<typename Ret , typename T1 , typename... T>
Ret * Coalesce ( T1 *  first,
T *...  rest 
)

Definition at line 498 of file Util.h.

◆ CompareValues()

template<class T >
bool CompareValues ( ComparisionType  type,
val1,
val2 
)

Definition at line 469 of file Util.h.

+ Here is the caller graph for this function:

◆ consoleToUtf8()

TC_COMMON_API bool consoleToUtf8 ( std::string_view  conStr,
std::string &  utf8str 
)

Definition at line 735 of file Util.cpp.

+ Here is the call graph for this function:

◆ CreatePIDFile()

TC_COMMON_API uint32 CreatePIDFile ( std::string const &  filename)

create PID file

Definition at line 324 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DegToRad()

TC_COMMON_API float DegToRad ( float  degrees)

Definition at line 912 of file Util.cpp.

+ Here is the caller graph for this function:

◆ GetLocalHourTimestamp()

TC_COMMON_API time_t GetLocalHourTimestamp ( time_t  time,
uint8  hour,
bool  onlyAfterTime = true 
)

Definition at line 100 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetMainPartOfName()

TC_COMMON_API std::wstring GetMainPartOfName ( std::wstring const &  wname,
uint32  declension 
)

Definition at line 669 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPctOf()

template<class T >
float GetPctOf ( value,
max 
)
inline

Definition at line 78 of file Util.h.

+ Here is the caller graph for this function:

◆ GetPID()

TC_COMMON_API uint32 GetPID ( )

Definition at line 338 of file Util.cpp.

+ Here is the caller graph for this function:

◆ HexStrToByteArray() [1/2]

template<size_t Size>
std::array< uint8, Size > HexStrToByteArray ( std::string_view  str,
bool  reverse = false 
)

Definition at line 379 of file Util.h.

+ Here is the call graph for this function:

◆ HexStrToByteArray() [2/2]

template<size_t Size>
void HexStrToByteArray ( std::string_view  str,
std::array< uint8, Size > &  buf,
bool  reverse = false 
)

Definition at line 374 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HexStrToByteVector()

std::vector< uint8 > HexStrToByteVector ( std::string_view  str,
bool  reverse = false 
)
inline

Definition at line 386 of file Util.h.

+ Here is the call graph for this function:

◆ isBasicLatinCharacter()

bool isBasicLatinCharacter ( wchar_t  wchar)
inline

Definition at line 124 of file Util.h.

+ Here is the caller graph for this function:

◆ isBasicLatinString()

bool isBasicLatinString ( std::wstring_view  wstr,
bool  numericOrSpace 
)
inline

Definition at line 213 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isChineseCharacter()

bool isChineseCharacter ( wchar_t  wchar)
inline

Definition at line 176 of file Util.h.

+ Here is the caller graph for this function:

◆ isChineseString()

bool isChineseString ( std::wstring_view  wstr,
bool  numericOrSpace 
)
inline

Definition at line 245 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCyrillicCharacter()

bool isCyrillicCharacter ( wchar_t  wchar)
inline

Definition at line 154 of file Util.h.

+ Here is the caller graph for this function:

◆ isCyrillicString()

bool isCyrillicString ( std::wstring_view  wstr,
bool  numericOrSpace 
)
inline

Definition at line 229 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isExtendedLatinCharacter()

bool isExtendedLatinCharacter ( wchar_t  wchar)
inline

Definition at line 133 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isExtendedLatinString()

bool isExtendedLatinString ( std::wstring_view  wstr,
bool  numericOrSpace 
)
inline

Definition at line 221 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsIPAddress()

TC_COMMON_API bool IsIPAddress ( char const *  ipaddress)

Check if the string is a valid ip address representation.

Definition at line 313 of file Util.cpp.

+ Here is the caller graph for this function:

◆ isKoreanCharacter()

bool isKoreanCharacter ( wchar_t  wchar)
inline

Definition at line 163 of file Util.h.

+ Here is the caller graph for this function:

◆ isKoreanString()

bool isKoreanString ( std::wstring_view  wstr,
bool  numericOrSpace 
)
inline

Definition at line 237 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isLower()

bool isLower ( wchar_t  wchar)
inline

Definition at line 312 of file Util.h.

+ Here is the caller graph for this function:

◆ isNumeric() [1/3]

bool isNumeric ( char  c)
inline

Definition at line 194 of file Util.h.

◆ isNumeric() [2/3]

bool isNumeric ( char const *  str)
inline

Definition at line 199 of file Util.h.

+ Here is the call graph for this function:

◆ isNumeric() [3/3]

bool isNumeric ( wchar_t  wchar)
inline

Definition at line 189 of file Util.h.

+ Here is the caller graph for this function:

◆ isNumericOrSpace()

bool isNumericOrSpace ( wchar_t  wchar)
inline

Definition at line 208 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isUpper()

bool isUpper ( wchar_t  wchar)
inline

Definition at line 325 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MoneyStringToMoney()

TC_COMMON_API Optional< int64 > MoneyStringToMoney ( std::string const &  moneyString)

Definition at line 216 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReadWinConsole()

TC_COMMON_API bool ReadWinConsole ( std::string &  str,
size_t  size = 256 
)

Definition at line 807 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveCRLF()

TC_COMMON_API Optional< std::size_t > RemoveCRLF ( std::string &  str)

Definition at line 839 of file Util.cpp.

+ Here is the caller graph for this function:

◆ RoundToInterval()

template<class T >
T RoundToInterval ( T &  num,
floor,
ceil 
)
inline

Definition at line 97 of file Util.h.

+ Here is the caller graph for this function:

◆ secsToTimeString()

TC_COMMON_API std::string secsToTimeString ( uint64  timeInSecs,
TimeFormat  timeFormat = TimeFormat::FullText,
bool  hoursOnly = false 
)

Definition at line 115 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ square()

template<class T >
T square ( x)
inline

Definition at line 103 of file Util.h.

+ Here is the caller graph for this function:

◆ StringCompareLessI()

TC_COMMON_API bool StringCompareLessI ( std::string_view  a,
std::string_view  b 
)

Definition at line 902 of file Util.cpp.

+ Here is the caller graph for this function:

◆ StringContainsStringI()

TC_COMMON_API bool StringContainsStringI ( std::string_view  haystack,
std::string_view  needle 
)

Definition at line 896 of file Util.cpp.

+ Here is the caller graph for this function:

◆ StringEqualI()

TC_COMMON_API bool StringEqualI ( std::string_view  str1,
std::string_view  str2 
)

Definition at line 891 of file Util.cpp.

+ Here is the caller graph for this function:

◆ StringStartsWith()

bool StringStartsWith ( std::string_view  haystack,
std::string_view  needle 
)
inline

Definition at line 398 of file Util.h.

+ Here is the caller graph for this function:

◆ StringStartsWithI()

bool StringStartsWithI ( std::string_view  haystack,
std::string_view  needle 
)
inline

Definition at line 399 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strToLower()

TC_COMMON_API void strToLower ( std::string &  str)

Definition at line 482 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strToUpper()

TC_COMMON_API void strToUpper ( std::string &  str)

Definition at line 481 of file Util.cpp.

+ Here is the call graph for this function:

◆ TimeBreakdown()

TC_COMMON_API tm TimeBreakdown ( time_t  t)

Definition at line 93 of file Util.cpp.

+ Here is the caller graph for this function:

◆ TimeStringToSecs()

TC_COMMON_API uint32 TimeStringToSecs ( std::string const &  timestring)

Definition at line 258 of file Util.cpp.

+ Here is the caller graph for this function:

◆ TimeToHumanReadable()

TC_COMMON_API std::string TimeToHumanReadable ( time_t  t)

Definition at line 303 of file Util.cpp.

+ Here is the caller graph for this function:

◆ TimeToTimestampStr()

TC_COMMON_API std::string TimeToTimestampStr ( time_t  t)

Definition at line 290 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Utf8FitTo()

TC_COMMON_API bool Utf8FitTo ( std::string_view  str,
std::wstring_view  search 
)

Definition at line 750 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ utf8length()

TC_COMMON_API size_t utf8length ( std::string &  utf8str)

Definition at line 349 of file Util.cpp.

+ Here is the caller graph for this function:

◆ utf8printf()

TC_COMMON_API void utf8printf ( FILE *  out,
const char *  str,
  ... 
)

Definition at line 766 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ utf8ToConsole()

TC_COMMON_API bool utf8ToConsole ( std::string_view  utf8str,
std::string &  conStr 
)

Definition at line 718 of file Util.cpp.

+ Here is the call graph for this function:

◆ Utf8ToUpperOnlyLatin()

TC_COMMON_API bool Utf8ToUpperOnlyLatin ( std::string &  utf8String)

Definition at line 795 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Utf8toWStr() [1/3]

TC_COMMON_API bool Utf8toWStr ( char const *  utf8str,
size_t  csize,
wchar_t *  wstr,
size_t &  wsize 
)

Definition at line 383 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Utf8toWStr() [2/3]

TC_COMMON_API bool Utf8toWStr ( std::string_view  utf8str,
std::wstring &  wstr 
)

Definition at line 417 of file Util.cpp.

+ Here is the caller graph for this function:

◆ Utf8toWStr() [3/3]

bool Utf8toWStr ( std::string_view  utf8str,
wchar_t *  wstr,
size_t &  wsize 
)
inline

Definition at line 111 of file Util.h.

+ Here is the call graph for this function:

◆ utf8truncate()

TC_COMMON_API void utf8truncate ( std::string &  utf8str,
size_t  len 
)

Definition at line 362 of file Util.cpp.

+ Here is the caller graph for this function:

◆ ValueContainsStringI()

template<typename T >
bool ValueContainsStringI ( std::pair< T, std::string_view > const &  haystack,
std::string_view  needle 
)
inline

Definition at line 402 of file Util.h.

+ Here is the call graph for this function:

◆ vutf8printf()

TC_COMMON_API void vutf8printf ( FILE *  out,
const char *  str,
va_list *  ap 
)

Definition at line 774 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wcharToLower()

wchar_t wcharToLower ( wchar_t  wchar)
inline

Definition at line 285 of file Util.h.

+ Here is the caller graph for this function:

◆ wcharToUpper()

wchar_t wcharToUpper ( wchar_t  wchar)
inline

Definition at line 253 of file Util.h.

+ Here is the caller graph for this function:

◆ wcharToUpperOnlyLatin()

wchar_t wcharToUpperOnlyLatin ( wchar_t  wchar)
inline

Definition at line 280 of file Util.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WriteWinConsole()

TC_COMMON_API bool WriteWinConsole ( std::string_view  str,
bool  error = false 
)

Definition at line 826 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wstrCaseAccentInsensitiveParse()

TC_COMMON_API std::wstring wstrCaseAccentInsensitiveParse ( std::wstring_view  wstr,
LocaleConstant  locale 
)

Definition at line 484 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wstrToLower()

TC_COMMON_API void wstrToLower ( std::wstring &  str)

Definition at line 480 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wstrToUpper()

TC_COMMON_API void wstrToUpper ( std::wstring &  str)

Definition at line 479 of file Util.cpp.

+ Here is the call graph for this function:

◆ WStrToUtf8() [1/2]

TC_COMMON_API bool WStrToUtf8 ( std::wstring_view  wstr,
std::string &  utf8str 
)

Definition at line 456 of file Util.cpp.

◆ WStrToUtf8() [2/2]

TC_COMMON_API bool WStrToUtf8 ( wchar_t const *  wstr,
size_t  size,
std::string &  utf8str 
)

Definition at line 433 of file Util.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: