Fixed spacing to fit GG standards.

Fixed tabs to 3 spaces.
This commit is contained in:
Nathan Bowhay 2015-02-11 10:53:34 -08:00
parent 7ef3a64957
commit 02f859c150
3 changed files with 274 additions and 274 deletions

View file

@ -53,129 +53,129 @@ static char scriptFilenameBuffer[1024];
bool isInt(const char* str) bool isInt(const char* str)
{ {
int len = dStrlen(str); int len = dStrlen(str);
if(len <= 0) if(len <= 0)
return false; return false;
// Ingore whitespace // Ignore whitespace
int start = 0; int start = 0;
for(int i = start; i < len; i++) for(int i = start; i < len; i++)
if(str[i] != ' ') if(str[i] != ' ')
{ {
start = i; start = i;
break; break;
} }
for(int i = start; i < len; i++) for(int i = start; i < len; i++)
switch(str[i]) switch(str[i])
{ {
case '+': case '-': case '+': case '-':
if(i != 0) if(i != 0)
return false; return false;
break; break;
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0':
break; break;
case ' ': // ignore whitespace case ' ': // ignore whitespace
for(int j = i+1; j < len; j++) for(int j = i+1; j < len; j++)
if(str[j] != ' ') if(str[j] != ' ')
return false; return false;
return true; return true;
break; break;
default: default:
return false; return false;
} }
return true; return true;
} }
bool isFloat(const char* str, bool sciOk = false) bool isFloat(const char* str, bool sciOk = false)
{ {
int len = dStrlen(str); int len = dStrlen(str);
if(len <= 0) if(len <= 0)
return false; return false;
// Ingore whitespace // Ingore whitespace
int start = 0; int start = 0;
for(int i = start; i < len; i++) for(int i = start; i < len; i++)
if(str[i] != ' ') if(str[i] != ' ')
{ {
start = i; start = i;
break; break;
} }
bool seenDot = false; bool seenDot = false;
int eLoc = -1; int eLoc = -1;
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
switch(str[i]) switch(str[i])
{ {
case '+': case '-': case '+': case '-':
if(sciOk) if(sciOk)
{ {
//Haven't found e or scientific notation symbol //Haven't found e or scientific notation symbol
if(eLoc == -1) if(eLoc == -1)
{ {
//only allowed in beginning //only allowed in beginning
if(i != 0) if(i != 0)
return false; return false;
} }
else else
{ {
//if not right after the e //if not right after the e
if(i != (eLoc + 1)) if(i != (eLoc + 1))
return false; return false;
} }
} }
else else
{ {
//only allowed in beginning //only allowed in beginning
if(i != 0) if(i != 0)
return false; return false;
} }
break; break;
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0':
break; break;
case 'e': case 'E': case 'e': case 'E':
if(!sciOk) if(!sciOk)
return false; return false;
else else
{ {
//already saw it so can't have 2 //already saw it so can't have 2
if(eLoc != -1) if(eLoc != -1)
return false; return false;
eLoc = i; eLoc = i;
} }
break; break;
case '.': case '.':
if(seenDot | (sciOk && eLoc != -1)) if(seenDot | (sciOk && eLoc != -1))
return false; return false;
seenDot = true; seenDot = true;
break; break;
case ' ': // ignore whitespace case ' ': // ignore whitespace
for(int j = i+1; j < len; j++) for(int j = i+1; j < len; j++)
if(str[j] != ' ') if(str[j] != ' ')
return false; return false;
return true; return true;
break; break;
default: default:
return false; return false;
} }
return true; return true;
} }
bool isValidIP(const char* ip) bool isValidIP(const char* ip)
{ {
unsigned b1, b2, b3, b4; unsigned b1, b2, b3, b4;
unsigned char c; unsigned char c;
int rc = dSscanf(ip, "%3u.%3u.%3u.%3u%c", &b1, &b2, &b3, &b4, &c); int rc = dSscanf(ip, "%3u.%3u.%3u.%3u%c", &b1, &b2, &b3, &b4, &c);
if (rc != 4 && rc != 5) return false; if (rc != 4 && rc != 5) return false;
if ((b1 | b2 | b3 | b4) > 255) return false; if ((b1 | b2 | b3 | b4) > 255) return false;
if (dStrspn(ip, "0123456789.") < dStrlen(ip)) return false; if (dStrspn(ip, "0123456789.") < dStrlen(ip)) return false;
return true; return true;
} }
bool isValidPort(U16 port) bool isValidPort(U16 port)
{ {
return (port >= 0 && port <=65535); return (port >= 0 && port <=65535);
} }
//============================================================================= //=============================================================================
@ -380,29 +380,29 @@ DefineConsoleFunction( strlenskip, S32, ( const char* str, const char* first, co
"@return The length of the given string skipping blocks of text between characters.\n" "@return The length of the given string skipping blocks of text between characters.\n"
"@ingroup Strings" ) "@ingroup Strings" )
{ {
const UTF8* pos = str; const UTF8* pos = str;
U32 size = 0; U32 size = 0;
U32 length = dStrlen(str); U32 length = dStrlen(str);
bool count = true; bool count = true;
//loop through each character counting each character, skipping tags (anything with < followed by >) //loop through each character counting each character, skipping tags (anything with < followed by >)
for(U32 i = 0; i < length; i++, pos++) for(U32 i = 0; i < length; i++, pos++)
{ {
if(count) if(count)
{ {
if(*pos == first[0]) if(*pos == first[0])
count = false; count = false;
else else
size++; size++;
} }
else else
{ {
if(*pos == last[0]) if(*pos == last[0])
count = true; count = true;
} }
} }
return S32(size); return S32(size);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -831,9 +831,9 @@ DefineConsoleFunction( getFirstNumber, String, ( const char* str ),,
"@param str The string from which to read out the first number.\n" "@param str The string from which to read out the first number.\n"
"@return String representation of the number or "" if no number.\n\n") "@return String representation of the number or "" if no number.\n\n")
{ {
U32 start; U32 start;
U32 end; U32 end;
return String::GetFirstNumber(str, start, end); return String::GetFirstNumber(str, start, end);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------
@ -1031,17 +1031,17 @@ DefineConsoleFunction( strToggleCaseToWords, const char*, ( const char* str ),,
"@endtsexample\n" "@endtsexample\n"
"@ingroup Strings" ) "@ingroup Strings" )
{ {
String newStr; String newStr;
for(S32 i = 0; str[i]; i++) for(S32 i = 0; str[i]; i++)
{ {
//If capitol add a space //If capitol add a space
if(i != 0 && str[i] >= 65 && str[i] <= 90) if(i != 0 && str[i] >= 65 && str[i] <= 90)
newStr += " "; newStr += " ";
newStr += str[i]; newStr += str[i];
} }
return Con::getReturnBuffer(newStr); return Con::getReturnBuffer(newStr);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------
@ -1056,7 +1056,7 @@ DefineConsoleFunction( isInt, bool, ( const char* str),,
"@endtsexample\n" "@endtsexample\n"
"@ingroup Strings" ) "@ingroup Strings" )
{ {
return isInt(str); return isInt(str);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------
@ -1071,7 +1071,7 @@ DefineConsoleFunction( isFloat, bool, ( const char* str, bool sciOk), (false),
"@endtsexample\n" "@endtsexample\n"
"@ingroup Strings" ) "@ingroup Strings" )
{ {
return isFloat(str, sciOk); return isFloat(str, sciOk);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------
@ -1085,13 +1085,13 @@ DefineConsoleFunction( isValidPort, bool, ( const char* str),,
"@endtsexample\n" "@endtsexample\n"
"@ingroup Strings" ) "@ingroup Strings" )
{ {
if(isInt(str)) if(isInt(str))
{ {
U16 port = dAtous(str); U16 port = dAtous(str);
return isValidPort(port); return isValidPort(port);
} }
else else
return false; return false;
} }
//---------------------------------------------------------------- //----------------------------------------------------------------
@ -1105,12 +1105,12 @@ DefineConsoleFunction( isValidIP, bool, ( const char* str),,
"@endtsexample\n" "@endtsexample\n"
"@ingroup Strings" ) "@ingroup Strings" )
{ {
if(dStrcmp(str, "localhost") == 0) if(dStrcmp(str, "localhost") == 0)
{ {
return true; return true;
} }
else else
return isValidIP(str); return isValidIP(str);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------
@ -1244,22 +1244,22 @@ DefineEngineFunction( monthNumToStr, String, ( S32 num, bool abbreviate ), (fals
"@return month as a word given a number or \"\" if number is bad" "@return month as a word given a number or \"\" if number is bad"
"@ingroup FileSystem") "@ingroup FileSystem")
{ {
switch(num) switch(num)
{ {
case 1: return abbreviate ? "Jan" : "January"; break; case 1: return abbreviate ? "Jan" : "January"; break;
case 2: return abbreviate ? "Feb" : "February"; break; case 2: return abbreviate ? "Feb" : "February"; break;
case 3: return abbreviate ? "Mar" : "March"; break; case 3: return abbreviate ? "Mar" : "March"; break;
case 4: return abbreviate ? "Apr" : "April"; break; case 4: return abbreviate ? "Apr" : "April"; break;
case 5: return "May"; break; case 5: return "May"; break;
case 6: return abbreviate ? "Jun" : "June"; break; case 6: return abbreviate ? "Jun" : "June"; break;
case 7: return abbreviate ? "Jul" : "July"; break; case 7: return abbreviate ? "Jul" : "July"; break;
case 8: return abbreviate ? "Aug" : "August"; break; case 8: return abbreviate ? "Aug" : "August"; break;
case 9: return abbreviate ? "Sep" : "September"; break; case 9: return abbreviate ? "Sep" : "September"; break;
case 10: return abbreviate ? "Oct" : "October"; break; case 10: return abbreviate ? "Oct" : "October"; break;
case 11: return abbreviate ? "Nov" : "November"; break; case 11: return abbreviate ? "Nov" : "November"; break;
case 12: return abbreviate ? "Dec" : "December"; break; case 12: return abbreviate ? "Dec" : "December"; break;
default: return ""; default: return "";
} }
} }
DefineEngineFunction( weekdayNumToStr, String, ( S32 num, bool abbreviate ), (false), DefineEngineFunction( weekdayNumToStr, String, ( S32 num, bool abbreviate ), (false),
@ -1267,17 +1267,17 @@ DefineEngineFunction( weekdayNumToStr, String, ( S32 num, bool abbreviate ), (fa
"@return weekday as a word given a number or \"\" if number is bad" "@return weekday as a word given a number or \"\" if number is bad"
"@ingroup FileSystem") "@ingroup FileSystem")
{ {
switch(num) switch(num)
{ {
case 0: return abbreviate ? "Sun" : "Sunday"; break; case 0: return abbreviate ? "Sun" : "Sunday"; break;
case 1: return abbreviate ? "Mon" : "Monday"; break; case 1: return abbreviate ? "Mon" : "Monday"; break;
case 2: return abbreviate ? "Tue" : "Tuesday"; break; case 2: return abbreviate ? "Tue" : "Tuesday"; break;
case 3: return abbreviate ? "Wed" : "Wednesday"; break; case 3: return abbreviate ? "Wed" : "Wednesday"; break;
case 4: return abbreviate ? "Thu" : "Thursday"; break; case 4: return abbreviate ? "Thu" : "Thursday"; break;
case 5: return abbreviate ? "Fri" : "Friday"; break; case 5: return abbreviate ? "Fri" : "Friday"; break;
case 6: return abbreviate ? "Sat" : "Saturday"; break; case 6: return abbreviate ? "Sat" : "Saturday"; break;
default: return ""; default: return "";
} }
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -3071,5 +3071,5 @@ DefineEngineFunction( getMaxDynamicVerts, S32, (),,
"Get max number of allowable dynamic vertices in a single vertex buffer.\n\n" "Get max number of allowable dynamic vertices in a single vertex buffer.\n\n"
"@return the max number of allowable dynamic vertices in a single vertex buffer" ) "@return the max number of allowable dynamic vertices in a single vertex buffer" )
{ {
return MAX_DYNAMIC_VERTS / 2; return MAX_DYNAMIC_VERTS / 2;
} }

View file

@ -1627,100 +1627,100 @@ String String::GetTrailingNumber(const char* str, S32& number)
String String::GetFirstNumber(const char* str, U32& startPos, U32& endPos) String String::GetFirstNumber(const char* str, U32& startPos, U32& endPos)
{ {
// Check for trivial strings // Check for trivial strings
if (!str || !str[0]) if (!str || !str[0])
return String::EmptyString; return String::EmptyString;
// Find the number at the end of the string // Find the number at the end of the string
String base(str); String base(str);
const char* p = base.c_str(); const char* p = base.c_str();
const char* end = base.c_str() + base.length() - 1; const char* end = base.c_str() + base.length() - 1;
bool dec = false; bool dec = false;
startPos = 0; startPos = 0;
//Check if we are just a digit //Check if we are just a digit
if(p == end && isdigit(*p)) if(p == end && isdigit(*p))
return base; return base;
//Look for the first digit //Look for the first digit
while ((p != end) && (dIsspace(*p) || !isdigit(*p))) while ((p != end) && (dIsspace(*p) || !isdigit(*p)))
{ {
p++; p++;
startPos++; startPos++;
} }
//Handle if we are at the end and found nothing //Handle if we are at the end and found nothing
if(p == end && !isdigit(*p)) if(p == end && !isdigit(*p))
return ""; return "";
//update our end position at least to the start of our number //update our end position at least to the start of our number
endPos = startPos; endPos = startPos;
//Backup our ptr //Backup our ptr
const char* backup = p; const char* backup = p;
//Check for any negative or decimal values //Check for any negative or decimal values
if(startPos > 0) if(startPos > 0)
{ {
p--; p--;
startPos--; startPos--;
if(*p == '.') if(*p == '.')
{ {
dec = true; dec = true;
//ignore any duplicate periods //ignore any duplicate periods
while ((p != base.c_str()) && (*p == '.')) while ((p != base.c_str()) && (*p == '.'))
{ {
p--; p--;
startPos--; startPos--;
} }
//Found a decimal lets still check for negative sign //Found a decimal lets still check for negative sign
if(startPos > 0) if(startPos > 0)
{ {
p--; p--;
startPos--; startPos--;
if((*p != '-') && (*p != '_')) if((*p != '-') && (*p != '_'))
{ {
startPos++; startPos++;
p++; p++;
} }
} }
} }
else if((*p != '-') && (*p != '_')) else if((*p != '-') && (*p != '_'))
{ {
//go back to where we where cause no decimal or negative sign found //go back to where we where cause no decimal or negative sign found
startPos++; startPos++;
p++; p++;
} }
} }
//Restore where we were //Restore where we were
p = backup; p = backup;
//look for the end of the digits //look for the end of the digits
bool justFoundDec = false; bool justFoundDec = false;
while (p != end) while (p != end)
{ {
if(*p == '.') if(*p == '.')
{ {
if(dec && !justFoundDec) if(dec && !justFoundDec)
break; break;
else else
{ {
dec = true; dec = true;
justFoundDec = true; justFoundDec = true;
} }
} }
else if(!isdigit(*p)) else if(!isdigit(*p))
break; break;
else if(justFoundDec) else if(justFoundDec)
justFoundDec = false; justFoundDec = false;
p++; p++;
endPos++; endPos++;
} }
U32 len = (!isdigit(*p)) ? endPos - startPos : (endPos + 1) - startPos; U32 len = (!isdigit(*p)) ? endPos - startPos : (endPos + 1) - startPos;
return base.substr(startPos, len); return base.substr(startPos, len);
} }

View file

@ -96,16 +96,16 @@ DefineConsoleFunction( mFloor, S32, ( F32 v ),,
DefineConsoleFunction( mRound, F32, ( F32 v, S32 n ), (0), DefineConsoleFunction( mRound, F32, ( F32 v, S32 n ), (0),
"Round v to the nth decimal place or the nearest whole number by default." "Round v to the nth decimal place or the nearest whole number by default."
"@param v Value to round\n" "@param v Value to round\n"
"@param n Number of decimal places to round to, 0 by default\n" "@param n Number of decimal places to round to, 0 by default\n"
"@return The rounded value as a S32." "@return The rounded value as a S32."
"@ingroup Math" ) "@ingroup Math" )
{ {
if(n <= 0) if(n <= 0)
return mRound(v); return mRound(v);
else else
return mRound(v, n); return mRound(v, n);
} }
DefineConsoleFunction( mCeil, S32, ( F32 v ),, DefineConsoleFunction( mCeil, S32, ( F32 v ),,