TrinityCore
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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  WcharToUpper
 
struct  WcharToUpperOnlyLatin
 
struct  WcharToLower
 
struct  CharToUpper
 
struct  CharToLower
 
struct  CStringBoundedSentinel< Iterator >
 
struct  CStringSentinel_T
 
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)
 
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 isLatin1Character (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)
 
bool isLower (wchar_t wchar)
 
bool isUpper (wchar_t wchar)
 
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 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)
 
TC_COMMON_API bool StringCompareLessI (std::string_view a, std::string_view b)
 
TC_COMMON_API void StringReplaceAll (std::string *str, std::string_view text, std::string_view replacement)
 
std::string StringReplaceAll (std::string_view str, std::string_view text, std::string_view replacement)
 
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>
constexpr 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)
 

Variables

struct WcharToUpper wcharToUpper
 
struct WcharToUpperOnlyLatin wcharToUpperOnlyLatin
 
struct WcharToLower wcharToLower
 
struct CharToUpper charToUpper
 
struct CharToLower charToLower
 
struct CStringSentinel_T CStringSentinel
 

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 525 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 558 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 431 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.

◆ Coalesce()

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

Definition at line 565 of file Util.h.

◆ CompareValues()

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

Definition at line 536 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 692 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 277 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 880 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 101 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 622 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 291 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 442 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 437 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 449 of file Util.h.

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

◆ isBasicLatinCharacter()

bool isBasicLatinCharacter ( wchar_t  wchar)
inline

Definition at line 121 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 231 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 194 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 263 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 172 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 247 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 130 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 239 of file Util.h.

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

◆ isKoreanCharacter()

bool isKoreanCharacter ( wchar_t  wchar)
inline

Definition at line 181 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 255 of file Util.h.

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

◆ isLatin1Character()

bool isLatin1Character ( wchar_t  wchar)
inline

Definition at line 151 of file Util.h.

+ Here is the call graph for this function:

◆ isLower()

bool isLower ( wchar_t  wchar)
inline

Definition at line 339 of file Util.h.

+ Here is the caller graph for this function:

◆ isNumeric() [1/3]

bool isNumeric ( char  c)
inline

Definition at line 212 of file Util.h.

◆ isNumeric() [2/3]

bool isNumeric ( char const *  str)
inline

Definition at line 217 of file Util.h.

+ Here is the call graph for this function:

◆ isNumeric() [3/3]

bool isNumeric ( wchar_t  wchar)
inline

Definition at line 207 of file Util.h.

+ Here is the caller graph for this function:

◆ isNumericOrSpace()

bool isNumericOrSpace ( wchar_t  wchar)
inline

Definition at line 226 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 352 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 180 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 764 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 797 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 116 of file Util.cpp.

+ Here is the call graph for this function:
+ 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 860 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 854 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 849 of file Util.cpp.

+ Here is the caller graph for this function:

◆ StringReplaceAll() [1/2]

TC_COMMON_API void StringReplaceAll ( std::string *  str,
std::string_view  text,
std::string_view  replacement 
)

Definition at line 865 of file Util.cpp.

+ Here is the caller graph for this function:

◆ StringReplaceAll() [2/2]

std::string StringReplaceAll ( std::string_view  str,
std::string_view  text,
std::string_view  replacement 
)
inline

Definition at line 473 of file Util.h.

+ Here is the call graph for this function:

◆ StringStartsWith()

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

Definition at line 461 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 462 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 435 of file Util.cpp.

+ Here is the caller graph for this function:

◆ strToUpper()

TC_COMMON_API void strToUpper ( std::string &  str)

Definition at line 434 of file Util.cpp.

◆ TimeBreakdown()

TC_COMMON_API tm TimeBreakdown ( time_t  t)

Definition at line 94 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 222 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 267 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 254 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 707 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 302 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 723 of file Util.cpp.

+ Here is the call graph for this function:

◆ utf8ToConsole()

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

Definition at line 675 of file Util.cpp.

+ Here is the call graph for this function:

◆ Utf8ToUpperOnlyLatin()

TC_COMMON_API bool Utf8ToUpperOnlyLatin ( std::string &  utf8String)

Definition at line 752 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 336 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 370 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 108 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 315 of file Util.cpp.

+ Here is the caller graph for this function:

◆ vutf8printf()

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

Definition at line 731 of file Util.cpp.

+ 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 783 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 437 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 433 of file Util.cpp.

+ Here is the caller graph for this function:

◆ wstrToUpper()

TC_COMMON_API void wstrToUpper ( std::wstring &  str)

Definition at line 432 of file Util.cpp.

◆ WStrToUtf8() [1/2]

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

Definition at line 409 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 386 of file Util.cpp.

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

Variable Documentation

◆ charToLower

struct CharToLower charToLower

◆ charToUpper

struct CharToUpper charToUpper

◆ CStringSentinel

struct CStringSentinel_T CStringSentinel

◆ wcharToLower

struct WcharToLower wcharToLower

◆ wcharToUpper

struct WcharToUpper wcharToUpper

◆ wcharToUpperOnlyLatin

struct WcharToUpperOnlyLatin wcharToUpperOnlyLatin