SkOSPath.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkOSPath_DEFINED
  8. #define SkOSPath_DEFINED
  9. #include "include/core/SkString.h"
  10. /**
  11. * Functions for modifying SkStrings which represent paths on the filesystem.
  12. */
  13. class SkOSPath {
  14. public:
  15. #ifdef _WIN32
  16. const static char SEPARATOR = '\\';
  17. #else
  18. const static char SEPARATOR = '/';
  19. #endif
  20. /**
  21. * Assembles rootPath and relativePath into a single path, like this:
  22. * rootPath/relativePath.
  23. * It is okay to call with a NULL rootPath and/or relativePath. A path
  24. * separator will still be inserted.
  25. *
  26. * Uses SkPATH_SEPARATOR, to work on all platforms.
  27. */
  28. static SkString Join(const char* rootPath, const char* relativePath);
  29. /**
  30. * Return the name of the file, ignoring the directory structure.
  31. * Behaves like python's os.path.basename. If the fullPath is
  32. * /dir/subdir/, an empty string is returned.
  33. * @param fullPath Full path to the file.
  34. * @return SkString The basename of the file - anything beyond the
  35. * final slash, or the full name if there is no slash.
  36. */
  37. static SkString Basename(const char* fullPath);
  38. /**
  39. * Given a qualified file name returns the directory.
  40. * Behaves like python's os.path.dirname. If the fullPath is
  41. * /dir/subdir/ the return will be /dir/subdir/
  42. * @param fullPath Full path to the file.
  43. * @return SkString The dir containing the file - anything preceding the
  44. * final slash, or the full name if ending in a slash.
  45. */
  46. static SkString Dirname(const char* fullPath);
  47. };
  48. #endif