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.

85 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 <string>
  16. #include <vector>
  17. namespace fs
  18. {
  19. namespace path
  20. {
  21. std::string dirname(const char *path);
  22. std::string dirname(const std::string &path);
  23. std::string basename(const std::string &path);
  24. static
  25. inline
  26. void
  27. append(std::string &base_,
  28. const char *suffix_)
  29. {
  30. base_ += suffix_;
  31. }
  32. static
  33. inline
  34. void
  35. append(std::string &base_,
  36. const std::string &suffix_)
  37. {
  38. base_ += suffix_;
  39. }
  40. static
  41. inline
  42. std::string
  43. make(const char *base_,
  44. const char *suffix_)
  45. {
  46. char back;
  47. std::string path(base_);
  48. back = *path.rbegin();
  49. if((back != '/') && (suffix_[0] != '/'))
  50. path.push_back('/');
  51. path += suffix_;
  52. return path;
  53. }
  54. static
  55. inline
  56. std::string
  57. make(const std::string &base_,
  58. const char *suffix_)
  59. {
  60. return (base_ + suffix_);
  61. }
  62. static
  63. inline
  64. std::string
  65. make(const std::string &base_,
  66. const std::string &suffix_)
  67. {
  68. return (base_ + suffix_);
  69. }
  70. }
  71. };