AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Util.cpp File Reference
#include "Util.h"
#include "Common.h"
#include "Containers.h"
#include "IpAddress.h"
#include "StringConvert.h"
#include "Tokenize.h"
#include <algorithm>
#include <boost/core/demangle.hpp>
#include <cctype>
#include <cstdarg>
#include <ctime>
#include <sstream>
#include <string>
#include <utf8.h>

Go to the source code of this file.

Functions

void stripLineInvisibleChars (std::string &str)
 
std::string secsToTimeString (uint64 timeInSecs, bool shortText)
 
Optional< int32MoneyStringToMoney (std::string_view moneyString)
 
uint32 TimeStringToSecs (const std::string &timestring)
 
bool IsIPAddress (char const *ipaddress)
 Check if the string is a valid ip address representation.
 
uint32 CreatePIDFile (std::string const &filename)
 create PID file
 
uint32 GetPID ()
 
size_t utf8length (std::string &utf8str)
 
void utf8truncate (std::string &utf8str, size_t len)
 
bool Utf8toWStr (char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
 
bool Utf8toWStr (std::string_view utf8str, std::wstring &wstr)
 
bool WStrToUtf8 (wchar_t const *wstr, size_t size, std::string &utf8str)
 
bool WStrToUtf8 (std::wstring_view wstr, std::string &utf8str)
 
void wstrToUpper (std::wstring &str)
 
void wstrToLower (std::wstring &str)
 
void strToUpper (std::string &str)
 
void strToLower (std::string &str)
 
std::wstring GetMainPartOfName (std::wstring const &wname, uint32 declension)
 
bool utf8ToConsole (std::string_view utf8str, std::string &conStr)
 
bool consoleToUtf8 (std::string_view conStr, std::string &utf8str)
 
bool Utf8FitTo (std::string_view str, std::wstring_view search)
 
void utf8printf (FILE *out, const char *str,...)
 
void vutf8printf (FILE *out, const char *str, va_list *ap)
 
bool Utf8ToUpperOnlyLatin (std::string &utf8String)
 
bool StringEqualI (std::string_view a, std::string_view b)
 
bool StringContainsStringI (std::string_view haystack, std::string_view needle)
 
bool StringCompareLessI (std::string_view a, std::string_view b)
 
std::string GetTypeName (std::type_info const &info)
 

Function Documentation

◆ consoleToUtf8()

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 ( std::string const &  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()

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

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

◆ MoneyStringToMoney()

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

◆ secsToTimeString()

std::string secsToTimeString ( uint64  timeInSecs,
bool  shortText 
)
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()

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

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

◆ stripLineInvisibleChars()

void stripLineInvisibleChars ( std::string &  str)
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}

◆ strToLower()

void strToLower ( std::string &  str)
385{ std::transform(std::begin(str), std::end(str), std::begin(str), charToLower); }
char charToLower(char c)
Definition: Util.h:271

References charToLower().

Referenced by ExtractGameobjectModels().

◆ strToUpper()

void strToUpper ( std::string &  str)
384{ std::transform(std::begin(str), std::end(str), std::begin(str), charToUpper); }
char charToUpper(char c)
Definition: Util.h:270

References charToUpper().

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

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

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/2]

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/2]

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

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

◆ vutf8printf()

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

◆ 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:315

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); }
wchar_t wcharToUpper(wchar_t wchar)
Definition: Util.h:273

References wcharToUpper().

◆ WStrToUtf8() [1/2]

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]

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