• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // FilePath is a container for pathnames stored in a platform's native string
6 // type, providing containers for manipulation in according with the
7 // platform's conventions for pathnames.  It supports the following path
8 // types:
9 //
10 //                   POSIX            Windows
11 //                   ---------------  ----------------------------------
12 // Fundamental type  char[]           wchar_t[]
13 // Encoding          unspecified*     UTF-16
14 // Separator         /                \, tolerant of /
15 // Drive letters     no               case-insensitive A-Z followed by :
16 // Alternate root    // (surprise!)   \\ (2 Separators), for UNC paths
17 //
18 // * The encoding need not be specified on POSIX systems, although some
19 //   POSIX-compliant systems do specify an encoding.  Mac OS X uses UTF-8.
20 //   Chrome OS also uses UTF-8.
21 //   Linux does not specify an encoding, but in practice, the locale's
22 //   character set may be used.
23 //
24 // For more arcane bits of path trivia, see below.
25 //
26 // FilePath objects are intended to be used anywhere paths are.  An
27 // application may pass FilePath objects around internally, masking the
28 // underlying differences between systems, only differing in implementation
29 // where interfacing directly with the system.  For example, a single
30 // OpenFile(const FilePath &) function may be made available, allowing all
31 // callers to operate without regard to the underlying implementation.  On
32 // POSIX-like platforms, OpenFile might wrap fopen, and on Windows, it might
33 // wrap _wfopen_s, perhaps both by calling file_path.value().c_str().  This
34 // allows each platform to pass pathnames around without requiring conversions
35 // between encodings, which has an impact on performance, but more imporantly,
36 // has an impact on correctness on platforms that do not have well-defined
37 // encodings for pathnames.
38 //
39 // Several methods are available to perform common operations on a FilePath
40 // object, such as determining the parent directory (DirName), isolating the
41 // final path component (BaseName), and appending a relative pathname string
42 // to an existing FilePath object (Append).  These methods are highly
43 // recommended over attempting to split and concatenate strings directly.
44 // These methods are based purely on string manipulation and knowledge of
45 // platform-specific pathname conventions, and do not consult the filesystem
46 // at all, making them safe to use without fear of blocking on I/O operations.
47 // These methods do not function as mutators but instead return distinct
48 // instances of FilePath objects, and are therefore safe to use on const
49 // objects.  The objects themselves are safe to share between threads.
50 //
51 // To aid in initialization of FilePath objects from string literals, a
52 // FILE_PATH_LITERAL macro is provided, which accounts for the difference
53 // between char[]-based pathnames on POSIX systems and wchar_t[]-based
54 // pathnames on Windows.
55 //
56 // As a precaution against premature truncation, paths can't contain NULs.
57 //
58 // Because a FilePath object should not be instantiated at the global scope,
59 // instead, use a FilePath::CharType[] and initialize it with
60 // FILE_PATH_LITERAL.  At runtime, a FilePath object can be created from the
61 // character array.  Example:
62 //
63 // | const FilePath::CharType kLogFileName[] = FILE_PATH_LITERAL("log.txt");
64 // |
65 // | void Function() {
66 // |   FilePath log_file_path(kLogFileName);
67 // |   [...]
68 // | }
69 //
70 // WARNING: FilePaths should ALWAYS be displayed with LTR directionality, even
71 // when the UI language is RTL. This means you always need to pass filepaths
72 // through base::i18n::WrapPathWithLTRFormatting() before displaying it in the
73 // RTL UI.
74 //
75 // This is a very common source of bugs, please try to keep this in mind.
76 //
77 // ARCANE BITS OF PATH TRIVIA
78 //
79 //  - A double leading slash is actually part of the POSIX standard.  Systems
80 //    are allowed to treat // as an alternate root, as Windows does for UNC
81 //    (network share) paths.  Most POSIX systems don't do anything special
82 //    with two leading slashes, but FilePath handles this case properly
83 //    in case it ever comes across such a system.  FilePath needs this support
84 //    for Windows UNC paths, anyway.
85 //    References:
86 //    The Open Group Base Specifications Issue 7, sections 3.267 ("Pathname")
87 //    and 4.12 ("Pathname Resolution"), available at:
88 //    http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_267
89 //    http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_12
90 //
91 //  - Windows treats c:\\ the same way it treats \\.  This was intended to
92 //    allow older applications that require drive letters to support UNC paths
93 //    like \\server\share\path, by permitting c:\\server\share\path as an
94 //    equivalent.  Since the OS treats these paths specially, FilePath needs
95 //    to do the same.  Since Windows can use either / or \ as the separator,
96 //    FilePath treats c://, c:\\, //, and \\ all equivalently.
97 //    Reference:
98 //    The Old New Thing, "Why is a drive letter permitted in front of UNC
99 //    paths (sometimes)?", available at:
100 //    http://blogs.msdn.com/oldnewthing/archive/2005/11/22/495740.aspx
101 
102 #ifndef BASE_FILES_FILE_PATH_H_
103 #define BASE_FILES_FILE_PATH_H_
104 
105 #include <cstddef>
106 #include <iosfwd>
107 #include <string>
108 #include <vector>
109 
110 #include "base/base_export.h"
111 #include "base/strings/string_piece.h"
112 #include "base/trace_event/base_tracing_forward.h"
113 #include "build/build_config.h"
114 
115 // Windows-style drive letter support and pathname separator characters can be
116 // enabled and disabled independently, to aid testing.  These #defines are
117 // here so that the same setting can be used in both the implementation and
118 // in the unit test.
119 #if BUILDFLAG(IS_WIN)
120 #define FILE_PATH_USES_DRIVE_LETTERS
121 #define FILE_PATH_USES_WIN_SEPARATORS
122 #endif  // BUILDFLAG(IS_WIN)
123 
124 // To print path names portably use PRFilePath (based on PRIuS and friends from
125 // C99 and format_macros.h) like this:
126 // base::StringPrintf("Path is %" PRFilePath ".\n", path.value().c_str());
127 #if BUILDFLAG(IS_WIN)
128 #define PRFilePath "ls"
129 #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
130 #define PRFilePath "s"
131 #endif  // BUILDFLAG(IS_WIN)
132 
133 // Macros for string literal initialization of FilePath::CharType[].
134 #if BUILDFLAG(IS_WIN)
135 
136 // The `FILE_PATH_LITERAL_INTERNAL` indirection allows `FILE_PATH_LITERAL` to
137 // work correctly with macro parameters, for example
138 // `FILE_PATH_LITERAL(TEST_FILE)` where `TEST_FILE` is a macro #defined as
139 // "TestFile".
140 #define FILE_PATH_LITERAL_INTERNAL(x) L##x
141 #define FILE_PATH_LITERAL(x) FILE_PATH_LITERAL_INTERNAL(x)
142 
143 #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
144 #define FILE_PATH_LITERAL(x) x
145 #endif  // BUILDFLAG(IS_WIN)
146 
147 namespace base {
148 
149 class SafeBaseName;
150 class Pickle;
151 class PickleIterator;
152 
153 // An abstraction to isolate users from the differences between native
154 // pathnames on different platforms.
155 class BASE_EXPORT FilePath {
156  public:
157 #if BUILDFLAG(IS_WIN)
158   // On Windows, for Unicode-aware applications, native pathnames are wchar_t
159   // arrays encoded in UTF-16.
160   typedef std::wstring StringType;
161 #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
162   // On most platforms, native pathnames are char arrays, and the encoding
163   // may or may not be specified.  On Mac OS X, native pathnames are encoded
164   // in UTF-8.
165   typedef std::string StringType;
166 #endif  // BUILDFLAG(IS_WIN)
167 
168   typedef StringType::value_type CharType;
169   typedef BasicStringPiece<CharType> StringPieceType;
170 
171   // Null-terminated array of separators used to separate components in paths.
172   // Each character in this array is a valid separator, but kSeparators[0] is
173   // treated as the canonical separator and is used when composing pathnames.
174   static constexpr CharType kSeparators[] =
175 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
176       FILE_PATH_LITERAL("\\/");
177 #else   // FILE_PATH_USES_WIN_SEPARATORS
178       FILE_PATH_LITERAL("/");
179 #endif  // FILE_PATH_USES_WIN_SEPARATORS
180 
181   // std::size(kSeparators), i.e., the number of separators in kSeparators plus
182   // one (the null terminator at the end of kSeparators).
183   static constexpr size_t kSeparatorsLength = std::size(kSeparators);
184 
185   // The special path component meaning "this directory."
186   static constexpr CharType kCurrentDirectory[] = FILE_PATH_LITERAL(".");
187 
188   // The special path component meaning "the parent directory."
189   static constexpr CharType kParentDirectory[] = FILE_PATH_LITERAL("..");
190 
191   // The character used to identify a file extension.
192   static constexpr CharType kExtensionSeparator = FILE_PATH_LITERAL('.');
193 
194   FilePath();
195   FilePath(const FilePath& that);
196   explicit FilePath(StringPieceType path);
197   ~FilePath();
198   FilePath& operator=(const FilePath& that);
199 
200   // Constructs FilePath with the contents of |that|, which is left in valid but
201   // unspecified state.
202   FilePath(FilePath&& that) noexcept;
203   // Replaces the contents with those of |that|, which is left in valid but
204   // unspecified state.
205   FilePath& operator=(FilePath&& that) noexcept;
206 
207   bool operator==(const FilePath& that) const;
208 
209   bool operator!=(const FilePath& that) const;
210 
211   // Required for some STL containers and operations
212   bool operator<(const FilePath& that) const {
213     return path_ < that.path_;
214   }
215 
value()216   const StringType& value() const { return path_; }
217 
empty()218   [[nodiscard]] bool empty() const { return path_.empty(); }
219 
clear()220   void clear() { path_.clear(); }
221 
222   // Returns true if |character| is in kSeparators.
223   static bool IsSeparator(CharType character);
224 
225   // Returns a vector of all of the components of the provided path. It is
226   // equivalent to calling DirName().value() on the path's root component,
227   // and BaseName().value() on each child component.
228   //
229   // To make sure this is lossless so we can differentiate absolute and
230   // relative paths, the root slash will be included even though no other
231   // slashes will be. The precise behavior is:
232   //
233   // Posix:  "/foo/bar"  ->  [ "/", "foo", "bar" ]
234   // Windows:  "C:\foo\bar"  ->  [ "C:", "\\", "foo", "bar" ]
235   std::vector<FilePath::StringType> GetComponents() const;
236 
237   // Returns true if this FilePath is a parent or ancestor of the |child|.
238   // Absolute and relative paths are accepted i.e. /foo is a parent to /foo/bar,
239   // and foo is a parent to foo/bar. Any ancestor is considered a parent i.e. /a
240   // is a parent to both /a/b and /a/b/c.  Does not convert paths to absolute,
241   // follow symlinks or directory navigation (e.g. ".."). A path is *NOT* its
242   // own parent.
243   bool IsParent(const FilePath& child) const;
244 
245   // If IsParent(child) holds, appends to path (if non-NULL) the
246   // relative path to child and returns true.  For example, if parent
247   // holds "/Users/johndoe/Library/Application Support", child holds
248   // "/Users/johndoe/Library/Application Support/Google/Chrome/Default", and
249   // *path holds "/Users/johndoe/Library/Caches", then after
250   // parent.AppendRelativePath(child, path) is called *path will hold
251   // "/Users/johndoe/Library/Caches/Google/Chrome/Default".  Otherwise,
252   // returns false.
253   bool AppendRelativePath(const FilePath& child, FilePath* path) const;
254 
255   // Returns a FilePath corresponding to the directory containing the path
256   // named by this object, stripping away the file component.  If this object
257   // only contains one component, returns a FilePath identifying
258   // kCurrentDirectory.  If this object already refers to the root directory,
259   // returns a FilePath identifying the root directory. Please note that this
260   // doesn't resolve directory navigation, e.g. the result for "../a" is "..".
261   [[nodiscard]] FilePath DirName() const;
262 
263   // Returns a FilePath corresponding to the last path component of this
264   // object, either a file or a directory.  If this object already refers to
265   // the root directory, returns a FilePath identifying the root directory;
266   // this is the only situation in which BaseName will return an absolute path.
267   [[nodiscard]] FilePath BaseName() const;
268 
269   // Returns the extension of a file path.  This method works very similarly to
270   // FinalExtension(), except when the file path ends with a common
271   // double-extension.  For common double-extensions like ".tar.gz" and
272   // ".user.js", this method returns the combined extension.
273   //
274   // Common means that detecting double-extensions is based on a hard-coded
275   // allow-list (including but not limited to ".*.gz" and ".user.js") and isn't
276   // solely dependent on the number of dots.  Specifically, even if somebody
277   // invents a new Blah compression algorithm:
278   //   - calling this function with "foo.tar.bz2" will return ".tar.bz2", but
279   //   - calling this function with "foo.tar.blah" will return just ".blah"
280   //     until ".*.blah" is added to the hard-coded allow-list.
281   //
282   // That hard-coded allow-list is case-insensitive: ".GZ" and ".gz" are
283   // equivalent. However, the StringType returned is not canonicalized for
284   // case: "foo.TAR.bz2" input will produce ".TAR.bz2", not ".tar.bz2", and
285   // "bar.EXT", which is not a double-extension, will produce ".EXT".
286   //
287   // The following code should always work regardless of the value of path.
288   //   new_path = path.RemoveExtension().value().append(path.Extension());
289   //   ASSERT(new_path == path.value());
290   //
291   // NOTE: this is different from the original file_util implementation which
292   // returned the extension without a leading "." ("jpg" instead of ".jpg").
293   [[nodiscard]] StringType Extension() const;
294 
295   // Returns the final extension of a file path, or an empty string if the file
296   // path has no extension.  In most cases, the final extension of a file path
297   // refers to the part of the file path from the last dot to the end (including
298   // the dot itself).  For example, this method applied to "/pics/jojo.jpg"
299   // and "/pics/jojo." returns ".jpg" and ".", respectively.  However, if the
300   // base name of the file path is either "." or "..", this method returns an
301   // empty string.
302   //
303   // TODO(davidben): Check all our extension-sensitive code to see if
304   // we can rename this to Extension() and the other to something like
305   // LongExtension(), defaulting to short extensions and leaving the
306   // long "extensions" to logic like base::GetUniquePathNumber().
307   [[nodiscard]] StringType FinalExtension() const;
308 
309   // Returns "C:\pics\jojo" for path "C:\pics\jojo.jpg"
310   // NOTE: this is slightly different from the similar file_util implementation
311   // which returned simply 'jojo'.
312   [[nodiscard]] FilePath RemoveExtension() const;
313 
314   // Removes the path's file extension, as in RemoveExtension(), but
315   // ignores double extensions.
316   [[nodiscard]] FilePath RemoveFinalExtension() const;
317 
318   // Inserts |suffix| after the file name portion of |path| but before the
319   // extension.  Returns "" if BaseName() == "." or "..".
320   // Examples:
321   // path == "C:\pics\jojo.jpg" suffix == " (1)", returns "C:\pics\jojo (1).jpg"
322   // path == "jojo.jpg"         suffix == " (1)", returns "jojo (1).jpg"
323   // path == "C:\pics\jojo"     suffix == " (1)", returns "C:\pics\jojo (1)"
324   // path == "C:\pics.old\jojo" suffix == " (1)", returns "C:\pics.old\jojo (1)"
325   [[nodiscard]] FilePath InsertBeforeExtension(StringPieceType suffix) const;
326   [[nodiscard]] FilePath InsertBeforeExtensionASCII(StringPiece suffix) const;
327 
328   // Adds |extension| to |file_name|. Returns the current FilePath if
329   // |extension| is empty. Returns "" if BaseName() == "." or "..".
330   [[nodiscard]] FilePath AddExtension(StringPieceType extension) const;
331 
332   // Like above, but takes the extension as an ASCII string. See AppendASCII for
333   // details on how this is handled.
334   [[nodiscard]] FilePath AddExtensionASCII(StringPiece extension) const;
335 
336   // Replaces the extension of |file_name| with |extension|.  If |file_name|
337   // does not have an extension, then |extension| is added.  If |extension| is
338   // empty, then the extension is removed from |file_name|.
339   // Returns "" if BaseName() == "." or "..".
340   [[nodiscard]] FilePath ReplaceExtension(StringPieceType extension) const;
341 
342   // Returns true if file path's Extension() matches `extension`. The test is
343   // case insensitive. Don't forget the leading period if appropriate.
344   bool MatchesExtension(StringPieceType extension) const;
345 
346   // Returns true if file path's FinalExtension() matches `extension`. The
347   // test is case insensitive. Don't forget the leading period if appropriate.
348   bool MatchesFinalExtension(StringPieceType extension) const;
349 
350   // Returns a FilePath by appending a separator and the supplied path
351   // component to this object's path.  Append takes care to avoid adding
352   // excessive separators if this object's path already ends with a separator.
353   // If this object's path is kCurrentDirectory ('.'), a new FilePath
354   // corresponding only to |component| is returned.  |component| must be a
355   // relative path; it is an error to pass an absolute path.
356   [[nodiscard]] FilePath Append(StringPieceType component) const;
357   [[nodiscard]] FilePath Append(const FilePath& component) const;
358   [[nodiscard]] FilePath Append(const SafeBaseName& component) const;
359 
360   // Although Windows StringType is std::wstring, since the encoding it uses for
361   // paths is well defined, it can handle ASCII path components as well.
362   // Mac uses UTF8, and since ASCII is a subset of that, it works there as well.
363   // On Linux, although it can use any 8-bit encoding for paths, we assume that
364   // ASCII is a valid subset, regardless of the encoding, since many operating
365   // system paths will always be ASCII.
366   [[nodiscard]] FilePath AppendASCII(StringPiece component) const;
367 
368   // Returns true if this FilePath contains an absolute path.  On Windows, an
369   // absolute path begins with either a drive letter specification followed by
370   // a separator character, or with two separator characters.  On POSIX
371   // platforms, an absolute path begins with a separator character.
372   bool IsAbsolute() const;
373 
374   // Returns true if this FilePath is a network path which starts with 2 path
375   // separators. See class documentation for 'Alternate root'.
376   bool IsNetwork() const;
377 
378   // Returns true if the patch ends with a path separator character.
379   [[nodiscard]] bool EndsWithSeparator() const;
380 
381   // Returns a copy of this FilePath that ends with a trailing separator. If
382   // the input path is empty, an empty FilePath will be returned.
383   [[nodiscard]] FilePath AsEndingWithSeparator() const;
384 
385   // Returns a copy of this FilePath that does not end with a trailing
386   // separator.
387   [[nodiscard]] FilePath StripTrailingSeparators() const;
388 
389   // Returns true if this FilePath contains an attempt to reference a parent
390   // directory (e.g. has a path component that is "..").
391   bool ReferencesParent() const;
392 
393   // Return a Unicode human-readable version of this path.
394   // Warning: you can *not*, in general, go from a display name back to a real
395   // path.  Only use this when displaying paths to users, not just when you
396   // want to stuff a std::u16string into some other API.
397   std::u16string LossyDisplayName() const;
398 
399   // Return the path as ASCII, or the empty string if the path is not ASCII.
400   // This should only be used for cases where the FilePath is representing a
401   // known-ASCII filename.
402   std::string MaybeAsASCII() const;
403 
404   // Return the path as UTF-8.
405   //
406   // This function is *unsafe* as there is no way to tell what encoding is
407   // used in file names on POSIX systems other than Mac and Chrome OS,
408   // although UTF-8 is practically used everywhere these days. To mitigate
409   // the encoding issue, this function internally calls
410   // SysNativeMBToWide() on POSIX systems other than Mac and Chrome OS,
411   // per assumption that the current locale's encoding is used in file
412   // names, but this isn't a perfect solution.
413   //
414   // Once it becomes safe to to stop caring about non-UTF-8 file names,
415   // the SysNativeMBToWide() hack will be removed from the code, along
416   // with "Unsafe" in the function name.
417   std::string AsUTF8Unsafe() const;
418 
419   // Similar to AsUTF8Unsafe, but returns UTF-16 instead.
420   std::u16string AsUTF16Unsafe() const;
421 
422   // Returns a FilePath object from a path name in ASCII.
423   static FilePath FromASCII(StringPiece ascii);
424 
425   // Returns a FilePath object from a path name in UTF-8. This function
426   // should only be used for cases where you are sure that the input
427   // string is UTF-8.
428   //
429   // Like AsUTF8Unsafe(), this function is unsafe. This function
430   // internally calls SysWideToNativeMB() on POSIX systems other than Mac
431   // and Chrome OS, to mitigate the encoding issue. See the comment at
432   // AsUTF8Unsafe() for details.
433   static FilePath FromUTF8Unsafe(StringPiece utf8);
434 
435   // Similar to FromUTF8Unsafe, but accepts UTF-16 instead.
436   static FilePath FromUTF16Unsafe(StringPiece16 utf16);
437 
438   void WriteToPickle(Pickle* pickle) const;
439   bool ReadFromPickle(PickleIterator* iter);
440 
441   // Normalize all path separators to backslash on Windows
442   // (if FILE_PATH_USES_WIN_SEPARATORS is true), or do nothing on POSIX systems.
443   [[nodiscard]] FilePath NormalizePathSeparators() const;
444 
445   // Normalize all path separattors to given type on Windows
446   // (if FILE_PATH_USES_WIN_SEPARATORS is true), or do nothing on POSIX systems.
447   [[nodiscard]] FilePath NormalizePathSeparatorsTo(CharType separator) const;
448 
449   // Compare two strings in the same way the file system does.
450   // Note that these always ignore case, even on file systems that are case-
451   // sensitive. If case-sensitive comparison is ever needed, add corresponding
452   // methods here.
453   // The methods are written as a static method so that they can also be used
454   // on parts of a file path, e.g., just the extension.
455   // CompareIgnoreCase() returns -1, 0 or 1 for less-than, equal-to and
456   // greater-than respectively.
457   static int CompareIgnoreCase(StringPieceType string1,
458                                StringPieceType string2);
CompareEqualIgnoreCase(StringPieceType string1,StringPieceType string2)459   static bool CompareEqualIgnoreCase(StringPieceType string1,
460                                      StringPieceType string2) {
461     return CompareIgnoreCase(string1, string2) == 0;
462   }
CompareLessIgnoreCase(StringPieceType string1,StringPieceType string2)463   static bool CompareLessIgnoreCase(StringPieceType string1,
464                                     StringPieceType string2) {
465     return CompareIgnoreCase(string1, string2) < 0;
466   }
467 
468   // Serialise this object into a trace.
469   void WriteIntoTrace(perfetto::TracedValue context) const;
470 
471 #if BUILDFLAG(IS_APPLE)
472   // Returns the string in the special canonical decomposed form as defined for
473   // HFS, which is close to, but not quite, decomposition form D. See
474   // http://developer.apple.com/mac/library/technotes/tn/tn1150.html#UnicodeSubtleties
475   // for further comments.
476   // Returns the epmty string if the conversion failed.
477   static StringType GetHFSDecomposedForm(StringPieceType string);
478 
479   // Special UTF-8 version of FastUnicodeCompare. Cf:
480   // http://developer.apple.com/mac/library/technotes/tn/tn1150.html#StringComparisonAlgorithm
481   // IMPORTANT: The input strings must be in the special HFS decomposed form!
482   // (cf. above GetHFSDecomposedForm method)
483   static int HFSFastUnicodeCompare(StringPieceType string1,
484                                    StringPieceType string2);
485 #endif
486 
487 #if BUILDFLAG(IS_ANDROID)
488   // On android, file selection dialog can return a file with content uri
489   // scheme(starting with content://). Content uri needs to be opened with
490   // ContentResolver to guarantee that the app has appropriate permissions
491   // to access it.
492   // Returns true if the path is a content uri, or false otherwise.
493   bool IsContentUri() const;
494 #endif
495 
496   // NOTE: When adding a new public method, consider adding it to
497   // file_path_fuzzer.cc as well.
498 
499  private:
500   // Remove trailing separators from this object.  If the path is absolute, it
501   // will never be stripped any more than to refer to the absolute root
502   // directory, so "////" will become "/", not "".  A leading pair of
503   // separators is never stripped, to support alternate roots.  This is used to
504   // support UNC paths on Windows.
505   void StripTrailingSeparatorsInternal();
506 
507   StringType path_;
508 };
509 
510 BASE_EXPORT std::ostream& operator<<(std::ostream& out,
511                                      const FilePath& file_path);
512 
513 }  // namespace base
514 
515 namespace std {
516 
517 template <>
518 struct hash<base::FilePath> {
519   typedef base::FilePath argument_type;
520   typedef std::size_t result_type;
521   result_type operator()(argument_type const& f) const {
522     return hash<base::FilePath::StringType>()(f.value());
523   }
524 };
525 
526 }  // namespace std
527 
528 #endif  // BASE_FILES_FILE_PATH_H_
529