From cb612c391bf7807f898fa84291827594448f78ab Mon Sep 17 00:00:00 2001 From: fluxgen Date: Tue, 8 Jan 2002 21:35:57 +0000 Subject: Changed to auto_ptr and added comment --- src/StringUtil.cc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/StringUtil.cc b/src/StringUtil.cc index 2295784..0f91b44 100644 --- a/src/StringUtil.cc +++ b/src/StringUtil.cc @@ -21,10 +21,13 @@ #include "StringUtil.hh" -#include -#include -#include -#include +#include +#include +#include +#include +#include + +using namespace std; //------- strdup ------------------------ //TODO: comment this @@ -37,12 +40,15 @@ char *StringUtil::strdup(const char *s) { } //------- strcasestr -------------- +// Tries to find a string in another and +// ignoring the case of the characters +// Returns 0 on success else pointer to str. // TODO: comment this //--------------------------------- const char * StringUtil::strcasestr(const char *str, const char *ptn) { const char *s2, *p2; for( ; *str; str++) { - for(s2=str,p2=ptn; ; s2++,p2++) { + for(s2=str, p2=ptn; ; s2++,p2++) { if (!*p2) return str; if (toupper(*s2) != toupper(*p2)) break; } @@ -57,13 +63,12 @@ const char * StringUtil::strcasestr(const char *str, const char *ptn) { //--------------------------------------------------- char *StringUtil::expandFilename(const char *filename) { - char retval[strlen(filename)+strlen(getenv("HOME"))+2]; - retval[0]=0; //mark end + auto_ptr retval( new char[strlen(filename)+strlen(getenv("HOME"))+2]); if (filename[0]=='~') { - strcat(retval, getenv("HOME")); - strcat(retval, &filename[1]); + strcat(retval.get(), getenv("HOME")); + strcat(retval.get(), &filename[1]); } else return StringUtil::strdup(filename); //return unmodified value - return StringUtil::strdup(retval); //return modified value + return StringUtil::strdup(retval.get()); //return modified value } -- cgit v0.11.2