| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "storage/common/fileapi/file_system_util.h" | 5 #include "storage/common/fileapi/file_system_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 // TODO(ericu): Consider removing support for '\', even on Windows, if possible. | 32 // TODO(ericu): Consider removing support for '\', even on Windows, if possible. |
| 33 // There's a lot of test code that will need reworking, and we may have trouble | 33 // There's a lot of test code that will need reworking, and we may have trouble |
| 34 // with base::FilePath elsewhere [e.g. DirName and other methods may also need | 34 // with base::FilePath elsewhere [e.g. DirName and other methods may also need |
| 35 // replacement]. | 35 // replacement]. |
| 36 base::FilePath VirtualPath::BaseName(const base::FilePath& virtual_path) { | 36 base::FilePath VirtualPath::BaseName(const base::FilePath& virtual_path) { |
| 37 base::FilePath::StringType path = virtual_path.value(); | 37 base::FilePath::StringType path = virtual_path.value(); |
| 38 | 38 |
| 39 // Keep everything after the final separator, but if the pathname is only | 39 // Keep everything after the final separator, but if the pathname is only |
| 40 // one character and it's a separator, leave it alone. | 40 // one character and it's a separator, leave it alone. |
| 41 while (path.size() > 1 && base::FilePath::IsSeparator(path[path.size() - 1])) | 41 while (path.size() > 1 && base::FilePath::IsSeparator(path.back())) |
| 42 path.resize(path.size() - 1); | 42 path.resize(path.size() - 1); |
| 43 base::FilePath::StringType::size_type last_separator = | 43 base::FilePath::StringType::size_type last_separator = |
| 44 path.find_last_of(base::FilePath::kSeparators); | 44 path.find_last_of(base::FilePath::kSeparators); |
| 45 if (last_separator != base::FilePath::StringType::npos && | 45 if (last_separator != base::FilePath::StringType::npos && |
| 46 last_separator < path.size() - 1) | 46 last_separator < path.size() - 1) |
| 47 path.erase(0, last_separator + 1); | 47 path.erase(0, last_separator + 1); |
| 48 | 48 |
| 49 return base::FilePath(path); | 49 return base::FilePath(path); |
| 50 } | 50 } |
| 51 | 51 |
| 52 base::FilePath VirtualPath::DirName(const base::FilePath& virtual_path) { | 52 base::FilePath VirtualPath::DirName(const base::FilePath& virtual_path) { |
| 53 typedef base::FilePath::StringType StringType; | 53 typedef base::FilePath::StringType StringType; |
| 54 StringType path = virtual_path.value(); | 54 StringType path = virtual_path.value(); |
| 55 | 55 |
| 56 // The logic below is taken from that of base::FilePath::DirName, except | 56 // The logic below is taken from that of base::FilePath::DirName, except |
| 57 // that this version never cares about '//' or drive-letters even on win32. | 57 // that this version never cares about '//' or drive-letters even on win32. |
| 58 | 58 |
| 59 // Strip trailing separators. | 59 // Strip trailing separators. |
| 60 while (path.size() > 1 && base::FilePath::IsSeparator(path[path.size() - 1])) | 60 while (path.size() > 1 && base::FilePath::IsSeparator(path.back())) |
| 61 path.resize(path.size() - 1); | 61 path.resize(path.size() - 1); |
| 62 | 62 |
| 63 StringType::size_type last_separator = | 63 StringType::size_type last_separator = |
| 64 path.find_last_of(base::FilePath::kSeparators); | 64 path.find_last_of(base::FilePath::kSeparators); |
| 65 if (last_separator == StringType::npos) { | 65 if (last_separator == StringType::npos) { |
| 66 // path_ is in the current directory. | 66 // path_ is in the current directory. |
| 67 return base::FilePath(base::FilePath::kCurrentDirectory); | 67 return base::FilePath(base::FilePath::kCurrentDirectory); |
| 68 } | 68 } |
| 69 if (last_separator == 0) { | 69 if (last_separator == 0) { |
| 70 // path_ is in the root directory. | 70 // path_ is in the root directory. |
| 71 return base::FilePath(path.substr(0, 1)); | 71 return base::FilePath(path.substr(0, 1)); |
| 72 } | 72 } |
| 73 // path_ is somewhere else, trim the basename. | 73 // path_ is somewhere else, trim the basename. |
| 74 path.resize(last_separator); | 74 path.resize(last_separator); |
| 75 | 75 |
| 76 // Strip trailing separators. | 76 // Strip trailing separators. |
| 77 while (path.size() > 1 && base::FilePath::IsSeparator(path[path.size() - 1])) | 77 while (path.size() > 1 && base::FilePath::IsSeparator(path.back())) |
| 78 path.resize(path.size() - 1); | 78 path.resize(path.size() - 1); |
| 79 | 79 |
| 80 if (path.empty()) | 80 if (path.empty()) |
| 81 return base::FilePath(base::FilePath::kCurrentDirectory); | 81 return base::FilePath(base::FilePath::kCurrentDirectory); |
| 82 | 82 |
| 83 return base::FilePath(path); | 83 return base::FilePath(path); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void VirtualPath::GetComponents( | 86 void VirtualPath::GetComponents( |
| 87 const base::FilePath& path, | 87 const base::FilePath& path, |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 return base::File::FILE_ERROR_ABORT; | 501 return base::File::FILE_ERROR_ABORT; |
| 502 case net::ERR_ADDRESS_INVALID: | 502 case net::ERR_ADDRESS_INVALID: |
| 503 case net::ERR_INVALID_URL: | 503 case net::ERR_INVALID_URL: |
| 504 return base::File::FILE_ERROR_INVALID_URL; | 504 return base::File::FILE_ERROR_INVALID_URL; |
| 505 default: | 505 default: |
| 506 return base::File::FILE_ERROR_FAILED; | 506 return base::File::FILE_ERROR_FAILED; |
| 507 } | 507 } |
| 508 } | 508 } |
| 509 | 509 |
| 510 } // namespace storage | 510 } // namespace storage |
| OLD | NEW |