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