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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 return Append(ASCIIToUTF16(component.as_string())); | 514 return Append(ASCIIToUTF16(component.as_string())); |
515 #elif defined(OS_POSIX) | 515 #elif defined(OS_POSIX) |
516 return Append(component.as_string()); | 516 return Append(component.as_string()); |
517 #endif | 517 #endif |
518 } | 518 } |
519 | 519 |
520 bool FilePath::IsAbsolute() const { | 520 bool FilePath::IsAbsolute() const { |
521 return IsPathAbsolute(path_); | 521 return IsPathAbsolute(path_); |
522 } | 522 } |
523 | 523 |
| 524 bool FilePath::EndsWithSeparator() const { |
| 525 if (empty()) |
| 526 return false; |
| 527 return IsSeparator(path_[path_.size() - 1]); |
| 528 } |
| 529 |
| 530 FilePath FilePath::AsEndingWithSeparator() const { |
| 531 if (EndsWithSeparator() || path_.empty()) |
| 532 return *this; |
| 533 |
| 534 StringType path_str; |
| 535 path_str.reserve(path_.length() + 1); // Only allocate string once. |
| 536 |
| 537 path_str = path_; |
| 538 path_str.append(&kSeparators[0], 1); |
| 539 return FilePath(path_str); |
| 540 } |
| 541 |
524 FilePath FilePath::StripTrailingSeparators() const { | 542 FilePath FilePath::StripTrailingSeparators() const { |
525 FilePath new_path(path_); | 543 FilePath new_path(path_); |
526 new_path.StripTrailingSeparatorsInternal(); | 544 new_path.StripTrailingSeparatorsInternal(); |
527 | 545 |
528 return new_path; | 546 return new_path; |
529 } | 547 } |
530 | 548 |
531 bool FilePath::ReferencesParent() const { | 549 bool FilePath::ReferencesParent() const { |
532 std::vector<StringType> components; | 550 std::vector<StringType> components; |
533 GetComponents(&components); | 551 GetComponents(&components); |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 #else | 1269 #else |
1252 return *this; | 1270 return *this; |
1253 #endif | 1271 #endif |
1254 } | 1272 } |
1255 | 1273 |
1256 } // namespace base | 1274 } // namespace base |
1257 | 1275 |
1258 void PrintTo(const base::FilePath& path, std::ostream* out) { | 1276 void PrintTo(const base::FilePath& path, std::ostream* out) { |
1259 *out << path.value(); | 1277 *out << path.value(); |
1260 } | 1278 } |
OLD | NEW |