[12062] Cleanup MaNGOS sources

This commit is contained in:
Schmoozerd 2012-07-19 22:03:32 +02:00
parent a4cbed3199
commit aeff8f9d1a
46 changed files with 1982 additions and 1864 deletions

View file

@ -68,47 +68,47 @@ uint32 WorldTimer::getMSTime_internal(bool savetime /*= false*/)
}
//////////////////////////////////////////////////////////////////////////
int32 irand (int32 min, int32 max)
int32 irand(int32 min, int32 max)
{
return int32 (mtRand->randInt (max - min)) + min;
return int32(mtRand->randInt(max - min)) + min;
}
uint32 urand (uint32 min, uint32 max)
uint32 urand(uint32 min, uint32 max)
{
return mtRand->randInt (max - min) + min;
return mtRand->randInt(max - min) + min;
}
float frand (float min, float max)
float frand(float min, float max)
{
return mtRand->randExc (max - min) + min;
return mtRand->randExc(max - min) + min;
}
int32 rand32 ()
int32 rand32()
{
return mtRand->randInt ();
return mtRand->randInt();
}
double rand_norm(void)
{
return mtRand->randExc ();
return mtRand->randExc();
}
float rand_norm_f(void)
{
return (float)mtRand->randExc ();
return (float)mtRand->randExc();
}
double rand_chance (void)
double rand_chance(void)
{
return mtRand->randExc (100.0);
return mtRand->randExc(100.0);
}
float rand_chance_f(void)
{
return (float)mtRand->randExc (100.0);
return (float)mtRand->randExc(100.0);
}
Tokens StrSplit(const std::string &src, const std::string &sep)
Tokens StrSplit(const std::string& src, const std::string& sep)
{
Tokens r;
std::string s;
@ -130,7 +130,7 @@ Tokens StrSplit(const std::string &src, const std::string &sep)
uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index)
{
if(index >= data.size())
if (index >= data.size())
return 0;
return (uint32)atoi(data[index].c_str());
@ -145,18 +145,18 @@ float GetFloatValueFromArray(Tokens const& data, uint16 index)
return result;
}
void stripLineInvisibleChars(std::string &str)
void stripLineInvisibleChars(std::string& str)
{
static std::string invChars = " \t\7\n";
size_t wpos = 0;
bool space = false;
for(size_t pos = 0; pos < str.size(); ++pos)
for (size_t pos = 0; pos < str.size(); ++pos)
{
if(invChars.find(str[pos])!=std::string::npos)
if (invChars.find(str[pos])!=std::string::npos)
{
if(!space)
if (!space)
{
str[wpos++] = ' ';
space = true;
@ -164,7 +164,7 @@ void stripLineInvisibleChars(std::string &str)
}
else
{
if(wpos!=pos)
if (wpos!=pos)
str[wpos++] = str[pos];
else
++wpos;
@ -172,7 +172,7 @@ void stripLineInvisibleChars(std::string &str)
}
}
if(wpos < str.size())
if (wpos < str.size())
str.erase(wpos,str.size());
}
@ -184,15 +184,15 @@ std::string secsToTimeString(time_t timeInSecs, bool shortText, bool hoursOnly)
time_t days = timeInSecs / DAY;
std::ostringstream ss;
if(days)
if (days)
ss << days << (shortText ? "d" : " Day(s) ");
if(hours || hoursOnly)
if (hours || hoursOnly)
ss << hours << (shortText ? "h" : " Hour(s) ");
if(!hoursOnly)
if (!hoursOnly)
{
if(minutes)
if (minutes)
ss << minutes << (shortText ? "m" : " Minute(s) ");
if(secs || (!days && !hours && !minutes) )
if (secs || (!days && !hours && !minutes))
ss << secs << (shortText ? "s" : " Second(s).");
}
@ -205,16 +205,16 @@ uint32 TimeStringToSecs(const std::string& timestring)
uint32 buffer = 0;
uint32 multiplier = 0;
for(std::string::const_iterator itr = timestring.begin(); itr != timestring.end(); ++itr)
for (std::string::const_iterator itr = timestring.begin(); itr != timestring.end(); ++itr)
{
if(isdigit(*itr))
if (isdigit(*itr))
{
buffer*=10;
buffer+= (*itr)-'0';
}
else
{
switch(*itr)
switch (*itr)
{
case 'd': multiplier = DAY; break;
case 'h': multiplier = HOUR; break;
@ -248,7 +248,7 @@ std::string TimeToTimestampStr(time_t t)
/// Check if the string is a valid ip address representation
bool IsIPAddress(char const* ipaddress)
{
if(!ipaddress)
if (!ipaddress)
return false;
// Let the big boys do it.
@ -259,7 +259,7 @@ bool IsIPAddress(char const* ipaddress)
/// create PID file
uint32 CreatePIDFile(const std::string& filename)
{
FILE * pid_file = fopen (filename.c_str(), "w" );
FILE* pid_file = fopen(filename.c_str(), "w");
if (pid_file == NULL)
return 0;
@ -269,7 +269,7 @@ uint32 CreatePIDFile(const std::string& filename)
pid_t pid = getpid();
#endif
fprintf(pid_file, "%d", pid );
fprintf(pid_file, "%d", pid);
fclose(pid_file);
return (uint32)pid;
@ -281,7 +281,7 @@ size_t utf8length(std::string& utf8str)
{
return utf8::distance(utf8str.c_str(),utf8str.c_str()+utf8str.size());
}
catch(std::exception)
catch (std::exception)
{
utf8str = "";
return 0;
@ -293,7 +293,7 @@ void utf8truncate(std::string& utf8str,size_t len)
try
{
size_t wlen = utf8::distance(utf8str.c_str(),utf8str.c_str()+utf8str.size());
if(wlen <= len)
if (wlen <= len)
return;
std::wstring wstr;
@ -303,7 +303,7 @@ void utf8truncate(std::string& utf8str,size_t len)
char* oend = utf8::utf16to8(wstr.c_str(),wstr.c_str()+wstr.size(),&utf8str[0]);
utf8str.resize(oend-(&utf8str[0])); // remove unused tail
}
catch(std::exception)
catch (std::exception)
{
utf8str = "";
}
@ -314,9 +314,9 @@ bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
try
{
size_t len = utf8::distance(utf8str,utf8str+csize);
if(len > wsize)
if (len > wsize)
{
if(wsize > 0)
if (wsize > 0)
wstr[0] = L'\0';
wsize = 0;
return false;
@ -326,9 +326,9 @@ bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
utf8::utf8to16(utf8str,utf8str+csize,wstr);
wstr[len] = L'\0';
}
catch(std::exception)
catch (std::exception)
{
if(wsize > 0)
if (wsize > 0)
wstr[0] = L'\0';
wsize = 0;
return false;
@ -347,7 +347,7 @@ bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr)
if (len)
utf8::utf8to16(utf8str.c_str(),utf8str.c_str()+utf8str.size(),&wstr[0]);
}
catch(std::exception)
catch (std::exception)
{
wstr = L"";
return false;
@ -367,7 +367,7 @@ bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str)
utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail
utf8str = utf8str2;
}
catch(std::exception)
catch (std::exception)
{
utf8str = "";
return false;
@ -387,7 +387,7 @@ bool WStrToUtf8(std::wstring wstr, std::string& utf8str)
utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail
utf8str = utf8str2;
}
catch(std::exception)
catch (std::exception)
{
utf8str = "";
return false;
@ -401,7 +401,7 @@ typedef wchar_t const* const* wstrlist;
std::wstring GetMainPartOfName(std::wstring wname, uint32 declension)
{
// supported only Cyrillic cases
if(wname.size() < 1 || !isCyrillicCharacter(wname[0]) || declension > 5)
if (wname.size() < 1 || !isCyrillicCharacter(wname[0]) || declension > 5)
return wname;
// Important: end length must be <= MAX_INTERNAL_PLAYER_NAME-MAX_PLAYER_NAME (3 currently)
@ -423,7 +423,8 @@ std::wstring GetMainPartOfName(std::wstring wname, uint32 declension)
static wchar_t const soft_End[] = { wchar_t(1), wchar_t(0x044C),wchar_t(0x0000)};
static wchar_t const j_End[] = { wchar_t(1), wchar_t(0x0439),wchar_t(0x0000)};
static wchar_t const* const dropEnds[6][8] = {
static wchar_t const* const dropEnds[6][8] =
{
{ &a_End[1], &o_End[1], &ya_End[1], &ie_End[1], &soft_End[1], &j_End[1], NULL, NULL },
{ &a_End[1], &ya_End[1], &yeru_End[1], &i_End[1], NULL, NULL, NULL, NULL },
{ &ie_End[1], &u_End[1], &yu_End[1], &i_End[1], NULL, NULL, NULL, NULL },
@ -432,11 +433,11 @@ std::wstring GetMainPartOfName(std::wstring wname, uint32 declension)
{ &ie_End[1], &i_End[1], NULL, NULL, NULL, NULL, NULL, NULL }
};
for(wchar_t const * const* itr = &dropEnds[declension][0]; *itr; ++itr)
for (wchar_t const * const* itr = &dropEnds[declension][0]; *itr; ++itr)
{
size_t len = size_t((*itr)[-1]); // get length from string size field
if(wname.substr(wname.size()-len,len)==*itr)
if (wname.substr(wname.size()-len,len)==*itr)
return wname.substr(0,wname.size()-len);
}
@ -447,7 +448,7 @@ bool utf8ToConsole(const std::string& utf8str, std::string& conStr)
{
#if PLATFORM == PLATFORM_WINDOWS
std::wstring wstr;
if(!Utf8toWStr(utf8str,wstr))
if (!Utf8toWStr(utf8str,wstr))
return false;
conStr.resize(wstr.size());
@ -479,19 +480,19 @@ bool Utf8FitTo(const std::string& str, std::wstring search)
{
std::wstring temp;
if(!Utf8toWStr(str,temp))
if (!Utf8toWStr(str,temp))
return false;
// converting to lower case
wstrToLower( temp );
wstrToLower(temp);
if(temp.find(search) == std::wstring::npos)
if (temp.find(search) == std::wstring::npos)
return false;
return true;
}
void utf8printf(FILE *out, const char *str, ...)
void utf8printf(FILE* out, const char* str, ...)
{
va_list ap;
va_start(ap, str);
@ -499,7 +500,7 @@ void utf8printf(FILE *out, const char *str, ...)
va_end(ap);
}
void vutf8printf(FILE *out, const char *str, va_list* ap)
void vutf8printf(FILE* out, const char* str, va_list* ap)
{
#if PLATFORM == PLATFORM_WINDOWS
char temp_buf[32*1024];
@ -520,13 +521,13 @@ void vutf8printf(FILE *out, const char *str, va_list* ap)
void hexEncodeByteArray(uint8* bytes, uint32 arrayLen, std::string& result)
{
std::ostringstream ss;
for(uint32 i=0; i<arrayLen; ++i)
for (uint32 i=0; i<arrayLen; ++i)
{
for(uint8 j=0; j<2; ++j)
for (uint8 j=0; j<2; ++j)
{
unsigned char nibble = 0x0F & (bytes[i]>>((1-j)*4));
char encodedNibble;
if(nibble < 0x0A)
if (nibble < 0x0A)
encodedNibble = '0'+nibble;
else
encodedNibble = 'A'+nibble-0x0A;