Changeset 1425
- Timestamp:
- Dec 16, 2011, 5:06:18 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/utility.cc
r1424 r1425 41 41 42 42 #include <iostream> 43 44 #include <libgen.h> 43 45 44 46 namespace theplu{ … … 117 119 std::string directory_name(std::string path) 118 120 { 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()); 125 122 } 126 123 … … 128 125 std::string file_name(const std::string& full_path) 129 126 { 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()); 137 128 } 138 129
Note: See TracChangeset
for help on using the changeset viewer.