summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-08-14 22:43:30 (GMT)
committerfluxgen <fluxgen>2002-08-14 22:43:30 (GMT)
commit781fb842420ffda1bb639918ec771dc93c187a21 (patch)
tree4a90bb706653d451995c7b9b20abe67c9b9d56ff /src
parent0b25dc379cdcea545c93fcc6108c500f805c1f10 (diff)
downloadfluxbox_lack-781fb842420ffda1bb639918ec771dc93c187a21.zip
fluxbox_lack-781fb842420ffda1bb639918ec771dc93c187a21.tar.bz2
changed to std string in expandFilename
Diffstat (limited to 'src')
-rw-r--r--src/StringUtil.cc23
-rw-r--r--src/StringUtil.hh4
2 files changed, 15 insertions, 12 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 -----------
diff --git a/src/StringUtil.hh b/src/StringUtil.hh
index cd3e0c0..f2f4944 100644
--- a/src/StringUtil.hh
+++ b/src/StringUtil.hh
@@ -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.hh,v 1.8 2002/04/12 15:06:07 fluxgen Exp $ 22//$Id: StringUtil.hh,v 1.9 2002/08/14 22:43:30 fluxgen Exp $
23 23
24#ifndef STRINGUTIL_HH 24#ifndef STRINGUTIL_HH
25#define STRINGUTIL_HH 25#define STRINGUTIL_HH
@@ -34,7 +34,7 @@ char *strdup(const char *);
34//Similar to `strstr' but this function ignores the case of both strings 34//Similar to `strstr' but this function ignores the case of both strings
35const char *strcasestr(const char *str, const char *ptn); 35const char *strcasestr(const char *str, const char *ptn);
36 36
37char *expandFilename(const char *filename); 37std::string expandFilename(const std::string &filename);
38int getStringBetween(std::string& out, const char *instr, const char first, const char last, 38int getStringBetween(std::string& out, const char *instr, const char first, const char last,
39 const char *ok_chars=" \t\n"); 39 const char *ok_chars=" \t\n");
40 40