Filesystem.cpp 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. void getFilepathExtension(const CString& filename, StringAuto& out)
  8. {
  9. const char* pc = std::strrchr(filename.cstr(), '.');
  10. if(pc == nullptr)
  11. {
  12. // Do nothing
  13. }
  14. else
  15. {
  16. ++pc;
  17. if(*pc != '\0')
  18. {
  19. out.create(CString(pc));
  20. }
  21. }
  22. }
  23. void getFilepathFilename(const CString& filename, StringAuto& out)
  24. {
  25. const char* pc = std::strrchr(filename.cstr(), '/');
  26. if(pc == nullptr)
  27. {
  28. out.create(filename);
  29. }
  30. else
  31. {
  32. ++pc;
  33. if(*pc != '\0')
  34. {
  35. out.create(CString(pc));
  36. }
  37. }
  38. }
  39. void getParentFilepath(const CString& filename, StringAuto& out)
  40. {
  41. const char* pc = std::strrchr(filename.cstr(), '/');
  42. if(pc == nullptr)
  43. {
  44. out.create("");
  45. }
  46. else
  47. {
  48. out.create(filename.cstr(), pc);
  49. }
  50. }
  51. } // end namespace anki