pathinfo.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "pathinfo.h"
  9. #include "dirname.h"
  10. #include "basename.h"
  11. // Verbose should be removed once everythings working correctly
  12. #include "verbose.h"
  13. #include <algorithm>
  14. IGL_INLINE void igl::pathinfo(
  15. const std::string & path,
  16. std::string & dirname,
  17. std::string & basename,
  18. std::string & extension,
  19. std::string & filename)
  20. {
  21. dirname = igl::dirname(path);
  22. basename = igl::basename(path);
  23. std::string::reverse_iterator last_dot =
  24. std::find(
  25. basename.rbegin(),
  26. basename.rend(), '.');
  27. // Was a dot found?
  28. if(last_dot == basename.rend())
  29. {
  30. // filename is same as basename
  31. filename = basename;
  32. // no extension
  33. extension = "";
  34. }else
  35. {
  36. // extension is substring of basename
  37. extension = std::string(last_dot.base(),basename.end());
  38. // filename is substring of basename
  39. filename = std::string(basename.begin(),last_dot.base()-1);
  40. }
  41. }
  42. #ifdef IGL_STATIC_LIBRARY
  43. // Explicit template specialization
  44. #endif