You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
976B

  1. #include "Path.hpp"
  2. #include <iostream>
  3. std::string Path::extractFileName(std::string const& path)
  4. {
  5. auto lastSlashPos = path.find_last_of("\\/");
  6. auto lastDotPos = path.find_last_of(".");
  7. if (lastSlashPos == std::string::npos)
  8. {
  9. lastSlashPos = 0u;
  10. }
  11. else
  12. {
  13. lastSlashPos += 1;
  14. }
  15. if (lastDotPos == std::string::npos)
  16. {
  17. lastDotPos = path.size();
  18. }
  19. auto const extractSize = lastDotPos - lastSlashPos;
  20. return path.substr(lastSlashPos, extractSize);
  21. }
  22. std::string Path::extractFileNameWithExtension(std::string const& path)
  23. {
  24. auto lastSlashPos = path.find_last_of("\\/");
  25. if (lastSlashPos == std::string::npos)
  26. {
  27. lastSlashPos = 0u;
  28. }
  29. else
  30. {
  31. lastSlashPos += 1;
  32. }
  33. return path.substr(lastSlashPos);
  34. }
  35. std::string Path::extractExtension(std::string const& path)
  36. {
  37. auto lastDotPos = path.find_last_of(".");
  38. if (lastDotPos != std::string::npos)
  39. {
  40. lastDotPos += 1;
  41. }
  42. else
  43. {
  44. lastDotPos = path.size();
  45. }
  46. return path.substr(lastDotPos);
  47. }