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.

89 lines
1.9 KiB

6 years ago
6 years ago
  1. /*
  2. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #pragma once
  15. #include "ghc/filesystem.hpp"
  16. #include <string>
  17. #include <vector>
  18. namespace fs
  19. {
  20. typedef ghc::filesystem::path Path;
  21. namespace path
  22. {
  23. std::string dirname(const char *path);
  24. std::string dirname(const std::string &path);
  25. std::string basename(const std::string &path);
  26. static
  27. inline
  28. void
  29. append(std::string &base_,
  30. const char *suffix_)
  31. {
  32. base_ += suffix_;
  33. }
  34. static
  35. inline
  36. void
  37. append(std::string &base_,
  38. const std::string &suffix_)
  39. {
  40. base_ += suffix_;
  41. }
  42. static
  43. inline
  44. std::string
  45. make(const char *base_,
  46. const char *suffix_)
  47. {
  48. char back;
  49. std::string path(base_);
  50. back = *path.rbegin();
  51. if((back != '/') && (suffix_[0] != '/'))
  52. path.push_back('/');
  53. path += suffix_;
  54. return path;
  55. }
  56. static
  57. inline
  58. std::string
  59. make(const std::string &base_,
  60. const char *suffix_)
  61. {
  62. return (base_ + suffix_);
  63. }
  64. static
  65. inline
  66. std::string
  67. make(const std::string &base_,
  68. const std::string &suffix_)
  69. {
  70. return (base_ + suffix_);
  71. }
  72. }
  73. };