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