changed to std string in expandFilename
This commit is contained in:
parent
0b25dc379c
commit
781fb84242
2 changed files with 15 additions and 12 deletions
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// $Id: StringUtil.cc,v 1.10 2002/05/17 16:31:34 fluxgen Exp $
|
||||
// $Id: StringUtil.cc,v 1.11 2002/08/14 22:43:30 fluxgen Exp $
|
||||
|
||||
#include "StringUtil.hh"
|
||||
|
||||
|
@ -66,18 +66,21 @@ const char *strcasestr(const char *str, const char *ptn) {
|
|||
//------------- expandFilename ----------------------
|
||||
// if ~ then expand it to home of user
|
||||
// returns expanded filename
|
||||
// (note: the function creates new memory for the string)
|
||||
//---------------------------------------------------
|
||||
char *expandFilename(const char *filename) {
|
||||
string expandFilename(const std::string &filename) {
|
||||
|
||||
auto_ptr<char> retval( new char[strlen(filename)+strlen(getenv("HOME"))+2]);
|
||||
if (filename[0]=='~') {
|
||||
strcpy(retval.get(), getenv("HOME"));
|
||||
strcat(retval.get(), &filename[1]);
|
||||
} else
|
||||
return StringUtil::strdup(filename); //return unmodified value
|
||||
string retval;
|
||||
size_t pos = filename.find_first_not_of(" \t");
|
||||
if (pos != std::string::npos && filename[pos] == '~') {
|
||||
retval = getenv("HOME");
|
||||
if (pos != filename.size()) {
|
||||
// copy from the character after '~'
|
||||
retval += static_cast<const char *>(filename.c_str() + pos + 1);
|
||||
}
|
||||
} else
|
||||
return filename; //return unmodified value
|
||||
|
||||
return StringUtil::strdup(retval.get()); //return modified value
|
||||
return retval;
|
||||
}
|
||||
|
||||
//------------- getStringBetween -----------
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
//$Id: StringUtil.hh,v 1.8 2002/04/12 15:06:07 fluxgen Exp $
|
||||
//$Id: StringUtil.hh,v 1.9 2002/08/14 22:43:30 fluxgen Exp $
|
||||
|
||||
#ifndef STRINGUTIL_HH
|
||||
#define STRINGUTIL_HH
|
||||
|
@ -34,7 +34,7 @@ char *strdup(const char *);
|
|||
//Similar to `strstr' but this function ignores the case of both strings
|
||||
const char *strcasestr(const char *str, const char *ptn);
|
||||
|
||||
char *expandFilename(const char *filename);
|
||||
std::string expandFilename(const std::string &filename);
|
||||
int getStringBetween(std::string& out, const char *instr, const char first, const char last,
|
||||
const char *ok_chars=" \t\n");
|
||||
|
||||
|
|
Loading…
Reference in a new issue