| 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 // FilePath is a container for pathnames stored in a platform's native string | 5 // FilePath is a container for pathnames stored in a platform's native string |
| 6 // type, providing containers for manipulation in according with the | 6 // type, providing containers for manipulation in according with the |
| 7 // platform's conventions for pathnames. It supports the following path | 7 // platform's conventions for pathnames. It supports the following path |
| 8 // types: | 8 // types: |
| 9 // | 9 // |
| 10 // POSIX Windows | 10 // POSIX Windows |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // FilePath treats c://, c:\\, //, and \\ all equivalently. | 96 // FilePath treats c://, c:\\, //, and \\ all equivalently. |
| 97 // Reference: | 97 // Reference: |
| 98 // The Old New Thing, "Why is a drive letter permitted in front of UNC | 98 // The Old New Thing, "Why is a drive letter permitted in front of UNC |
| 99 // paths (sometimes)?", available at: | 99 // paths (sometimes)?", available at: |
| 100 // http://blogs.msdn.com/oldnewthing/archive/2005/11/22/495740.aspx | 100 // http://blogs.msdn.com/oldnewthing/archive/2005/11/22/495740.aspx |
| 101 | 101 |
| 102 #ifndef BASE_FILES_FILE_PATH_H_ | 102 #ifndef BASE_FILES_FILE_PATH_H_ |
| 103 #define BASE_FILES_FILE_PATH_H_ | 103 #define BASE_FILES_FILE_PATH_H_ |
| 104 | 104 |
| 105 #include <stddef.h> | 105 #include <stddef.h> |
| 106 |
| 107 #include <iosfwd> |
| 106 #include <string> | 108 #include <string> |
| 107 #include <vector> | 109 #include <vector> |
| 108 | 110 |
| 109 #include "base/base_export.h" | 111 #include "base/base_export.h" |
| 110 #include "base/compiler_specific.h" | 112 #include "base/compiler_specific.h" |
| 111 #include "base/containers/hash_tables.h" | 113 #include "base/containers/hash_tables.h" |
| 112 #include "base/strings/string16.h" | 114 #include "base/strings/string16.h" |
| 113 #include "base/strings/string_piece.h" // For implicit conversions. | 115 #include "base/strings/string_piece.h" // For implicit conversions. |
| 114 #include "build/build_config.h" | 116 #include "build/build_config.h" |
| 115 | 117 |
| 116 // Windows-style drive letter support and pathname separator characters can be | 118 // Windows-style drive letter support and pathname separator characters can be |
| 117 // enabled and disabled independently, to aid testing. These #defines are | 119 // enabled and disabled independently, to aid testing. These #defines are |
| 118 // here so that the same setting can be used in both the implementation and | 120 // here so that the same setting can be used in both the implementation and |
| 119 // in the unit test. | 121 // in the unit test. |
| 120 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
| 121 #define FILE_PATH_USES_DRIVE_LETTERS | 123 #define FILE_PATH_USES_DRIVE_LETTERS |
| 122 #define FILE_PATH_USES_WIN_SEPARATORS | 124 #define FILE_PATH_USES_WIN_SEPARATORS |
| 123 #endif // OS_WIN | 125 #endif // OS_WIN |
| 124 | 126 |
| 127 namespace base { |
| 128 |
| 125 class Pickle; | 129 class Pickle; |
| 126 class PickleIterator; | 130 class PickleIterator; |
| 127 | 131 |
| 128 namespace base { | |
| 129 | |
| 130 // An abstraction to isolate users from the differences between native | 132 // An abstraction to isolate users from the differences between native |
| 131 // pathnames on different platforms. | 133 // pathnames on different platforms. |
| 132 class BASE_EXPORT FilePath { | 134 class BASE_EXPORT FilePath { |
| 133 public: | 135 public: |
| 134 #if defined(OS_POSIX) | 136 #if defined(OS_POSIX) |
| 135 // On most platforms, native pathnames are char arrays, and the encoding | 137 // On most platforms, native pathnames are char arrays, and the encoding |
| 136 // may or may not be specified. On Mac OS X, native pathnames are encoded | 138 // may or may not be specified. On Mac OS X, native pathnames are encoded |
| 137 // in UTF-8. | 139 // in UTF-8. |
| 138 typedef std::string StringType; | 140 typedef std::string StringType; |
| 139 #elif defined(OS_WIN) | 141 #elif defined(OS_WIN) |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 // Remove trailing separators from this object. If the path is absolute, it | 428 // Remove trailing separators from this object. If the path is absolute, it |
| 427 // will never be stripped any more than to refer to the absolute root | 429 // will never be stripped any more than to refer to the absolute root |
| 428 // directory, so "////" will become "/", not "". A leading pair of | 430 // directory, so "////" will become "/", not "". A leading pair of |
| 429 // separators is never stripped, to support alternate roots. This is used to | 431 // separators is never stripped, to support alternate roots. This is used to |
| 430 // support UNC paths on Windows. | 432 // support UNC paths on Windows. |
| 431 void StripTrailingSeparatorsInternal(); | 433 void StripTrailingSeparatorsInternal(); |
| 432 | 434 |
| 433 StringType path_; | 435 StringType path_; |
| 434 }; | 436 }; |
| 435 | 437 |
| 438 // This is required by googletest to print a readable output on test failures. |
| 439 // This is declared here for use in gtest-based unit tests but is defined in |
| 440 // the test_support_base target. Depend on that to use this in your unit test. |
| 441 // This should not be used in production code - call ToString() instead. |
| 442 void PrintTo(const FilePath& path, std::ostream* out); |
| 443 |
| 436 } // namespace base | 444 } // namespace base |
| 437 | 445 |
| 438 // This is required by googletest to print a readable output on test failures. | |
| 439 BASE_EXPORT extern void PrintTo(const base::FilePath& path, std::ostream* out); | |
| 440 | |
| 441 // Macros for string literal initialization of FilePath::CharType[], and for | 446 // Macros for string literal initialization of FilePath::CharType[], and for |
| 442 // using a FilePath::CharType[] in a printf-style format string. | 447 // using a FilePath::CharType[] in a printf-style format string. |
| 443 #if defined(OS_POSIX) | 448 #if defined(OS_POSIX) |
| 444 #define FILE_PATH_LITERAL(x) x | 449 #define FILE_PATH_LITERAL(x) x |
| 445 #define PRFilePath "s" | 450 #define PRFilePath "s" |
| 446 #elif defined(OS_WIN) | 451 #elif defined(OS_WIN) |
| 447 #define FILE_PATH_LITERAL(x) L ## x | 452 #define FILE_PATH_LITERAL(x) L ## x |
| 448 #define PRFilePath "ls" | 453 #define PRFilePath "ls" |
| 449 #endif // OS_WIN | 454 #endif // OS_WIN |
| 450 | 455 |
| 451 // Provide a hash function so that hash_sets and maps can contain FilePath | 456 // Provide a hash function so that hash_sets and maps can contain FilePath |
| 452 // objects. | 457 // objects. |
| 453 namespace BASE_HASH_NAMESPACE { | 458 namespace BASE_HASH_NAMESPACE { |
| 454 | 459 |
| 455 template<> | 460 template<> |
| 456 struct hash<base::FilePath> { | 461 struct hash<base::FilePath> { |
| 457 size_t operator()(const base::FilePath& f) const { | 462 size_t operator()(const base::FilePath& f) const { |
| 458 return hash<base::FilePath::StringType>()(f.value()); | 463 return hash<base::FilePath::StringType>()(f.value()); |
| 459 } | 464 } |
| 460 }; | 465 }; |
| 461 | 466 |
| 462 } // namespace BASE_HASH_NAMESPACE | 467 } // namespace BASE_HASH_NAMESPACE |
| 463 | 468 |
| 464 #endif // BASE_FILES_FILE_PATH_H_ | 469 #endif // BASE_FILES_FILE_PATH_H_ |
| OLD | NEW |