TrinityCore
Loading...
Searching...
No Matches
Util.cpp File Reference
#include "Util.h"
#include "Common.h"
#include "Containers.h"
#include "StringConvert.h"
#include "StringFormat.h"
#include <boost/core/demangle.hpp>
#include <utf8.h>
#include <algorithm>
#include <string>
#include <cctype>
#include <cstdarg>
#include <ctime>
#include <Windows.h>
+ Include dependency graph for Util.cpp:

Go to the source code of this file.

Functions

tm TimeBreakdown (time_t time)
 
time_t GetLocalHourTimestamp (time_t time, uint8 hour, bool onlyAfterTime)
 
std::string secsToTimeString (uint64 timeInSecs, TimeFormat timeFormat, bool hoursOnly)
 
Optional< int64 > MoneyStringToMoney (std::string const &moneyString)
 
uint32 TimeStringToSecs (std::string const &timestring)
 
std::string TimeToTimestampStr (time_t t)
 
std::string TimeToHumanReadable (time_t t)
 
uint32 CreatePIDFile (std::string const &filename)
 create PID file
 
uint32 GetPID ()
 
size_t utf8length (std::string &utf8str)
 
void utf8truncate (std::string &utf8str, size_t len)
 
bool Utf8toWStr (char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
 
bool Utf8toWStr (std::string_view utf8str, std::wstring &wstr)
 
bool WStrToUtf8 (wchar_t const *wstr, size_t size, std::string &utf8str)
 
bool WStrToUtf8 (std::wstring_view wstr, std::string &utf8str)
 
void wstrToUpper (std::wstring &str)
 
void wstrToLower (std::wstring &str)
 
void strToUpper (std::string &str)
 
void strToLower (std::string &str)
 
std::wstring wstrCaseAccentInsensitiveParse (std::wstring_view wstr, LocaleConstant locale)
 
std::wstring GetMainPartOfName (std::wstring const &wname, uint32 declension)
 
bool utf8ToConsole (std::string_view utf8str, std::string &conStr)
 
bool consoleToUtf8 (std::string_view conStr, std::string &utf8str)
 
bool Utf8FitTo (std::string_view str, std::wstring_view search)
 
void utf8printf (FILE *out, const char *str,...)
 
void vutf8printf (FILE *out, const char *str, va_list *ap)
 
bool Utf8ToUpperOnlyLatin (std::string &utf8String)
 
bool ReadWinConsole (std::string &str, size_t size)
 
bool WriteWinConsole (std::string_view str, bool error)
 
TC_COMMON_API Optional< std::size_t > RemoveCRLF (std::string &str)
 
bool StringEqualI (std::string_view a, std::string_view b)
 
bool StringContainsStringI (std::string_view haystack, std::string_view needle)
 
bool StringCompareLessI (std::string_view a, std::string_view b)
 
void StringReplaceAll (std::string *str, std::string_view text, std::string_view replacement)
 
float DegToRad (float degrees)
 

Function Documentation

◆ consoleToUtf8()

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

Definition at line 692 of file Util.cpp.

References WStrToUtf8().

◆ CreatePIDFile()

uint32 CreatePIDFile ( std::string const &  filename)

create PID file

Definition at line 277 of file Util.cpp.

References GetPID().

Referenced by main().

◆ DegToRad()

float DegToRad ( float  degrees)

Definition at line 880 of file Util.cpp.

References M_PI.

Referenced by ObjectMgr::LoadWorldSafeLocs(), and Spell::SelectImplicitConeTargets().

◆ GetLocalHourTimestamp()

time_t GetLocalHourTimestamp ( time_t  time,
uint8  hour,
bool  onlyAfterTime 
)

◆ GetMainPartOfName()

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

Definition at line 622 of file Util.cpp.

References isCyrillicCharacter().

Referenced by ObjectMgr::CheckDeclinedNames().

◆ GetPID()

uint32 GetPID ( )

Definition at line 291 of file Util.cpp.

Referenced by CreatePIDFile(), and Battlenet::Services::V1::Connection::HandleConnect().

◆ MoneyStringToMoney()

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

Definition at line 180 of file Util.cpp.

References Trinity::Tokenize().

Referenced by modify_commandscript::HandleModifyMoneyCommand().

◆ ReadWinConsole()

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

Definition at line 764 of file Util.cpp.

References WStrToUtf8().

Referenced by CliThread().

◆ RemoveCRLF()

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

Definition at line 797 of file Util.cpp.

Referenced by CliThread(), and LoadGameTable().

◆ secsToTimeString()

◆ StringCompareLessI()

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

Definition at line 860 of file Util.cpp.

References charToLower.

Referenced by StringCompareLessI_T::operator()().

◆ StringContainsStringI()

◆ StringEqualI()

◆ StringReplaceAll()

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

◆ strToLower()

void strToLower ( std::string &  str)

Definition at line 435 of file Util.cpp.

References charToLower.

Referenced by DB2Manager::GetPowerTypeByName(), and IpLocationStore::Load().

◆ strToUpper()

void strToUpper ( std::string &  str)

Definition at line 434 of file Util.cpp.

References charToUpper.

◆ TimeBreakdown()

tm TimeBreakdown ( time_t  time)

◆ TimeStringToSecs()

uint32 TimeStringToSecs ( std::string const &  timestring)

◆ TimeToHumanReadable()

std::string TimeToHumanReadable ( time_t  t)

Definition at line 267 of file Util.cpp.

Referenced by debug_commandscript::HandleDebugQuestResetCommand().

◆ TimeToTimestampStr()

◆ Utf8FitTo()

◆ utf8length()

◆ utf8printf()

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

Definition at line 723 of file Util.cpp.

References vutf8printf().

◆ utf8ToConsole()

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

Definition at line 675 of file Util.cpp.

References Utf8toWStr().

◆ Utf8ToUpperOnlyLatin()

bool Utf8ToUpperOnlyLatin ( std::string &  utf8String)

◆ Utf8toWStr() [1/2]

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

Definition at line 336 of file Util.cpp.

References Trinity::CheckedBufferOutputIterator< T >::remaining().

Referenced by AuctionHouseObject::AddAuction(), ObjectMgr::AddGameTele(), ObjectMgr::CheckDeclinedNames(), ObjectMgr::CheckPetName(), ObjectMgr::CheckPlayerName(), ChannelMgr::CreateCustomChannel(), ObjectMgr::DeleteGameTele(), ChannelMgr::GetChannel(), ChannelMgr::GetChannelForPlayerByNamePart(), ChannelMgr::GetCustomChannel(), ObjectMgr::GetGameTele(), ObjectMgr::GetGameTeleExactName(), WorldSession::HandleAuctionBrowseQuery(), lookup_commandscript::HandleLookupAreaCommand(), lookup_commandscript::HandleLookupCreatureCommand(), lookup_commandscript::HandleLookupEventCommand(), lookup_commandscript::HandleLookupFactionCommand(), lookup_commandscript::HandleLookupItemCommand(), lookup_commandscript::HandleLookupItemSetCommand(), lookup_commandscript::HandleLookupMapCommand(), lookup_commandscript::HandleLookupObjectCommand(), lookup_commandscript::HandleLookupQuestCommand(), lookup_commandscript::HandleLookupSkillCommand(), lookup_commandscript::HandleLookupSpellCommand(), lookup_commandscript::HandleLookupTaxiNodeCommand(), lookup_commandscript::HandleLookupTeleCommand(), lookup_commandscript::HandleLookupTitleCommand(), modify_commandscript::HandleModifyRepCommand(), WorldSession::HandlePetRename(), WorldSession::HandleSetPlayerDeclinedNames(), WorldSession::HandleWhoOpcode(), DB2Manager::IndexLoadedStores(), ObjectMgr::IsReservedName(), ObjectMgr::IsValidCharterName(), ChannelMgr::LoadFromDB(), ObjectMgr::LoadGameTele(), ObjectMgr::LoadReservedPlayersNames(), normalizePlayerName(), LanguageMgr::Translate(), Trinity::ChatCommands::WTail::TryConsume(), Trinity::Impl::ChatCommands::ArgInfo< std::wstring >::TryConsume(), WhoListStorageMgr::Update(), Utf8FitTo(), utf8ToConsole(), Utf8ToUpperOnlyLatin(), vutf8printf(), and WriteWinConsole().

◆ Utf8toWStr() [2/2]

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

Definition at line 370 of file Util.cpp.

Referenced by Utf8toWStr().

◆ utf8truncate()

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

Definition at line 315 of file Util.cpp.

Referenced by PlayerSocial::SetFriendNote(), and Guild::BankTab::SetText().

◆ vutf8printf()

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

Definition at line 731 of file Util.cpp.

References Utf8toWStr().

Referenced by utf8printf().

◆ WriteWinConsole()

bool WriteWinConsole ( std::string_view  str,
bool  error 
)

Definition at line 783 of file Util.cpp.

References Utf8toWStr().

Referenced by AppenderConsole::Print(), and utf8print().

◆ wstrCaseAccentInsensitiveParse()

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

◆ wstrToLower()

◆ wstrToUpper()

void wstrToUpper ( std::wstring &  str)

Definition at line 432 of file Util.cpp.

References wcharToUpper.

◆ WStrToUtf8() [1/2]

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

Definition at line 409 of file Util.cpp.

◆ WStrToUtf8() [2/2]

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

Definition at line 386 of file Util.cpp.

Referenced by consoleToUtf8(), normalizePlayerName(), ReadWinConsole(), and Utf8ToUpperOnlyLatin().