Changeset 1425


Ignore:
Timestamp:
Dec 16, 2011, 5:06:18 AM (11 years ago)
Author:
Peter Johansson
Message:

use posix functions http://linux.die.net/man/3/basename

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/utility.cc

    r1424 r1425  
    4141
    4242#include <iostream>
     43
     44#include <libgen.h>
    4345
    4446namespace theplu{
     
    117119  std::string directory_name(std::string path)
    118120  {
    119     size_t pos = path.find_last_of("/");
    120     if (pos==std::string::npos)
    121       return ".";
    122     if (pos==path.size()-1)
    123       return directory_name(path.substr(0,path.size()-2));
    124     return path.substr(0,pos+1);
     121    return dirname(path.c_str());
    125122  }
    126123
     
    128125  std::string file_name(const std::string& full_path)
    129126  {
    130     if (full_path.size()<2)
    131       return full_path;
    132     // exclude last char from search
    133     size_t pos = full_path.find_last_of('/', full_path.size()-2);
    134     if (pos==std::string::npos)
    135       return full_path;
    136     return full_path.substr(pos+1);
     127    return basename(full_path.c_str());
    137128  }
    138129
Note: See TracChangeset for help on using the changeset viewer.