AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Util.h File Reference
#include "Containers.h"
#include "Define.h"
#include "Errors.h"
#include "Optional.h"
#include <algorithm>
#include <array>
#include <cctype>
#include <list>
#include <map>
#include <string>
#include <vector>

Go to the source code of this file.

Classes

struct  Finder< T, S >
 
struct  StringCompareLessI_T
 
class  HookList< T >
 
class  flag96
 

Namespaces

namespace  Acore
 
namespace  Acore::Impl
 

Enumerations

enum  ComparisionType {
  COMP_TYPE_EQ = 0 ,
  COMP_TYPE_HIGH ,
  COMP_TYPE_LOW ,
  COMP_TYPE_HIGH_EQ ,
  COMP_TYPE_LOW_EQ ,
  COMP_TYPE_MAX
}
 

Functions

void stripLineInvisibleChars (std::string &src)
 
AC_COMMON_API Optional< int32MoneyStringToMoney (std::string_view moneyString)
 
std::string secsToTimeString (uint64 timeInSecs, bool shortText=false)
 
uint32 TimeStringToSecs (const std::string &timestring)
 
void ApplyPercentModFloatVar (float &var, float val, bool apply)
 
template<class T , class U >
CalculatePct (T base, U pct)
 
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)
 
AC_COMMON_API bool Utf8toWStr (std::string_view utf8str, std::wstring &wstr)
 
AC_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)
 
AC_COMMON_API bool WStrToUtf8 (std::wstring_view wstr, std::string &utf8str)
 
AC_COMMON_API bool WStrToUtf8 (wchar_t const *wstr, size_t size, std::string &utf8str)
 
size_t utf8length (std::string &utf8str)
 
void utf8truncate (std::string &utf8str, size_t len)
 
bool isBasicLatinCharacter (wchar_t wchar)
 
bool isExtendedLatinCharacter (wchar_t wchar)
 
bool isCyrillicCharacter (wchar_t wchar)
 
bool isEastAsianCharacter (wchar_t wchar)
 
bool isNumeric (wchar_t wchar)
 
bool isNumeric (char c)
 
bool IsEvenNumber (int32 n)
 
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 isEastAsianString (std::wstring_view wstr, bool numericOrSpace)
 
char charToUpper (char c)
 
char charToLower (char c)
 
wchar_t wcharToUpper (wchar_t wchar)
 
wchar_t wcharToUpperOnlyLatin (wchar_t wchar)
 
wchar_t wcharToLower (wchar_t wchar)
 
void wstrToUpper (std::wstring &str)
 
void wstrToLower (std::wstring &str)
 
std::wstring GetMainPartOfName (std::wstring const &wname, uint32 declension)
 
AC_COMMON_API bool utf8ToConsole (std::string_view utf8str, std::string &conStr)
 
AC_COMMON_API bool consoleToUtf8 (std::string_view conStr, std::string &utf8str)
 
AC_COMMON_API bool Utf8FitTo (std::string_view str, std::wstring_view search)
 
AC_COMMON_API void utf8printf (FILE *out, const char *str,...)
 
AC_COMMON_API void vutf8printf (FILE *out, const char *str, va_list *ap)
 
AC_COMMON_API bool Utf8ToUpperOnlyLatin (std::string &utf8String)
 
bool IsIPAddress (char const *ipaddress)
 Check if the string is a valid ip address representation.
 
uint32 CreatePIDFile (const std::string &filename)
 create PID file
 
uint32 GetPID ()
 
AC_COMMON_API std::string Acore::Impl::ByteArrayToHexStr (uint8 const *bytes, size_t length, bool reverse=false)
 
AC_COMMON_API void Acore::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)
 
AC_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)
 
AC_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)
 
AC_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)
 
AC_COMMON_API std::string GetTypeName (std::type_info const &)
 
template<typename T >
std::string GetTypeName ()
 
template<typename T >
std::enable_if_t<!std::is_same_v< std::decay_t< T >, std::type_info >, std::string > 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 
587{
588 COMP_TYPE_EQ = 0,
594};
@ COMP_TYPE_LOW
Definition: Util.h:590
@ COMP_TYPE_MAX
Definition: Util.h:593
@ COMP_TYPE_HIGH
Definition: Util.h:589
@ COMP_TYPE_EQ
Definition: Util.h:588
@ COMP_TYPE_HIGH_EQ
Definition: Util.h:591
@ COMP_TYPE_LOW_EQ
Definition: Util.h:592

Function Documentation

◆ AddPct()

template<class T , class U >
T AddPct ( T &  base,
pct 
)
inline
68{
69 return base += CalculatePct(base, pct);
70}
T CalculatePct(T base, U pct)
Definition: Util.h:61

References CalculatePct().

Referenced by KillRewarder::_RewardXP(), HostileReference::addThreatPercent(), Unit::CalcAbsorbResist(), Unit::CalcArmorReducedDamage(), spell_gen_reduced_above_60_aura::CalculateAmount(), spell_hun_cower::CalculateAmount(), spell_pri_lightwell_renew::CalculateAmount(), spell_pal_sacred_shield_base::CalculateAmount(), spell_sha_earth_shield::CalculateAmount(), spell_warr_rend::CalculateAmount(), AuraEffect::CalculateAmount(), spell_dru_treant_scaling::CalculateAPAmount(), spell_hun_generic_scaling::CalculateAPAmount(), Unit::CalculateLevelPenalty(), Unit::CalculateMeleeDamage(), spell_hun_generic_scaling::CalculateSPAmount(), CalculateSpellAmount(), Unit::CalculateSpellDamageTaken(), spell_dk_pet_scaling::CalculateStatAmount(), spell_hun_generic_scaling::CalculateStatAmount(), Spell::Delayed(), Spell::DelayedChannel(), Spell::EffectEnergize(), Spell::EffectSchoolDMG(), Spell::EffectWeaponDmg(), Player::getMaxTimer(), Unit::GetTotalAuraMultiplier(), Unit::GetTotalAuraMultiplierByAffectMask(), Unit::GetTotalAuraMultiplierByMiscMask(), Unit::GetTotalAuraMultiplierByMiscValue(), spell_pri_shadow_word_death::HandleDamage(), spell_sha_healing_stream_totem::HandleDummy(), spell_dk_raise_ally::HandleDummy(), spell_dk_death_strike::HandleDummy(), spell_dk_scourge_strike::HandleDummy(), spell_sha_lava_lash::HandleDummy(), spell_warl_life_tap::HandleDummy(), Unit::HandleDummyAuraProc(), spell_pri_prayer_of_mending_heal::HandleHeal(), AuraEffect::HandlePeriodicHealAurasTick(), spell_hun_ascpect_of_the_viper::HandleProc(), spell_pal_sacred_shield_base::HandleProc(), Unit::MeleeDamageBonusDone(), Unit::MeleeDamageBonusTaken(), Unit::ModSpellDuration(), spell_warl_siphon_life::OnProc(), Unit::processDummyAuras(), spell_dk_death_and_decay::RecalculateDamage(), spell_gen_reduced_above_60::RecalculateDamage(), Creature::Regenerate(), Player::Regenerate(), Creature::RegenerateHealth(), Player::RegenerateHealth(), Player::RewardHonor(), Player::RewardQuest(), Unit::RewardRage(), Battleground::RewardReputationToTeam(), Unit::SpellCriticalDamageBonus(), Unit::SpellDamageBonusDone(), Unit::SpellDamageBonusTaken(), Unit::SpellHealingBonusDone(), Unit::SpellHealingBonusTaken(), Unit::SpellPctDamageModsDone(), Unit::SpellPctHealingModsDone(), and Unit::UpdateSpeed().

◆ ApplyPct()

◆ ApplyPercentModFloatVar()

void ApplyPercentModFloatVar ( float &  var,
float  val,
bool  apply 
)
inline
51{
52 if (val == -100.0f) // prevent set var to zero
53 {
54 val = -99.99f;
55 }
56 var *= (apply ? (100.0f + val) / 100.0f : 100.0f / (100.0f + val));
57}
void apply(T *val)
Definition: ByteConverter.h:40

Referenced by Unit::ApplyAttackTimePercentMod(), Object::ApplyPercentModFloatValue(), Player::HandleBaseModValue(), AuraEffect::HandleModThreat(), Unit::HandleStatModifier(), and Unit::ModifyPowerPct().

◆ AsUnderlyingType()

template<typename E >
constexpr std::underlying_type< E >::type AsUnderlyingType ( enumValue)
constexpr
620{
621 static_assert(std::is_enum<E>::value, "AsUnderlyingType can only be used with enums");
622 return static_cast<typename std::underlying_type<E>::type>(enumValue);
623}

Referenced by SmartAIMgr::IsEventValid(), ObjectMgr::LoadCreatureAddons(), ObjectMgr::LoadCreatureTemplateAddons(), WorldObject::SetVisibilityDistanceOverride(), and CreatureMovementData::ToString().

◆ ByteArrayToHexStr()

template<typename Container >
std::string ByteArrayToHexStr ( Container const &  c,
bool  reverse = false 
)
382{
383 return Acore::Impl::ByteArrayToHexStr(std::data(c), std::size(c), reverse);
384}
AC_COMMON_API std::string ByteArrayToHexStr(uint8 const *bytes, size_t length, bool reverse=false)
Definition: Util.cpp:541

References Acore::Impl::ByteArrayToHexStr().

Referenced by WardenMac::Init(), WardenWin::Init(), and UpdateFetcher::Update().

◆ CalculatePct()

template<class T , class U >
T CalculatePct ( base,
pct 
)
inline
62{
63 return T(base * static_cast<float>(pct) / 100.0f);
64}

Referenced by spell_shield_generator::spell_shield_generator_AuraScript::Absorb(), spell_charge_shield_bomber::spell_charge_shield_bomber_AuraScript::Absorb(), spell_dk_anti_magic_shell_raid::Absorb(), spell_dk_anti_magic_shell_self::Absorb(), spell_dk_anti_magic_zone::Absorb(), spell_dk_spell_deflection::Absorb(), spell_dk_will_of_the_necropolis::Absorb(), spell_dru_moonkin_form_passive::Absorb(), spell_dru_primal_tenacity::Absorb(), spell_rog_nerves_of_steel::Absorb(), spell_sha_astral_shift::Absorb(), spell_dru_savage_defense::Absorb(), spell_pal_ardent_defender::Absorb(), AddPct(), ApplyPct(), Player::ApplySpellMod(), Unit::CalcAbsorbResist(), Unit::CalcArmorReducedDamage(), SpellInfo::CalcPowerCost(), spell_mark_of_kazzak::spell_mark_of_kazzak_AuraScript::CalculateAmount(), spell_dru_owlkin_frenzy::CalculateAmount(), spell_dru_rip::CalculateAmount(), spell_dru_innervate::CalculateAmount(), spell_gen_lifeblood::CalculateAmount(), spell_pal_sacred_shield_base::CalculateAmount(), spell_warl_demonic_knowledge::CalculateAmount(), spell_dru_treant_scaling::CalculateAPAmount(), spell_hun_generic_scaling::CalculateAPAmount(), spell_pri_shadowfiend_scaling::CalculateAPAmount(), spell_sha_feral_spirit_scaling::CalculateAPAmount(), spell_sha_fire_elemental_scaling::CalculateAPAmount(), spell_warl_generic_scaling::CalculateAPAmount(), spell_warl_infernal_scaling::CalculateAPAmount(), Player::CalculateReputationGain(), spell_dru_treant_scaling::CalculateResistanceAmount(), spell_hun_generic_scaling::CalculateResistanceAmount(), spell_mage_pet_scaling::CalculateResistanceAmount(), spell_pri_shadowfiend_scaling::CalculateResistanceAmount(), spell_sha_feral_spirit_scaling::CalculateResistanceAmount(), spell_sha_fire_elemental_scaling::CalculateResistanceAmount(), spell_warl_generic_scaling::CalculateResistanceAmount(), spell_warl_infernal_scaling::CalculateResistanceAmount(), spell_dk_pet_scaling::CalculateSPAmount(), spell_dru_treant_scaling::CalculateSPAmount(), spell_hun_generic_scaling::CalculateSPAmount(), spell_mage_pet_scaling::CalculateSPAmount(), spell_pri_shadowfiend_scaling::CalculateSPAmount(), spell_sha_feral_spirit_scaling::CalculateSPAmount(), spell_sha_fire_elemental_scaling::CalculateSPAmount(), spell_warl_generic_scaling::CalculateSPAmount(), spell_warl_infernal_scaling::CalculateSPAmount(), CalculateSpellAmount(), spell_dk_pet_scaling::CalculateStatAmount(), spell_dru_treant_scaling::CalculateStatAmount(), spell_hun_generic_scaling::CalculateStatAmount(), spell_mage_pet_scaling::CalculateStatAmount(), spell_pri_shadowfiend_scaling::CalculateStatAmount(), spell_sha_feral_spirit_scaling::CalculateStatAmount(), spell_sha_fire_elemental_scaling::CalculateStatAmount(), spell_warl_generic_scaling::CalculateStatAmount(), spell_warl_infernal_scaling::CalculateStatAmount(), Unit::CountPctFromCurHealth(), Unit::CountPctFromMaxHealth(), Unit::DealDamage(), Spell::DelayedChannel(), ThreatMgr::DoAddThreat(), Spell::EffectDestroyAllTotems(), Spell::EffectEnergize(), Spell::EffectEnergizePct(), Spell::EffectPowerBurn(), Spell::EffectResurrect(), Spell::EffectSchoolDMG(), Spell::EffectSelfResurrect(), AuctionEntry::GetAuctionCut(), AuctionHouseMgr::GetAuctionDeposit(), AuctionEntry::GetAuctionOutBid(), Unit::GetCombatRatingDamageReduction(), spell_mt_phoenix_burn::spell_mt_phoenix_burn_SpellScript::HandleAfterCast(), spell_illidari_council_empyreal_balance::spell_illidari_council_empyreal_balance_SpellScript::HandleAfterCast(), spell_sha_totem_of_wrath::HandleAfterCast(), spell_warl_haunt::HandleAfterHit(), AuraEffect::HandleAuraModIncreaseHealthPercent(), Unit::HandleAuraProc(), Aura::HandleAuraSpecificMods(), spell_dru_lifebloom::HandleDispel(), spell_dk_raise_ally::HandleDummy(), spell_sha_mana_tide_totem::HandleDummy(), spell_warr_concussion_blow::HandleDummy(), Unit::HandleDummyAuraProc(), AuraEffect::HandleModPowerCostPCT(), AuraEffect::HandlePeriodicManaLeechAuraTick(), spell_mage_ignite::HandleProc(), spell_hun_ascpect_of_the_viper::HandleProc(), spell_yogg_saron_grim_reprisal::spell_yogg_saron_grim_reprisal_AuraScript::HandleProc(), spell_dru_t10_balance_4p_bonus::HandleProc(), spell_dru_living_seed::HandleProc(), spell_item_blessing_of_ancient_kings::HandleProc(), spell_item_necrotic_touch::HandleProc(), spell_mage_burnout::HandleProc(), spell_mage_master_of_elements::HandleProc(), spell_pri_divine_aegis::HandleProc(), spell_pri_glyph_of_prayer_of_healing::HandleProc(), spell_sha_t10_restoration_4p_bonus::HandleProc(), spell_sha_item_mana_surge::HandleProc(), spell_warl_drain_soul::HandleProc(), Unit::HandleProcTriggerSpell(), spell_hun_chimera_shot::HandleScriptEffect(), boss_curator::JustEngagedWith(), spell_valanar_kinetic_bomb_absorb::spell_valanar_kinetic_bomb_absorb_AuraScript::OnAbsorb(), spell_blood_queen_essence_of_the_blood_queen::spell_blood_queen_essence_of_the_blood_queen_AuraScript::OnProc(), spell_pal_eye_for_an_eye::OnProc(), spell_warl_siphon_life::OnProc(), spell_warl_fel_synergy::OnProc(), spell_warr_damage_shield::OnProc(), spell_item_oracle_ablutions::PrepareSpellScript(), spell_pilgrims_bounty_food_aura::RecalculateHook(), Unit::RecalculateObjectScale(), spell_pri_power_word_shield_aura::ReflectDamage(), OPvPCapturePoint::SetCapturePointData(), Unit::SpellBaseDamageBonusDone(), Unit::SpellBaseHealingBonusDone(), spell_dk_anti_magic_shell_self::Trigger(), spell_mage_incanters_absorbtion_base_AuraScript::Trigger(), Player::UpdateArmor(), Player::UpdateAttackPowerAndDamage(), Player::UpdateManaRegen(), and Player::UpdateRating().

◆ charToLower()

char charToLower ( char  c)
inline
276{ return std::tolower(c); }

Referenced by strToLower().

◆ charToUpper()

char charToUpper ( char  c)
inline
275{ return std::toupper(c); }

Referenced by strToUpper().

◆ Coalesce()

template<typename Ret , typename T1 , typename... T>
Ret * Coalesce ( T1 *  first,
T *...  rest 
)
627{
628 if constexpr (sizeof...(T) > 0)
629 return (first ? static_cast<Ret*>(first) : Coalesce<Ret>(rest...));
630 else
631 return static_cast<Ret*>(first);
632}

◆ CompareValues()

template<class T >
bool CompareValues ( ComparisionType  type,
val1,
val2 
)
598{
599 switch (type)
600 {
601 case COMP_TYPE_EQ:
602 return val1 == val2;
603 case COMP_TYPE_HIGH:
604 return val1 > val2;
605 case COMP_TYPE_LOW:
606 return val1 < val2;
608 return val1 >= val2;
609 case COMP_TYPE_LOW_EQ:
610 return val1 <= val2;
611 default:
612 // incorrect parameter
613 ABORT();
614 return false;
615 }
616}
#define ABORT
Definition: Errors.h:76

References ABORT, COMP_TYPE_EQ, COMP_TYPE_HIGH, COMP_TYPE_HIGH_EQ, COMP_TYPE_LOW, and COMP_TYPE_LOW_EQ.

Referenced by Condition::Meets(), and AchievementCriteriaData::Meets().

◆ consoleToUtf8()

AC_COMMON_API bool consoleToUtf8 ( std::string_view  conStr,
std::string &  utf8str 
)
463{
464#if AC_PLATFORM == AC_PLATFORM_WINDOWS
465 std::wstring wstr;
466 wstr.resize(conStr.size());
467 OemToCharBuffW(&conStr[0], &wstr[0], uint32(conStr.size()));
468
469 return WStrToUtf8(wstr, utf8str);
470#else
471 // not implemented yet
472 utf8str = conStr;
473 return true;
474#endif
475}
std::uint32_t uint32
Definition: Define.h:108
bool WStrToUtf8(wchar_t const *wstr, size_t size, std::string &utf8str)
Definition: Util.cpp:334

References WStrToUtf8().

Referenced by Acore::ACLogSink< T >::write().

◆ CreatePIDFile()

uint32 CreatePIDFile ( const std::string &  filename)

create PID file

220{
221 FILE* pid_file = fopen(filename.c_str(), "w");
222 if (!pid_file)
223 {
224 return 0;
225 }
226
227 uint32 pid = GetPID();
228
229 fprintf(pid_file, "%u", pid);
230 fclose(pid_file);
231
232 return pid;
233}
uint32 GetPID()
Definition: Util.cpp:235

References GetPID().

Referenced by main().

◆ GetMainPartOfName()

std::wstring GetMainPartOfName ( std::wstring const &  wname,
uint32  declension 
)
388{
389 // supported only Cyrillic cases
390 if (wname.empty() || !isCyrillicCharacter(wname[0]) || declension > 5)
391 {
392 return wname;
393 }
394
395 // Important: end length must be <= MAX_INTERNAL_PLAYER_NAME-MAX_PLAYER_NAME (3 currently)
396 static std::wstring const a_End = { wchar_t(0x0430), wchar_t(0x0000) };
397 static std::wstring const o_End = { wchar_t(0x043E), wchar_t(0x0000) };
398 static std::wstring const ya_End = { wchar_t(0x044F), wchar_t(0x0000) };
399 static std::wstring const ie_End = { wchar_t(0x0435), wchar_t(0x0000) };
400 static std::wstring const i_End = { wchar_t(0x0438), wchar_t(0x0000) };
401 static std::wstring const yeru_End = { wchar_t(0x044B), wchar_t(0x0000) };
402 static std::wstring const u_End = { wchar_t(0x0443), wchar_t(0x0000) };
403 static std::wstring const yu_End = { wchar_t(0x044E), wchar_t(0x0000) };
404 static std::wstring const oj_End = { wchar_t(0x043E), wchar_t(0x0439), wchar_t(0x0000) };
405 static std::wstring const ie_j_End = { wchar_t(0x0435), wchar_t(0x0439), wchar_t(0x0000) };
406 static std::wstring const io_j_End = { wchar_t(0x0451), wchar_t(0x0439), wchar_t(0x0000) };
407 static std::wstring const o_m_End = { wchar_t(0x043E), wchar_t(0x043C), wchar_t(0x0000) };
408 static std::wstring const io_m_End = { wchar_t(0x0451), wchar_t(0x043C), wchar_t(0x0000) };
409 static std::wstring const ie_m_End = { wchar_t(0x0435), wchar_t(0x043C), wchar_t(0x0000) };
410 static std::wstring const soft_End = { wchar_t(0x044C), wchar_t(0x0000) };
411 static std::wstring const j_End = { wchar_t(0x0439), wchar_t(0x0000) };
412
413 static std::array<std::array<std::wstring const*, 7>, 6> const dropEnds = {{
414 { &a_End, &o_End, &ya_End, &ie_End, &soft_End, &j_End, nullptr },
415 { &a_End, &ya_End, &yeru_End, &i_End, nullptr, nullptr, nullptr },
416 { &ie_End, &u_End, &yu_End, &i_End, nullptr, nullptr, nullptr },
417 { &u_End, &yu_End, &o_End, &ie_End, &soft_End, &ya_End, &a_End },
418 { &oj_End, &io_j_End, &ie_j_End, &o_m_End, &io_m_End, &ie_m_End, &yu_End },
419 { &ie_End, &i_End, nullptr, nullptr, nullptr, nullptr, nullptr }
420 }
421 };
422
423 std::size_t const thisLen = wname.length();
424 std::array<std::wstring const*, 7> const& endings = dropEnds[declension];
425 for (auto itr = endings.begin(), end = endings.end(); (itr != end) && *itr; ++itr)
426 {
427 std::wstring const& ending = **itr;
428 std::size_t const endLen = ending.length();
429 if (endLen > thisLen)
430 {
431 continue;
432 }
433
434 if (wname.substr(thisLen - endLen, thisLen) == ending)
435 {
436 return wname.substr(0, thisLen - endLen);
437 }
438 }
439
440 return wname;
441}
bool isCyrillicCharacter(wchar_t wchar)
Definition: Util.h:154

References isCyrillicCharacter().

Referenced by ObjectMgr::CheckDeclinedNames().

◆ GetPID()

uint32 GetPID ( )
236{
237#ifdef _WIN32
238 DWORD pid = GetCurrentProcessId();
239#else
240 pid_t pid = getpid();
241#endif
242
243 return uint32(pid);
244}

Referenced by CreatePIDFile().

◆ GetTypeName() [1/3]

template<typename T >
std::string GetTypeName ( )
637{ return GetTypeName(typeid(T)); }
std::string GetTypeName()
Definition: Util.h:637

References GetTypeName().

Referenced by GetTypeName().

◆ GetTypeName() [2/3]

AC_COMMON_API std::string GetTypeName ( std::type_info const &  info)
605{
606 return boost::core::demangle(info.name());
607}

◆ GetTypeName() [3/3]

template<typename T >
std::enable_if_t<!std::is_same_v< std::decay_t< T >, std::type_info >, std::string > GetTypeName ( T &&  v)
640{ return GetTypeName(typeid(v)); }

References GetTypeName().

◆ HexStrToByteArray() [1/2]

template<size_t Size>
std::array< uint8, Size > HexStrToByteArray ( std::string_view  str,
bool  reverse = false 
)
394{
395 std::array<uint8, Size> arr;
396 HexStrToByteArray(str, arr, reverse);
397 return arr;
398}
void HexStrToByteArray(std::string_view str, std::array< uint8, Size > &buf, bool reverse=false)
Definition: Util.h:387

References HexStrToByteArray().

◆ HexStrToByteArray() [2/2]

template<size_t Size>
void HexStrToByteArray ( std::string_view  str,
std::array< uint8, Size > &  buf,
bool  reverse = false 
)
388{
389 Acore::Impl::HexStrToByteArray(str, buf.data(), Size, reverse);
390}
AC_COMMON_API void HexStrToByteArray(std::string_view str, uint8 *out, size_t outlen, bool reverse=false)
Definition: Util.cpp:565

References Acore::Impl::HexStrToByteArray().

Referenced by HexStrToByteArray(), and RealmList::LoadBuildInfo().

◆ isBasicLatinCharacter()

bool isBasicLatinCharacter ( wchar_t  wchar)
inline
105{
106 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
107 {
108 return true;
109 }
110 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
111 {
112 return true;
113 }
114 return false;
115}

Referenced by isBasicLatinString(), isExtendedLatinCharacter(), and wcharToUpperOnlyLatin().

◆ isBasicLatinString()

bool isBasicLatinString ( std::wstring_view  wstr,
bool  numericOrSpace 
)
inline
236{
237 for (wchar_t i : wstr)
238 if (!isBasicLatinCharacter(i) && (!numericOrSpace || !isNumericOrSpace(i)))
239 {
240 return false;
241 }
242 return true;
243}
bool isNumericOrSpace(wchar_t wchar)
Definition: Util.h:230
bool isBasicLatinCharacter(wchar_t wchar)
Definition: Util.h:104

References isBasicLatinCharacter(), and isNumericOrSpace().

Referenced by isValidString().

◆ isCyrillicCharacter()

bool isCyrillicCharacter ( wchar_t  wchar)
inline
155{
156 if (wchar >= 0x0410 && wchar <= 0x044F) // CYRILLIC CAPITAL LETTER A - CYRILLIC SMALL LETTER YA
157 {
158 return true;
159 }
160 if (wchar == 0x0401 || wchar == 0x0451) // CYRILLIC CAPITAL LETTER IO, CYRILLIC SMALL LETTER IO
161 {
162 return true;
163 }
164 return false;
165}

Referenced by GetMainPartOfName(), WorldSession::HandleSetPlayerDeclinedNames(), and isCyrillicString().

◆ isCyrillicString()

bool isCyrillicString ( std::wstring_view  wstr,
bool  numericOrSpace 
)
inline
256{
257 for (wchar_t i : wstr)
258 if (!isCyrillicCharacter(i) && (!numericOrSpace || !isNumericOrSpace(i)))
259 {
260 return false;
261 }
262 return true;
263}

References isCyrillicCharacter(), and isNumericOrSpace().

Referenced by isValidString().

◆ isEastAsianCharacter()

bool isEastAsianCharacter ( wchar_t  wchar)
inline
168{
169 if (wchar >= 0x1100 && wchar <= 0x11F9) // Hangul Jamo
170 {
171 return true;
172 }
173 if (wchar >= 0x3041 && wchar <= 0x30FF) // Hiragana + Katakana
174 {
175 return true;
176 }
177 if (wchar >= 0x3131 && wchar <= 0x318E) // Hangul Compatibility Jamo
178 {
179 return true;
180 }
181 if (wchar >= 0x31F0 && wchar <= 0x31FF) // Katakana Phonetic Ext.
182 {
183 return true;
184 }
185 if (wchar >= 0x3400 && wchar <= 0x4DB5) // CJK Ideographs Ext. A
186 {
187 return true;
188 }
189 if (wchar >= 0x4E00 && wchar <= 0x9FC3) // Unified CJK Ideographs
190 {
191 return true;
192 }
193 if (wchar >= 0xAC00 && wchar <= 0xD7A3) // Hangul Syllables
194 {
195 return true;
196 }
197 if (wchar >= 0xFF01 && wchar <= 0xFFEE) // Halfwidth forms
198 {
199 return true;
200 }
201 return false;
202}

Referenced by isEastAsianString().

◆ isEastAsianString()

bool isEastAsianString ( std::wstring_view  wstr,
bool  numericOrSpace 
)
inline
266{
267 for (wchar_t i : wstr)
268 if (!isEastAsianCharacter(i) && (!numericOrSpace || !isNumericOrSpace(i)))
269 {
270 return false;
271 }
272 return true;
273}
bool isEastAsianCharacter(wchar_t wchar)
Definition: Util.h:167

References isEastAsianCharacter(), and isNumericOrSpace().

Referenced by isValidString().

◆ IsEvenNumber()

bool IsEvenNumber ( int32  n)
inline
215{
216 return n % 2 == 0;
217}

Referenced by boss_mechano_lord_capacitus::JustEngagedWith().

◆ isExtendedLatinCharacter()

bool isExtendedLatinCharacter ( wchar_t  wchar)
inline
118{
119 if (isBasicLatinCharacter(wchar))
120 {
121 return true;
122 }
123 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
124 {
125 return true;
126 }
127 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
128 {
129 return true;
130 }
131 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
132 {
133 return true;
134 }
135 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
136 {
137 return true;
138 }
139 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
140 {
141 return true;
142 }
143 if (wchar >= 0x0100 && wchar <= 0x012F) // LATIN CAPITAL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK
144 {
145 return true;
146 }
147 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
148 {
149 return true;
150 }
151 return false;
152}

References isBasicLatinCharacter().

Referenced by isExtendedLatinString().

◆ isExtendedLatinString()

bool isExtendedLatinString ( std::wstring_view  wstr,
bool  numericOrSpace 
)
inline
246{
247 for (wchar_t i : wstr)
248 if (!isExtendedLatinCharacter(i) && (!numericOrSpace || !isNumericOrSpace(i)))
249 {
250 return false;
251 }
252 return true;
253}
bool isExtendedLatinCharacter(wchar_t wchar)
Definition: Util.h:117

References isExtendedLatinCharacter(), and isNumericOrSpace().

Referenced by isValidString().

◆ IsIPAddress()

bool IsIPAddress ( char const *  ipaddress)

Check if the string is a valid ip address representation.

207{
208 if (!ipaddress)
209 {
210 return false;
211 }
212
213 boost::system::error_code error;
214 Acore::Net::make_address(ipaddress, error);
215 return !error;
216}
boost::asio::ip::address make_address(char const *str)
Definition: IpAddress.h:31

References Acore::Net::make_address().

Referenced by ban_commandscript::HandleBanHelper(), ban_commandscript::HandleBanInfoIPCommand(), and ban_commandscript::HandleUnBanHelper().

◆ isNumeric() [1/3]

bool isNumeric ( char  c)
inline
210{
211 return (c >= '0' && c <= '9');
212}

◆ isNumeric() [2/3]

bool isNumeric ( char const *  str)
inline
220{
221 for (char const* c = str; *c; ++c)
222 if (!isNumeric(*c))
223 {
224 return false;
225 }
226
227 return true;
228}
bool isNumeric(wchar_t wchar)
Definition: Util.h:204

References isNumeric().

◆ isNumeric() [3/3]

bool isNumeric ( wchar_t  wchar)
inline

◆ isNumericOrSpace()

bool isNumericOrSpace ( wchar_t  wchar)
inline
231{
232 return isNumeric(wchar) || wchar == L' ';
233}

References isNumeric().

Referenced by isBasicLatinString(), isCyrillicString(), isEastAsianString(), and isExtendedLatinString().

◆ MoneyStringToMoney()

AC_COMMON_API Optional< int32 > MoneyStringToMoney ( std::string_view  moneyString)
110{
111 int32 money = 0;
112
113 bool hadG = false;
114 bool hadS = false;
115 bool hadC = false;
116
117 for (std::string_view token : Acore::Tokenize(moneyString, ' ', false))
118 {
119 uint32 unit;
120 switch (token[token.length() - 1])
121 {
122 case 'g':
123 if (hadG)
124 {
125 return std::nullopt;
126 }
127 hadG = true;
128 unit = 100 * 100;
129 break;
130 case 's':
131 if (hadS)
132 {
133 return std::nullopt;
134 }
135 hadS = true;
136 unit = 100;
137 break;
138 case 'c':
139 if (hadC)
140 {
141 return std::nullopt;
142 }
143 hadC = true;
144 unit = 1;
145 break;
146 default:
147 return std::nullopt;
148 }
149
150 Optional<uint32> amount = Acore::StringTo<uint32>(token.substr(0, token.length() - 1));
151 if (amount)
152 {
153 money += (unit * *amount);
154 }
155 else
156 {
157 return std::nullopt;
158 }
159 }
160
161 return money;
162}
std::int32_t int32
Definition: Define.h:104
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition: Tokenize.cpp:20

References Acore::Tokenize().

Referenced by modify_commandscript::HandleModifyMoneyCommand().

◆ RoundToInterval()

template<class T >
T RoundToInterval ( T &  num,
floor,
ceil 
)
inline
80{
81 return num = std::min<T>(std::max<T>(num, floor), ceil);
82}

Referenced by Unit::CalcAbsorbResist(), and npc_echo_of_medivh::HandlePieceMoveByAI().

◆ secsToTimeString()

std::string secsToTimeString ( uint64  timeInSecs,
bool  shortText = false 
)
75{
76 uint64 secs = timeInSecs % MINUTE;
77 uint64 minutes = timeInSecs % HOUR / MINUTE;
78 uint64 hours = timeInSecs % DAY / HOUR;
79 uint64 days = timeInSecs / DAY;
80
81 std::ostringstream ss;
82 if (days)
83 {
84 ss << days << (shortText ? "d" : " day(s) ");
85 }
86 if (hours)
87 {
88 ss << hours << (shortText ? "h" : " hour(s) ");
89 }
90 if (minutes)
91 {
92 ss << minutes << (shortText ? "m" : " minute(s) ");
93 }
94 if (secs || (!days && !hours && !minutes) )
95 {
96 ss << secs << (shortText ? "s" : " second(s) ");
97 }
98
99 std::string str = ss.str();
100
101 if (!shortText && !str.empty() && str[str.size() - 1] == ' ')
102 {
103 str.resize(str.size() - 1);
104 }
105
106 return str;
107}
constexpr auto DAY
Definition: Common.h:58
constexpr auto HOUR
Definition: Common.h:57
constexpr auto MINUTE
Definition: Common.h:56
std::uint64_t uint64
Definition: Define.h:107

References DAY, HOUR, and MINUTE.

Referenced by BanMgr::BanAccount(), BanMgr::BanAccountByPlayerName(), BanMgr::BanCharacter(), BanMgr::BanIP(), GmTicket::FormatMessageString(), ban_commandscript::HandleBanCharacterCommand(), ban_commandscript::HandleBanHelper(), ban_commandscript::HandleBanInfoCharacterCommand(), ban_commandscript::HandleBanInfoHelper(), ban_commandscript::HandleBanInfoIPCommand(), deserter_commandscript::HandleDeserterAdd(), deserter_commandscript::HandleDeserterRemove(), deserter_commandscript::HandleDeserterRemoveAll(), event_commandscript::HandleEventInfoCommand(), gobject_commandscript::HandleGameObjectTargetCommand(), instance_commandscript::HandleInstanceListBindsCommand(), instance_commandscript::HandleInstanceUnbindCommand(), WorldSession::HandleMessagechatOpcode(), misc_commandscript::HandleMuteCommand(), npc_commandscript::HandleNpcInfoCommand(), npc_commandscript::HandleNpcSetSpawnTimeCommand(), misc_commandscript::HandlePInfoCommand(), server_commandscript::HandleServerInfoCommand(), WorldSession::HandleTextEmoteOpcode(), main(), GmTicket::SetChatLog(), and World::ShutdownMsg().

◆ StringCompareLessI()

AC_COMMON_API bool StringCompareLessI ( std::string_view  a,
std::string_view  b 
)
600{
601 return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), [](char c1, char c2) { return std::tolower(c1) < std::tolower(c2); });
602}

Referenced by StringCompareLessI_T::operator()().

◆ StringContainsStringI()

AC_COMMON_API bool StringContainsStringI ( std::string_view  haystack,
std::string_view  needle 
)
594{
595 return haystack.end() !=
596 std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), [](char c1, char c2) { return std::tolower(c1) == std::tolower(c2); });
597}

Referenced by arena_commandscript::HandleArenaLookupCommand(), and ValueContainsStringI().

◆ StringEqualI()

◆ StringStartsWith()

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

◆ StringStartsWithI()

bool StringStartsWithI ( std::string_view  haystack,
std::string_view  needle 
)
inline
402{ return StringEqualI(haystack.substr(0, needle.length()), needle); }
AC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2)
Definition: Util.cpp:588

References StringEqualI().

Referenced by Acore::Impl::ChatCommands::FilteredCommandListIterator::_skip(), and Acore::Impl::ChatCommands::ArgInfo< T, std::enable_if_t< std::is_enum_v< T > > >::Match().

◆ stripLineInvisibleChars()

void stripLineInvisibleChars ( std::string &  src)
34{
35 static std::string const invChars = " \t\7\n";
36
37 size_t wpos = 0;
38
39 bool space = false;
40 for (size_t pos = 0; pos < str.size(); ++pos)
41 {
42 if (invChars.find(str[pos]) != std::string::npos)
43 {
44 if (!space)
45 {
46 str[wpos++] = ' ';
47 space = true;
48 }
49 }
50 else
51 {
52 if (wpos != pos)
53 {
54 str[wpos++] = str[pos];
55 }
56 else
57 {
58 ++wpos;
59 }
60 space = false;
61 }
62 }
63
64 if (wpos < str.size())
65 {
66 str.erase(wpos, str.size());
67 }
68 if (str.find("|TInterface") != std::string::npos)
69 {
70 str.clear();
71 }
72}

◆ TimeStringToSecs()

uint32 TimeStringToSecs ( const std::string &  timestring)
165{
166 uint32 secs = 0;
167 uint32 buffer = 0;
168 uint32 multiplier = 0;
169
170 for (std::string::const_iterator itr = timestring.begin(); itr != timestring.end(); ++itr)
171 {
172 if (isdigit(*itr))
173 {
174 buffer *= 10;
175 buffer += (*itr) - '0';
176 }
177 else
178 {
179 switch (*itr)
180 {
181 case 'd':
182 multiplier = DAY;
183 break;
184 case 'h':
185 multiplier = HOUR;
186 break;
187 case 'm':
188 multiplier = MINUTE;
189 break;
190 case 's':
191 multiplier = 1;
192 break;
193 default :
194 return 0; //bad format
195 }
196 buffer *= multiplier;
197 secs += buffer;
198 buffer = 0;
199 }
200 }
201
202 return secs;
203}

References DAY, HOUR, and MINUTE.

Referenced by BanMgr::BanAccount(), BanMgr::BanAccountByPlayerName(), BanMgr::BanCharacter(), BanMgr::BanIP(), ban_commandscript::HandleBanCharacterCommand(), ban_commandscript::HandleBanHelper(), bf_commandscript::HandleBattlefieldTimer(), deserter_commandscript::HandleDeserterAdd(), deserter_commandscript::HandleDeserterRemoveAll(), misc_commandscript::HandleMuteCommand(), npc_commandscript::HandleNpcSetSpawnTimeCommand(), server_commandscript::HandleServerIdleRestartCommand(), server_commandscript::HandleServerIdleShutDownCommand(), server_commandscript::HandleServerRestartCommand(), and server_commandscript::HandleServerShutDownCommand().

◆ Utf8FitTo()

◆ utf8length()

size_t utf8length ( std::string &  utf8str)
247{
248 try
249 {
250 return utf8::distance(utf8str.c_str(), utf8str.c_str() + utf8str.size());
251 }
252 catch (std::exception const&)
253 {
254 utf8str.clear();
255 return 0;
256 }
257}

Referenced by AccountMgr::ChangePassword(), AccountMgr::ChangeUsername(), and AccountMgr::CreateAccount().

◆ utf8printf()

AC_COMMON_API void utf8printf ( FILE *  out,
const char *  str,
  ... 
)
498{
499 va_list ap;
500 va_start(ap, str);
501 vutf8printf(out, str, &ap);
502 va_end(ap);
503}
void vutf8printf(FILE *out, const char *str, va_list *ap)
Definition: Util.cpp:505

References vutf8printf().

Referenced by AppenderConsole::_write().

◆ utf8ToConsole()

AC_COMMON_API bool utf8ToConsole ( std::string_view  utf8str,
std::string &  conStr 
)
444{
445#if AC_PLATFORM == AC_PLATFORM_WINDOWS
446 std::wstring wstr;
447 if (!Utf8toWStr(utf8str, wstr))
448 {
449 return false;
450 }
451
452 conStr.resize(wstr.size());
453 CharToOemBuffW(&wstr[0], &conStr[0], wstr.size());
454#else
455 // not implemented yet
456 conStr = utf8str;
457#endif
458
459 return true;
460}

References Utf8toWStr().

◆ Utf8ToUpperOnlyLatin()

◆ Utf8toWStr() [1/3]

AC_COMMON_API bool Utf8toWStr ( char const *  utf8str,
size_t  csize,
wchar_t *  wstr,
size_t &  wsize 
)
283{
284 try
285 {
287 out = utf8::utf8to16(utf8str, utf8str + csize, out);
288 wsize -= out.remaining(); // remaining unused space
289 wstr[wsize] = L'\0';
290 }
291 catch (std::exception const&)
292 {
293 // Replace the converted string with an error message if there is enough space
294 // Otherwise just return an empty string
295 const wchar_t* errorMessage = L"An error occurred converting string from UTF-8 to WStr";
296 std::size_t errorMessageLength = std::char_traits<wchar_t>::length(errorMessage);
297 if (wsize >= errorMessageLength)
298 {
299 std::wcscpy(wstr, errorMessage);
300 wsize = std::char_traits<wchar_t>::length(wstr);
301 }
302 else if (wsize > 0)
303 {
304 wstr[0] = L'\0';
305 wsize = 0;
306 }
307 else
308 {
309 wsize = 0;
310 }
311
312 return false;
313 }
314
315 return true;
316}
Definition: Containers.h:46

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

Referenced by ObjectMgr::AddGameTele(), ObjectMgr::AddProfanityPlayerName(), ObjectMgr::AddReservedPlayerName(), ObjectMgr::CheckDeclinedNames(), ObjectMgr::CheckPetName(), ObjectMgr::CheckPlayerName(), ObjectMgr::DeleteGameTele(), AuctionListItemsDelayEvent::Execute(), ChannelMgr::GetChannel(), ObjectMgr::GetGameTele(), Graveyard::GetGraveyard(), ChannelMgr::GetJoinChannel(), 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(), server_commandscript::HandleServerIdleRestartCommand(), server_commandscript::HandleServerIdleShutDownCommand(), server_commandscript::HandleServerRestartCommand(), server_commandscript::HandleServerSetMotdCommand(), server_commandscript::HandleServerShutDownCommand(), WorldSession::HandleSetPlayerDeclinedNames(), WorldSession::HandleWhoOpcode(), ObjectMgr::IsProfanityName(), ObjectMgr::IsReservedName(), ObjectMgr::IsValidChannelName(), ObjectMgr::IsValidCharterName(), ChannelMgr::LoadChannels(), ObjectMgr::LoadGameTele(), Graveyard::LoadGraveyardFromDB(), ObjectMgr::LoadProfanityPlayersNames(), ObjectMgr::LoadReservedPlayersNames(), normalizePlayerName(), ProfanityNames(), ReservedNames(), Acore::ChatCommands::WTail::TryConsume(), Acore::Impl::ChatCommands::ArgInfo< std::wstring, void >::TryConsume(), WhoListCacheMgr::Update(), Utf8FitTo(), utf8ToConsole(), Utf8ToUpperOnlyLatin(), and vutf8printf().

◆ Utf8toWStr() [2/3]

AC_COMMON_API bool Utf8toWStr ( std::string_view  utf8str,
std::wstring &  wstr 
)
319{
320 wstr.clear();
321 try
322 {
323 utf8::utf8to16(utf8str.begin(), utf8str.end(), std::back_inserter(wstr));
324 }
325 catch (std::exception const&)
326 {
327 wstr.clear();
328 return false;
329 }
330
331 return true;
332}

Referenced by Utf8toWStr().

◆ Utf8toWStr() [3/3]

bool Utf8toWStr ( std::string_view  utf8str,
wchar_t *  wstr,
size_t &  wsize 
)
inline
91{
92 return Utf8toWStr(utf8str.data(), utf8str.size(), wstr, wsize);
93}
AC_COMMON_API bool Utf8toWStr(std::string_view utf8str, std::wstring &wstr)
Definition: Util.cpp:318

References Utf8toWStr().

◆ utf8truncate()

void utf8truncate ( std::string &  utf8str,
size_t  len 
)
260{
261 try
262 {
263 size_t wlen = utf8::distance(utf8str.c_str(), utf8str.c_str() + utf8str.size());
264 if (wlen <= len)
265 {
266 return;
267 }
268
269 std::wstring wstr;
270 wstr.resize(wlen);
271 utf8::utf8to16(utf8str.c_str(), utf8str.c_str() + utf8str.size(), &wstr[0]);
272 wstr.resize(len);
273 char* oend = utf8::utf16to8(wstr.c_str(), wstr.c_str() + wstr.size(), &utf8str[0]);
274 utf8str.resize(oend - (&utf8str[0])); // remove unused tail
275 }
276 catch (std::exception const&)
277 {
278 utf8str.clear();
279 }
280}

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

◆ ValueContainsStringI()

template<typename T >
bool ValueContainsStringI ( std::pair< T, std::string_view > const &  haystack,
std::string_view  needle 
)
inline
407{
408 return StringContainsStringI(haystack.second, needle);
409}
AC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle)
Definition: Util.cpp:593

References StringContainsStringI().

◆ vutf8printf()

AC_COMMON_API void vutf8printf ( FILE *  out,
const char *  str,
va_list *  ap 
)
506{
507#if AC_PLATFORM == AC_PLATFORM_WINDOWS
508 char temp_buf[32 * 1024];
509 wchar_t wtemp_buf[32 * 1024];
510
511 size_t temp_len = vsnprintf(temp_buf, 32 * 1024, str, *ap);
512 //vsnprintf returns -1 if the buffer is too small
513 if (temp_len == size_t(-1))
514 {
515 temp_len = 32 * 1024 - 1;
516 }
517
518 size_t wtemp_len = 32 * 1024 - 1;
519 Utf8toWStr(temp_buf, temp_len, wtemp_buf, wtemp_len);
520
521 CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], uint32(wtemp_len + 1));
522 fprintf(out, "%s", temp_buf);
523#else
524 vfprintf(out, str, *ap);
525#endif
526}

References Utf8toWStr().

Referenced by utf8printf().

◆ wcharToLower()

wchar_t wcharToLower ( wchar_t  wchar)
inline
321{
322 if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
323 {
324 return wchar_t(uint16(wchar) + 0x0020);
325 }
326 if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
327 {
328 return wchar_t(uint16(wchar) + 0x0020);
329 }
330 if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
331 {
332 return wchar_t(uint16(wchar) + 0x0020);
333 }
334 if (wchar >= 0x0100 && wchar <= 0x012E) // LATIN CAPITAL LETTER A WITH MACRON - LATIN CAPITAL LETTER I WITH OGONEK (only %2=0)
335 {
336 if (wchar % 2 == 0)
337 {
338 return wchar_t(uint16(wchar) + 0x0001);
339 }
340 }
341 if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
342 {
343 return wchar_t(0x00DF);
344 }
345 if (wchar == 0x0401) // CYRILLIC CAPITAL LETTER IO
346 {
347 return wchar_t(0x0451);
348 }
349 if (wchar >= 0x0410 && wchar <= 0x042F) // CYRILLIC CAPITAL LETTER A - CYRILLIC CAPITAL LETTER YA
350 {
351 return wchar_t(uint16(wchar) + 0x0020);
352 }
353
354 return wchar;
355}
std::uint16_t uint16
Definition: Define.h:109

Referenced by wstrToLower().

◆ wcharToUpper()

wchar_t wcharToUpper ( wchar_t  wchar)
inline
279{
280 if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
281 {
282 return wchar_t(uint16(wchar) - 0x0020);
283 }
284 if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
285 {
286 return wchar_t(0x1E9E);
287 }
288 if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
289 {
290 return wchar_t(uint16(wchar) - 0x0020);
291 }
292 if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
293 {
294 return wchar_t(uint16(wchar) - 0x0020);
295 }
296 if (wchar >= 0x0101 && wchar <= 0x012F) // LATIN SMALL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK (only %2=1)
297 {
298 if (wchar % 2 == 1)
299 {
300 return wchar_t(uint16(wchar) - 0x0001);
301 }
302 }
303 if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
304 {
305 return wchar_t(uint16(wchar) - 0x0020);
306 }
307 if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
308 {
309 return wchar_t(0x0401);
310 }
311
312 return wchar;
313}

Referenced by normalizePlayerName(), wcharToUpperOnlyLatin(), and wstrToUpper().

◆ wcharToUpperOnlyLatin()

wchar_t wcharToUpperOnlyLatin ( wchar_t  wchar)
inline
316{
317 return isBasicLatinCharacter(wchar) ? wcharToUpper(wchar) : wchar;
318}
wchar_t wcharToUpper(wchar_t wchar)
Definition: Util.h:278

References isBasicLatinCharacter(), and wcharToUpper().

Referenced by Utf8ToUpperOnlyLatin().

◆ wstrToLower()

void wstrToLower ( std::wstring &  str)
383{ std::transform(std::begin(str), std::end(str), std::begin(str), wcharToLower); }
wchar_t wcharToLower(wchar_t wchar)
Definition: Util.h:320

References wcharToLower().

Referenced by ObjectMgr::AddGameTele(), ObjectMgr::AddProfanityPlayerName(), ObjectMgr::AddReservedPlayerName(), ObjectMgr::CheckPlayerName(), ObjectMgr::DeleteGameTele(), AuctionListItemsDelayEvent::Execute(), ChannelMgr::GetChannel(), ObjectMgr::GetGameTele(), Graveyard::GetGraveyard(), ChannelMgr::GetJoinChannel(), learn_commandscript::HandleLearnAllRecipesCommand(), 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::HandleWhoOpcode(), ObjectMgr::IsProfanityName(), ObjectMgr::IsReservedName(), list_commandscript::ListAurasCommand(), ObjectMgr::LoadGameTele(), Graveyard::LoadGraveyardFromDB(), ObjectMgr::LoadProfanityPlayersNames(), ObjectMgr::LoadReservedPlayersNames(), normalizePlayerName(), WhoListCacheMgr::Update(), and Utf8FitTo().

◆ wstrToUpper()

void wstrToUpper ( std::wstring &  str)
382{ std::transform(std::begin(str), std::end(str), std::begin(str), wcharToUpper); }

References wcharToUpper().

◆ WStrToUtf8() [1/2]

AC_COMMON_API bool WStrToUtf8 ( std::wstring_view  wstr,
std::string &  utf8str 
)
359{
360 try
361 {
362 std::string utf8str2;
363 utf8str2.resize(wstr.size() * 4); // allocate for most long case
364
365 if (!wstr.empty())
366 {
367 char* oend = utf8::utf16to8(wstr.begin(), wstr.end(), &utf8str2[0]);
368 utf8str2.resize(oend - (&utf8str2[0])); // remove unused tail
369 }
370
371 utf8str = utf8str2;
372 }
373 catch (std::exception const&)
374 {
375 utf8str.clear();
376 return false;
377 }
378
379 return true;
380}

◆ WStrToUtf8() [2/2]

AC_COMMON_API bool WStrToUtf8 ( wchar_t const *  wstr,
size_t  size,
std::string &  utf8str 
)
335{
336 try
337 {
338 std::string utf8str2;
339 utf8str2.resize(size * 4); // allocate for most long case
340
341 if (size)
342 {
343 char* oend = utf8::utf16to8(wstr, wstr + size, &utf8str2[0]);
344 utf8str2.resize(oend - (&utf8str2[0])); // remove unused tail
345 }
346
347 utf8str = utf8str2;
348 }
349 catch (std::exception const&)
350 {
351 utf8str.clear();
352 return false;
353 }
354
355 return true;
356}

Referenced by CliThread(), consoleToUtf8(), server_commandscript::HandleServerIdleRestartCommand(), server_commandscript::HandleServerIdleShutDownCommand(), server_commandscript::HandleServerRestartCommand(), server_commandscript::HandleServerSetMotdCommand(), server_commandscript::HandleServerShutDownCommand(), normalizePlayerName(), and Utf8ToUpperOnlyLatin().