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, std::size_t csize, wchar_t *wstr, std::size_t &wsize)
 
bool Utf8toWStr (std::string_view utf8str, wchar_t *wstr, std::size_t &wsize)
 
AC_COMMON_API bool WStrToUtf8 (std::wstring_view wstr, std::string &utf8str)
 
AC_COMMON_API bool WStrToUtf8 (wchar_t const *wstr, std::size_t size, std::string &utf8str)
 
std::size_t utf8length (std::string &utf8str)
 
void utf8truncate (std::string &utf8str, std::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. More...
 
uint32 CreatePIDFile (const std::string &filename)
 create PID file More...
 
uint32 GetPID ()
 
AC_COMMON_API std::string Acore::Impl::ByteArrayToHexStr (uint8 const *bytes, std::size_t length, bool reverse=false)
 
AC_COMMON_API void Acore::Impl::HexStrToByteArray (std::string_view str, uint8 *out, std::size_t outlen, bool reverse=false)
 
template<typename Container >
std::string ByteArrayToHexStr (Container const &c, bool reverse=false)
 
template<std::size_t Size>
void HexStrToByteArray (std::string_view str, std::array< uint8, Size > &buf, bool reverse=false)
 
template<std::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(), Player::CalculateQuestRewardXP(), spell_hun_generic_scaling::CalculateSPAmount(), CalculateSpellAmount(), Unit::CalculateSpellDamageTaken(), spell_dk_pet_scaling::CalculateStatAmount(), spell_hun_generic_scaling::CalculateStatAmount(), Spell::Delayed(), Spell::DelayedChannel(), 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(), 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(), ObjectMgr::LoadVehicleSeatAddon(), 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, std::size_t length, bool reverse=false)
Definition: Util.cpp:545

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_aura::Absorb(), spell_charge_shield_bomber_aura::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::Attack(), Unit::CalcAbsorbResist(), Unit::CalcArmorReducedDamage(), SpellInfo::CalcPowerCost(), spell_mark_of_kazzak_aura::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::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_aura::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_sha_t8_electrified::HandleProc(), spell_warl_drain_soul::HandleProc(), Unit::HandleProcTriggerSpell(), spell_hun_chimera_shot::HandleScriptEffect(), boss_curator::JustEngagedWith(), spell_valanar_kinetic_bomb_absorb_aura::OnAbsorb(), spell_blood_queen_essence_of_the_blood_queen_aura::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 
)
467{
468#if AC_PLATFORM == AC_PLATFORM_WINDOWS
469 std::wstring wstr;
470 wstr.resize(conStr.size());
471 OemToCharBuffW(&conStr[0], &wstr[0], uint32(conStr.size()));
472
473 return WStrToUtf8(wstr, utf8str);
474#else
475 // not implemented yet
476 utf8str = conStr;
477 return true;
478#endif
479}
bool WStrToUtf8(wchar_t const *wstr, std::size_t size, std::string &utf8str)
Definition: Util.cpp:333
std::uint32_t uint32
Definition: Define.h:107

References WStrToUtf8().

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

◆ CreatePIDFile()

uint32 CreatePIDFile ( const std::string &  filename)

create PID file

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

References GetPID().

Referenced by main().

◆ GetMainPartOfName()

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

◆ GetPID()

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

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)
609{
610 return boost::core::demangle(info.name());
611}

◆ 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<std::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<std::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, std::size_t outlen, bool reverse=false)
Definition: Util.cpp:569

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}
bool isCyrillicCharacter(wchar_t wchar)
Definition: Util.h:154

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.

206{
207 if (!ipaddress)
208 {
209 return false;
210 }
211
212 boost::system::error_code error;
213 Acore::Net::make_address(ipaddress, error);
214 return !error;
215}

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)
109{
110 int32 money = 0;
111
112 bool hadG = false;
113 bool hadS = false;
114 bool hadC = false;
115
116 for (std::string_view token : Acore::Tokenize(moneyString, ' ', false))
117 {
118 uint32 unit;
119 switch (token[token.length() - 1])
120 {
121 case 'g':
122 if (hadG)
123 {
124 return std::nullopt;
125 }
126 hadG = true;
127 unit = 100 * 100;
128 break;
129 case 's':
130 if (hadS)
131 {
132 return std::nullopt;
133 }
134 hadS = true;
135 unit = 100;
136 break;
137 case 'c':
138 if (hadC)
139 {
140 return std::nullopt;
141 }
142 hadC = true;
143 unit = 1;
144 break;
145 default:
146 return std::nullopt;
147 }
148
149 Optional<uint32> amount = Acore::StringTo<uint32>(token.substr(0, token.length() - 1));
150 if (amount)
151 {
152 money += (unit * *amount);
153 }
154 else
155 {
156 return std::nullopt;
157 }
158 }
159
160 return money;
161}
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
std::int32_t int32
Definition: Define.h:103
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 
)
74{
75 uint64 secs = timeInSecs % MINUTE;
76 uint64 minutes = timeInSecs % HOUR / MINUTE;
77 uint64 hours = timeInSecs % DAY / HOUR;
78 uint64 days = timeInSecs / DAY;
79
80 std::ostringstream ss;
81 if (days)
82 {
83 ss << days << (shortText ? "d" : " day(s) ");
84 }
85 if (hours)
86 {
87 ss << hours << (shortText ? "h" : " hour(s) ");
88 }
89 if (minutes)
90 {
91 ss << minutes << (shortText ? "m" : " minute(s) ");
92 }
93 if (secs || (!days && !hours && !minutes))
94 {
95 ss << secs << (shortText ? "s" : " second(s) ");
96 }
97
98 std::string str = ss.str();
99
100 if (!shortText && !str.empty() && str[str.size() - 1] == ' ')
101 {
102 str.resize(str.size() - 1);
103 }
104
105 return str;
106}
constexpr auto DAY
Definition: Common.h:49
constexpr auto HOUR
Definition: Common.h:48
constexpr auto MINUTE
Definition: Common.h:47
std::uint64_t uint64
Definition: Define.h:106

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 
)
604{
605 return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), [](char c1, char c2) { return std::tolower(c1) < std::tolower(c2); });
606}

Referenced by StringCompareLessI_T::operator()().

◆ StringContainsStringI()

AC_COMMON_API bool StringContainsStringI ( std::string_view  haystack,
std::string_view  needle 
)
598{
599 return haystack.end() !=
600 std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), [](char c1, char c2) { return std::tolower(c1) == std::tolower(c2); });
601}

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:592

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

◆ TimeStringToSecs()

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

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()

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

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

◆ utf8printf()

AC_COMMON_API void utf8printf ( FILE *  out,
const char *  str,
  ... 
)
502{
503 va_list ap;
504 va_start(ap, str);
505 vutf8printf(out, str, &ap);
506 va_end(ap);
507}
void vutf8printf(FILE *out, const char *str, va_list *ap)
Definition: Util.cpp:509

References vutf8printf().

Referenced by AppenderConsole::_write().

◆ utf8ToConsole()

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

References Utf8toWStr().

◆ Utf8ToUpperOnlyLatin()

◆ Utf8toWStr() [1/3]

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

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(), go_commandscript::HandleGoXYZCommand(), 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::LoadProfanityNamesFromDB(), ObjectMgr::LoadProfanityNamesFromDBC(), ObjectMgr::LoadReservedPlayerNamesDB(), ObjectMgr::LoadReservedPlayerNamesDBC(), normalizePlayerName(), 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 
)
318{
319 wstr.clear();
320 try
321 {
322 utf8::utf8to16(utf8str.begin(), utf8str.end(), std::back_inserter(wstr));
323 }
324 catch (std::exception const&)
325 {
326 wstr.clear();
327 return false;
328 }
329
330 return true;
331}

Referenced by Utf8toWStr().

◆ Utf8toWStr() [3/3]

bool Utf8toWStr ( std::string_view  utf8str,
wchar_t *  wstr,
std::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:317

References Utf8toWStr().

◆ utf8truncate()

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

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:597

References StringContainsStringI().

◆ vutf8printf()

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

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:108

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)
382{ 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::LoadProfanityNamesFromDB(), ObjectMgr::LoadReservedPlayerNamesDB(), normalizePlayerName(), WhoListCacheMgr::Update(), and Utf8FitTo().

◆ wstrToUpper()

void wstrToUpper ( std::wstring &  str)
381{ 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 
)
358{
359 try
360 {
361 std::string utf8str2;
362 utf8str2.resize(wstr.size() * 4); // allocate for most long case
363
364 if (!wstr.empty())
365 {
366 char* oend = utf8::utf16to8(wstr.begin(), wstr.end(), &utf8str2[0]);
367 utf8str2.resize(oend - (&utf8str2[0])); // remove unused tail
368 }
369
370 utf8str = utf8str2;
371 }
372 catch (std::exception const&)
373 {
374 utf8str.clear();
375 return false;
376 }
377
378 return true;
379}

◆ WStrToUtf8() [2/2]

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

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