1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2011 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "src/utils/SkOSPath.h"
9cb93a386Sopenharmony_ci
10cb93a386Sopenharmony_ciSkString SkOSPath::Join(const char *rootPath, const char *relativePath) {
11cb93a386Sopenharmony_ci    SkString result(rootPath);
12cb93a386Sopenharmony_ci    if (!result.endsWith(SEPARATOR) && !result.isEmpty()) {
13cb93a386Sopenharmony_ci        result.appendUnichar(SEPARATOR);
14cb93a386Sopenharmony_ci    }
15cb93a386Sopenharmony_ci    result.append(relativePath);
16cb93a386Sopenharmony_ci    return result;
17cb93a386Sopenharmony_ci}
18cb93a386Sopenharmony_ci
19cb93a386Sopenharmony_ciSkString SkOSPath::Basename(const char* fullPath) {
20cb93a386Sopenharmony_ci    if (!fullPath) {
21cb93a386Sopenharmony_ci        return SkString();
22cb93a386Sopenharmony_ci    }
23cb93a386Sopenharmony_ci    const char* filename = strrchr(fullPath, SEPARATOR);
24cb93a386Sopenharmony_ci    if (nullptr == filename) {
25cb93a386Sopenharmony_ci        filename = fullPath;
26cb93a386Sopenharmony_ci    } else {
27cb93a386Sopenharmony_ci        ++filename;
28cb93a386Sopenharmony_ci    }
29cb93a386Sopenharmony_ci    return SkString(filename);
30cb93a386Sopenharmony_ci}
31cb93a386Sopenharmony_ci
32cb93a386Sopenharmony_ciSkString SkOSPath::Dirname(const char* fullPath) {
33cb93a386Sopenharmony_ci    if (!fullPath) {
34cb93a386Sopenharmony_ci        return SkString();
35cb93a386Sopenharmony_ci    }
36cb93a386Sopenharmony_ci    const char* end = strrchr(fullPath, SEPARATOR);
37cb93a386Sopenharmony_ci    if (nullptr == end) {
38cb93a386Sopenharmony_ci        return SkString();
39cb93a386Sopenharmony_ci    }
40cb93a386Sopenharmony_ci    if (end == fullPath) {
41cb93a386Sopenharmony_ci        SkASSERT(fullPath[0] == SEPARATOR);
42cb93a386Sopenharmony_ci        ++end;
43cb93a386Sopenharmony_ci    }
44cb93a386Sopenharmony_ci    return SkString(fullPath, end - fullPath);
45cb93a386Sopenharmony_ci}
46