epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | #include "SkOSFile.h" |
| 8 | |
tfarina | a8e2e15 | 2014-07-28 19:26:58 -0700 | [diff] [blame] | 9 | SkString SkOSPath::Join(const char *rootPath, const char *relativePath) { |
scroggo@google.com | ccd7afb | 2013-05-28 16:45:07 +0000 | [diff] [blame] | 10 | SkString result(rootPath); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 11 | if (!result.endsWith(SkPATH_SEPARATOR) && !result.isEmpty()) { |
scroggo@google.com | ccd7afb | 2013-05-28 16:45:07 +0000 | [diff] [blame] | 12 | result.appendUnichar(SkPATH_SEPARATOR); |
| 13 | } |
| 14 | result.append(relativePath); |
| 15 | return result; |
| 16 | } |
| 17 | |
tfarina | a8e2e15 | 2014-07-28 19:26:58 -0700 | [diff] [blame] | 18 | SkString SkOSPath::Basename(const char* fullPath) { |
scroggo@google.com | ccd7afb | 2013-05-28 16:45:07 +0000 | [diff] [blame] | 19 | if (!fullPath) { |
| 20 | return SkString(); |
| 21 | } |
| 22 | const char* filename = strrchr(fullPath, SkPATH_SEPARATOR); |
| 23 | if (NULL == filename) { |
| 24 | filename = fullPath; |
| 25 | } else { |
| 26 | ++filename; |
| 27 | } |
| 28 | return SkString(filename); |
| 29 | } |
| 30 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 31 | SkString SkOSPath::Dirname(const char* fullPath) { |
| 32 | if (!fullPath) { |
| 33 | return SkString(); |
| 34 | } |
| 35 | const char* end = strrchr(fullPath, SkPATH_SEPARATOR); |
| 36 | if (NULL == end) { |
| 37 | return SkString(); |
| 38 | } |
| 39 | if (end == fullPath) { |
| 40 | SkASSERT(fullPath[0] == SkPATH_SEPARATOR); |
| 41 | ++end; |
| 42 | } |
| 43 | return SkString(fullPath, end - fullPath); |
| 44 | } |