Advertisement
ZoriaRPG

Strip Filepath, Return Filename as std::string

Dec 10th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <algorithm>
  2.  
  3. /** Strips a path from a path+filename string, returning only the filename */
  4. std::string strip_path(std::string *pth_str, bool lowercase)
  5. {
  6.     std::size_t found = 0;
  7.     std::size_t found1 = pth_str.find_last_of("/");
  8.     std::size_t found2 = pth_str.find_last_of("\\");
  9.     found = ( found2 > found1 ) ? found2: found1;
  10.     std::string fileonly = pth_str.substr(found+1); //at the slash, plus one
  11.     if(lowercase)
  12.         std::transform(fileonly.begin(), fileonly.end(), fileonly.begin(), ::tolower);
  13.     return fileonly;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement