Added string functions from T2D.

This commit is contained in:
Daniel Buckmaster 2014-05-05 22:13:25 +10:00
parent feec36731e
commit 33444e8a36
2 changed files with 32 additions and 0 deletions

View file

@ -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);
}

View file

@ -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]