From 33444e8a367590275ec6fc4bb36371b0ff4a83c0 Mon Sep 17 00:00:00 2001 From: Daniel Buckmaster Date: Mon, 5 May 2014 22:13:25 +1000 Subject: [PATCH] Added string functions from T2D. --- .../source/core/strings/stringFunctions.cpp | 29 +++++++++++++++++++ Engine/source/core/strings/stringFunctions.h | 3 ++ 2 files changed, 32 insertions(+) diff --git a/Engine/source/core/strings/stringFunctions.cpp b/Engine/source/core/strings/stringFunctions.cpp index 63377cfd4..476edf71b 100644 --- a/Engine/source/core/strings/stringFunctions.cpp +++ b/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 ); } + +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); +} diff --git a/Engine/source/core/strings/stringFunctions.h b/Engine/source/core/strings/stringFunctions.h index e211454d0..92602fd21 100644 --- a/Engine/source/core/strings/stringFunctions.h +++ b/Engine/source/core/strings/stringFunctions.h @@ -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]