aboutsummaryrefslogtreecommitdiff
path: root/src/StringUtil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/StringUtil.cc')
-rw-r--r--src/StringUtil.cc25
1 files 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 @@
21 21
22#include "StringUtil.hh" 22#include "StringUtil.hh"
23 23
24#include <stdlib.h> 24#include <string>
25#include <string.h> 25#include <cstdio>
26#include <stdio.h> 26#include <cstdlib>
27#include <ctype.h> 27#include <cctype>
28#include <memory>
29
30using namespace std;
28 31
29//------- strdup ------------------------ 32//------- strdup ------------------------
30//TODO: comment this 33//TODO: comment this
@@ -37,12 +40,15 @@ char *StringUtil::strdup(const char *s) {
37} 40}
38 41
39//------- strcasestr -------------- 42//------- strcasestr --------------
43// Tries to find a string in another and
44// ignoring the case of the characters
45// Returns 0 on success else pointer to str.
40// TODO: comment this 46// TODO: comment this
41//--------------------------------- 47//---------------------------------
42const char * StringUtil::strcasestr(const char *str, const char *ptn) { 48const char * StringUtil::strcasestr(const char *str, const char *ptn) {
43 const char *s2, *p2; 49 const char *s2, *p2;
44 for( ; *str; str++) { 50 for( ; *str; str++) {
45 for(s2=str,p2=ptn; ; s2++,p2++) { 51 for(s2=str, p2=ptn; ; s2++,p2++) {
46 if (!*p2) return str; 52 if (!*p2) return str;
47 if (toupper(*s2) != toupper(*p2)) break; 53 if (toupper(*s2) != toupper(*p2)) break;
48 } 54 }
@@ -57,13 +63,12 @@ const char * StringUtil::strcasestr(const char *str, const char *ptn) {
57//--------------------------------------------------- 63//---------------------------------------------------
58char *StringUtil::expandFilename(const char *filename) { 64char *StringUtil::expandFilename(const char *filename) {
59 65
60 char retval[strlen(filename)+strlen(getenv("HOME"))+2]; 66 auto_ptr<char> retval( new char[strlen(filename)+strlen(getenv("HOME"))+2]);
61 retval[0]=0; //mark end
62 if (filename[0]=='~') { 67 if (filename[0]=='~') {
63 strcat(retval, getenv("HOME")); 68 strcat(retval.get(), getenv("HOME"));
64 strcat(retval, &filename[1]); 69 strcat(retval.get(), &filename[1]);
65 } else 70 } else
66 return StringUtil::strdup(filename); //return unmodified value 71 return StringUtil::strdup(filename); //return unmodified value
67 72
68 return StringUtil::strdup(retval); //return modified value 73 return StringUtil::strdup(retval.get()); //return modified value
69} 74}