From 6c36406a5dba3d390e2c98bd48c01bb1db86a985 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 11 Jul 2006 07:33:20 +0000 Subject: I added stringrep, which is a cpp replacement for some c string functions. They're all really simple, and maybe could even be optimized. I did this so that you could use the old c functions when you wanted to, but with cpp memory management. Also, some of these don't exist on other platforms, so it makes other programs more portable. The new functions are just like the c ones, only named string* instead of str*, for example stringdup instead of strdup. --- src/stringrep.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/stringrep.cpp (limited to 'src/stringrep.cpp') diff --git a/src/stringrep.cpp b/src/stringrep.cpp new file mode 100644 index 0000000..a505f8a --- /dev/null +++ b/src/stringrep.cpp @@ -0,0 +1,19 @@ +#include "stringrep.h" + +int32_t stringlen( const char *s ) +{ + for( int32_t i = 0;; i++ ) + if( !s[i] ) + return i; +} + +char *stringdup( const char *s ) +{ + int len = stringlen( s ); + char *r = new char[len+1]; + for( int j = 0; j <= len; j++ ) + r[j] = s[j]; + + return r; +} + -- cgit v1.2.3