Filesystem.cpp 963 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Util/Filesystem.h>
  6. namespace anki
  7. {
  8. void getFilepathExtension(const CString& filename, StringAuto& out)
  9. {
  10. const char* pc = std::strrchr(filename.cstr(), '.');
  11. if(pc == nullptr)
  12. {
  13. // Do nothing
  14. }
  15. else
  16. {
  17. ++pc;
  18. if(*pc != '\0')
  19. {
  20. out.create(CString(pc));
  21. }
  22. }
  23. }
  24. void getFilepathFilename(const CString& filename, StringAuto& out)
  25. {
  26. const char* pc = std::strrchr(filename.cstr(), '/');
  27. if(pc == nullptr)
  28. {
  29. out.create(filename);
  30. }
  31. else
  32. {
  33. ++pc;
  34. if(*pc != '\0')
  35. {
  36. out.create(CString(pc));
  37. }
  38. }
  39. }
  40. void getParentFilepath(const CString& filename, StringAuto& out)
  41. {
  42. const char* pc = std::strrchr(filename.cstr(), '/');
  43. if(pc == nullptr)
  44. {
  45. out.create("");
  46. }
  47. else
  48. {
  49. out.create(filename.cstr(), pc);
  50. }
  51. }
  52. } // end namespace anki