mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
Forgot supporting method
Added string manipulation functions upload, requires these changes to compile.
This commit is contained in:
parent
df2ca75b13
commit
c98e95e6ff
2 changed files with 101 additions and 0 deletions
|
|
@ -1624,3 +1624,103 @@ String String::GetTrailingNumber(const char* str, S32& number)
|
||||||
|
|
||||||
return base.substr(0, p - base.c_str());
|
return base.substr(0, p - base.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String String::GetFirstNumber(const char* str, U32& startPos, U32& endPos)
|
||||||
|
{
|
||||||
|
// Check for trivial strings
|
||||||
|
if (!str || !str[0])
|
||||||
|
return String::EmptyString;
|
||||||
|
|
||||||
|
// Find the number at the end of the string
|
||||||
|
String base(str);
|
||||||
|
const char* p = base.c_str();
|
||||||
|
const char* end = base.c_str() + base.length() - 1;
|
||||||
|
bool dec = false;
|
||||||
|
startPos = 0;
|
||||||
|
|
||||||
|
//Check if we are just a digit
|
||||||
|
if(p == end && isdigit(*p))
|
||||||
|
return base;
|
||||||
|
|
||||||
|
//Look for the first digit
|
||||||
|
while ((p != end) && (dIsspace(*p) || !isdigit(*p)))
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
startPos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Handle if we are at the end and found nothing
|
||||||
|
if(p == end && !isdigit(*p))
|
||||||
|
return "";
|
||||||
|
|
||||||
|
//update our end position at least to the start of our number
|
||||||
|
endPos = startPos;
|
||||||
|
|
||||||
|
//Backup our ptr
|
||||||
|
const char* backup = p;
|
||||||
|
|
||||||
|
//Check for any negative or decimal values
|
||||||
|
if(startPos > 0)
|
||||||
|
{
|
||||||
|
p--;
|
||||||
|
startPos--;
|
||||||
|
if(*p == '.')
|
||||||
|
{
|
||||||
|
dec = true;
|
||||||
|
|
||||||
|
//ignore any duplicate periods
|
||||||
|
while ((p != base.c_str()) && (*p == '.'))
|
||||||
|
{
|
||||||
|
p--;
|
||||||
|
startPos--;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Found a decimal lets still check for negative sign
|
||||||
|
if(startPos > 0)
|
||||||
|
{
|
||||||
|
p--;
|
||||||
|
startPos--;
|
||||||
|
if((*p != '-') && (*p != '_'))
|
||||||
|
{
|
||||||
|
startPos++;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if((*p != '-') && (*p != '_'))
|
||||||
|
{
|
||||||
|
//go back to where we where cause no decimal or negative sign found
|
||||||
|
startPos++;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Restore where we were
|
||||||
|
p = backup;
|
||||||
|
|
||||||
|
//look for the end of the digits
|
||||||
|
bool justFoundDec = false;
|
||||||
|
while (p != end)
|
||||||
|
{
|
||||||
|
if(*p == '.')
|
||||||
|
{
|
||||||
|
if(dec && !justFoundDec)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dec = true;
|
||||||
|
justFoundDec = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(!isdigit(*p))
|
||||||
|
break;
|
||||||
|
else if(justFoundDec)
|
||||||
|
justFoundDec = false;
|
||||||
|
|
||||||
|
p++;
|
||||||
|
endPos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
U32 len = (!isdigit(*p)) ? endPos - startPos : (endPos + 1) - startPos;
|
||||||
|
return base.substr(startPos, len);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,7 @@ public:
|
||||||
static String ToUpper(const String &string);
|
static String ToUpper(const String &string);
|
||||||
|
|
||||||
static String GetTrailingNumber(const char* str, S32& number);
|
static String GetTrailingNumber(const char* str, S32& number);
|
||||||
|
static String GetFirstNumber(const char* str, U32& startPos, U32& endPos);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue