pathinfo.cpp 970 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "pathinfo.h"
  2. #include "dirname.h"
  3. #include "basename.h"
  4. // Verbose should be removed once everythings working correctly
  5. #include "verbose.h"
  6. #include <algorithm>
  7. IGL_INLINE void igl::pathinfo(
  8. const std::string & path,
  9. std::string & dirname,
  10. std::string & basename,
  11. std::string & extension,
  12. std::string & filename)
  13. {
  14. dirname = igl::dirname(path);
  15. basename = igl::basename(path);
  16. std::string::reverse_iterator last_dot =
  17. std::find(
  18. basename.rbegin(),
  19. basename.rend(), '.');
  20. // Was a dot found?
  21. if(last_dot == basename.rend())
  22. {
  23. // filename is same as basename
  24. filename = basename;
  25. // no extension
  26. extension = "";
  27. }else
  28. {
  29. // extension is substring of basename
  30. extension = std::string(last_dot.base(),basename.end());
  31. // filename is substring of basename
  32. filename = std::string(basename.begin(),last_dot.base()-1);
  33. }
  34. }
  35. #ifndef IGL_HEADER_ONLY
  36. // Explicit template specialization
  37. #endif