SkOSPath.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright 2011 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. #include "src/utils/SkOSPath.h"
  8. SkString SkOSPath::Join(const char *rootPath, const char *relativePath) {
  9. SkString result(rootPath);
  10. if (!result.endsWith(SEPARATOR) && !result.isEmpty()) {
  11. result.appendUnichar(SEPARATOR);
  12. }
  13. result.append(relativePath);
  14. return result;
  15. }
  16. SkString SkOSPath::Basename(const char* fullPath) {
  17. if (!fullPath) {
  18. return SkString();
  19. }
  20. const char* filename = strrchr(fullPath, SEPARATOR);
  21. if (nullptr == filename) {
  22. filename = fullPath;
  23. } else {
  24. ++filename;
  25. }
  26. return SkString(filename);
  27. }
  28. SkString SkOSPath::Dirname(const char* fullPath) {
  29. if (!fullPath) {
  30. return SkString();
  31. }
  32. const char* end = strrchr(fullPath, SEPARATOR);
  33. if (nullptr == end) {
  34. return SkString();
  35. }
  36. if (end == fullPath) {
  37. SkASSERT(fullPath[0] == SEPARATOR);
  38. ++end;
  39. }
  40. return SkString(fullPath, end - fullPath);
  41. }