aboutsummaryrefslogtreecommitdiff
path: root/src/StringUtil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/StringUtil.cc')
-rw-r--r--src/StringUtil.cc23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/StringUtil.cc b/src/StringUtil.cc
index 9c32e6b..1a9e7f1 100644
--- a/src/StringUtil.cc
+++ b/src/StringUtil.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: StringUtil.cc,v 1.10 2002/05/17 16:31:34 fluxgen Exp $ 22// $Id: StringUtil.cc,v 1.11 2002/08/14 22:43:30 fluxgen Exp $
23 23
24#include "StringUtil.hh" 24#include "StringUtil.hh"
25 25
@@ -66,18 +66,21 @@ const char *strcasestr(const char *str, const char *ptn) {
66//------------- expandFilename ---------------------- 66//------------- expandFilename ----------------------
67// if ~ then expand it to home of user 67// if ~ then expand it to home of user
68// returns expanded filename 68// returns expanded filename
69// (note: the function creates new memory for the string)
70//--------------------------------------------------- 69//---------------------------------------------------
71char *expandFilename(const char *filename) { 70string expandFilename(const std::string &filename) {
72 71
73 auto_ptr<char> retval( new char[strlen(filename)+strlen(getenv("HOME"))+2]); 72 string retval;
74 if (filename[0]=='~') { 73 size_t pos = filename.find_first_not_of(" \t");
75 strcpy(retval.get(), getenv("HOME")); 74 if (pos != std::string::npos && filename[pos] == '~') {
76 strcat(retval.get(), &filename[1]); 75 retval = getenv("HOME");
77 } else 76 if (pos != filename.size()) {
78 return StringUtil::strdup(filename); //return unmodified value 77 // copy from the character after '~'
78 retval += static_cast<const char *>(filename.c_str() + pos + 1);
79 }
80 } else
81 return filename; //return unmodified value
79 82
80 return StringUtil::strdup(retval.get()); //return modified value 83 return retval;
81} 84}
82 85
83//------------- getStringBetween ----------- 86//------------- getStringBetween -----------