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 <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. More...
 
uint32 CreatePIDFile (std::string const &filename)
 create PID file More...
 
uint32 GetPID ()
 
std::size_t utf8length (std::string &utf8str)
 
void utf8truncate (std::string &utf8str, std::size_t len)
 
bool Utf8toWStr (char const *utf8str, std::size_t csize, wchar_t *wstr, std::size_t &wsize)
 
bool Utf8toWStr (std::string_view utf8str, std::wstring &wstr)
 
bool WStrToUtf8 (wchar_t const *wstr, std::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_t 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 
)
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 ( std::string const &  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_t  declension 
)
387{
388 // supported only Cyrillic cases
389 if (wname.empty() || !isCyrillicCharacter(wname[0]) || declension > 5)
390 {
391 return wname;
392 }
393
394 // Important: end length must be <= MAX_INTERNAL_PLAYER_NAME-MAX_PLAYER_NAME (3 currently)
395 static std::wstring const a_End = L"\u0430";
396 static std::wstring const o_End = L"\u043E";
397 static std::wstring const ya_End = L"\u044F";
398 static std::wstring const ie_End = L"\u0435";
399 static std::wstring const i_End = L"\u0438";
400 static std::wstring const yeru_End = L"\u044B";
401 static std::wstring const u_End = L"\u0443";
402 static std::wstring const yu_End = L"\u044E";
403 static std::wstring const oj_End = L"\u043E\u0439";
404 static std::wstring const ie_j_End = L"\u0435\u0439";
405 static std::wstring const io_j_End = L"\u0451\u0439";
406 static std::wstring const o_m_End = L"\u043E\u043C";
407 static std::wstring const io_m_End = L"\u0451\u043C";
408 static std::wstring const ie_m_End = L"\u0435\u043C";
409 static std::wstring const soft_End = L"\u044C";
410 static std::wstring const j_End = L"\u0439";
411
412 static std::array<std::array<std::wstring const*, 7>, 6> const dropEnds = {{
413 { &a_End, &o_End, &ya_End, &ie_End, &soft_End, &j_End, nullptr },
414 { &a_End, &ya_End, &yeru_End, &i_End, nullptr, nullptr, nullptr },
415 { &ie_End, &u_End, &yu_End, &i_End, nullptr, nullptr, nullptr },
416 { &u_End, &yu_End, &o_End, &ie_End, &soft_End, &ya_End, &a_End },
417 { &oj_End, &io_j_End, &ie_j_End, &o_m_End, &io_m_End, &ie_m_End, &yu_End },
418 { &ie_End, &i_End, nullptr, nullptr, nullptr, nullptr, nullptr }
419 }
420 };
421
422 std::size_t const thisLen = wname.length();
423 std::array<std::wstring const*, 7> const& endings = dropEnds[declension];
424 for (const std::wstring* endingPtr : endings)
425 {
426 if (endingPtr == nullptr)
427 {
428 break;
429 }
430
431 std::wstring const& ending = *endingPtr;
432 std::size_t const endLen = ending.length();
433 if (endLen > thisLen)
434 {
435 continue;
436 }
437
438 if (wname.compare(thisLen - endLen, endLen, ending) == 0)
439 {
440 return wname.substr(0, thisLen - endLen);
441 }
442 }
443
444 return wname;
445}
bool isCyrillicCharacter(wchar_t wchar)
Definition: Util.h:154

References isCyrillicCharacter().

Referenced by ObjectMgr::CheckDeclinedNames().

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

std::string GetTypeName ( std::type_info const &  info)
609{
610 return boost::core::demangle(info.name());
611}

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

◆ MoneyStringToMoney()

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

◆ secsToTimeString()

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

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

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

◆ stripLineInvisibleChars()

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

◆ strToLower()

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

References charToLower().

Referenced by ExtractGameobjectModels().

◆ strToUpper()

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

References charToUpper().

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

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

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

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

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

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

◆ vutf8printf()

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

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

References wcharToUpper().

◆ WStrToUtf8() [1/2]

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]

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