mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-12 19:31:41 +00:00
Added string functions from T2D.
This commit is contained in:
parent
feec36731e
commit
33444e8a36
2 changed files with 32 additions and 0 deletions
|
|
@ -532,3 +532,32 @@ const char* dStristr( const char* str1, const char* str2 )
|
|||
{
|
||||
return dStristr( const_cast< char* >( str1 ), str2 );
|
||||
}
|
||||
|
||||
int dStrrev(char* str)
|
||||
{
|
||||
int l=dStrlen(str)-1; //get the string length
|
||||
for(int x=0;x < l;x++,l--)
|
||||
{
|
||||
str[x]^=str[l]; //triple XOR Trick
|
||||
str[l]^=str[x]; //for not using a temp
|
||||
str[x]^=str[l];
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
int dItoa(int n, char s[])
|
||||
{
|
||||
int i, sign;
|
||||
|
||||
if ((sign = n) < 0) /* record sign */
|
||||
n = -n; /* make n positive */
|
||||
i = 0;
|
||||
do { /* generate digits in reverse order */
|
||||
s[i++] = n % 10 + '0'; /* get next digit */
|
||||
} while ((n /= 10) > 0); /* delete it */
|
||||
if (sign < 0)
|
||||
s[i++] = '-';
|
||||
s[i] = '\0';
|
||||
dStrrev(s);
|
||||
return dStrlen(s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -217,6 +217,9 @@ bool dStrEndsWith(const char* str1, const char* str2);
|
|||
|
||||
char* dStripPath(const char* filename);
|
||||
|
||||
int dStrrev(char* str);
|
||||
int dItoa(int n, char s[]);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// standard I/O functions [defined in platformString.cpp]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue