2
0

path.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "string_utils.h"
  25. namespace crown
  26. {
  27. /// @defgroup Path Path
  28. /// Functions for operating on strings as file paths.
  29. ///
  30. /// @ingroup Path
  31. namespace path
  32. {
  33. /// Returns whether the path segment @a segment is valid.
  34. /// @note
  35. /// The rules for valid segments are as follows:
  36. /// a) The empty string is not valid.
  37. /// b) Any string containing the slash character ('/') is not valid.
  38. /// c) Common notations for current ('.') and parent ('..') directory are forbidden.
  39. /// d) Any string containing segment or device separator characters on the local file system,
  40. /// such as the backslash ('\') and colon (':') on some file systems are not valid.
  41. /// (Thanks org.eclipse.core.runtime for the documentation ;D).
  42. bool is_valid_segment(const char* segment);
  43. /// Returns whether @a path is valid.
  44. bool is_valid_path(const char* path);
  45. /// Returns whether the path @a path is absolute.
  46. bool is_absolute_path(const char* path);
  47. void pathname(const char* path, char* str, size_t len);
  48. void filename(const char* path, char* str, size_t len);
  49. void basename(const char* path, char* str, size_t len);
  50. void extension(const char* path, char* str, size_t len);
  51. void filename_without_extension(const char* path, char* str, size_t len);
  52. //bool segments(const char* path, Array<Str>& ret);
  53. void strip_trailing_separator(const char* path, char* ret, size_t len);
  54. } // namespace path
  55. } // namespace crown