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