all repos — fluxbox @ 781fb842420ffda1bb639918ec771dc93c187a21

custom fork of the fluxbox windowmanager

changed to std string in expandFilename
fluxgen fluxgen
commit

781fb842420ffda1bb639918ec771dc93c187a21

parent

0b25dc379cdcea545c93fcc6108c500f805c1f10

2 files changed, 15 insertions(+), 12 deletions(-)

jump to
M src/StringUtil.ccsrc/StringUtil.cc

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// 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 @@

//------------- 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 -----------
M src/StringUtil.hhsrc/StringUtil.hh

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// 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 @@

//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");