Explorar el Código

Added string functions from T2D.

Daniel Buckmaster hace 11 años
padre
commit
33444e8a36

+ 29 - 0
Engine/source/core/strings/stringFunctions.cpp

@@ -532,3 +532,32 @@ const char* dStristr( const char* str1, const char* str2 )
 {
 {
    return dStristr( const_cast< char* >( str1 ), 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);
+}

+ 3 - 0
Engine/source/core/strings/stringFunctions.h

@@ -217,6 +217,9 @@ bool dStrEndsWith(const char* str1, const char* str2);
 
 
 char* dStripPath(const char* filename);
 char* dStripPath(const char* filename);
 
 
+int dStrrev(char* str);
+int dItoa(int n, char s[]);
+
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 // standard I/O functions [defined in platformString.cpp]
 // standard I/O functions [defined in platformString.cpp]