path.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2012-2014 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #pragma once
  6. #include "string_utils.h"
  7. namespace crown
  8. {
  9. /// @defgroup Path Path
  10. /// Functions for operating on strings as file paths.
  11. ///
  12. /// @ingroup Path
  13. namespace path
  14. {
  15. /// Returns whether the path segment @a segment is valid.
  16. /// @note
  17. /// The rules for valid segments are as follows:
  18. /// a) The empty string is not valid.
  19. /// b) Any string containing the slash character ('/') is not valid.
  20. /// c) Common notations for current ('.') and parent ('..') directory are forbidden.
  21. /// d) Any string containing segment or device separator characters on the local file system,
  22. /// such as the backslash ('\') and colon (':') on some file systems are not valid.
  23. /// (Thanks org.eclipse.core.runtime for the documentation ;D).
  24. bool is_valid_segment(const char* segment);
  25. /// Returns whether @a path is valid.
  26. bool is_valid_path(const char* path);
  27. /// Returns whether the path @a path is absolute.
  28. bool is_absolute_path(const char* path);
  29. void pathname(const char* path, char* str, size_t len);
  30. void filename(const char* path, char* str, size_t len);
  31. void basename(const char* path, char* str, size_t len);
  32. void extension(const char* path, char* str, size_t len);
  33. void filename_without_extension(const char* path, char* str, size_t len);
  34. //bool segments(const char* path, Array<Str>& ret);
  35. void strip_trailing_separator(const char* path, char* ret, size_t len);
  36. } // namespace path
  37. } // namespace crown