• 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 <string_view>
109 #include <vector>
110 
111 #include "base/base_export.h"
112 #include "base/compiler_specific.h"
113 #include "base/trace_event/base_tracing_forward.h"
114 #include "build/build_config.h"
115 
116 // Windows-style drive letter support and pathname separator characters can be
117 // 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
119 // in the unit test.
120 #if BUILDFLAG(IS_WIN)
121 #define FILE_PATH_USES_DRIVE_LETTERS
122 #define FILE_PATH_USES_WIN_SEPARATORS
123 #endif  // BUILDFLAG(IS_WIN)
124 
125 // To print path names portably use PRFilePath (based on PRIuS and friends from
126 // C99 and format_macros.h) like this:
127 // base::StringPrintf("Path is %" PRFilePath ".\n", path.value().c_str());
128 #if BUILDFLAG(IS_WIN)
129 #define PRFilePath "ls"
130 #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
131 #define PRFilePath "s"
132 #endif  // BUILDFLAG(IS_WIN)
133 
134 // Macros for string literal initialization of FilePath::CharType[].
135 #if BUILDFLAG(IS_WIN)
136 
137 // The `FILE_PATH_LITERAL_INTERNAL` indirection allows `FILE_PATH_LITERAL` to
138 // work correctly with macro parameters, for example
139 // `FILE_PATH_LITERAL(TEST_FILE)` where `TEST_FILE` is a macro #defined as
140 // "TestFile".
141 #define FILE_PATH_LITERAL_INTERNAL(x) L##x
142 #define FILE_PATH_LITERAL(x) FILE_PATH_LITERAL_INTERNAL(x)
143 
144 #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
145 #define FILE_PATH_LITERAL(x) x
146 #endif  // BUILDFLAG(IS_WIN)
147 
148 #if BUILDFLAG(IS_APPLE)
149 typedef const struct __CFString* CFStringRef;
150 #endif
151 
152 namespace base {
153 
154 class SafeBaseName;
155 class Pickle;
156 class PickleIterator;
157 
158 // An abstraction to isolate users from the differences between native
159 // pathnames on different platforms.
160 class BASE_EXPORT FilePath {
161  public:
162 #if BUILDFLAG(IS_WIN)
163   // On Windows, for Unicode-aware applications, native pathnames are wchar_t
164   // arrays encoded in UTF-16.
165   typedef std::wstring StringType;
166 #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
167   // On most platforms, native pathnames are char arrays, and the encoding
168   // may or may not be specified.  On Mac OS X, native pathnames are encoded
169   // in UTF-8.
170   typedef std::string StringType;
171 #endif  // BUILDFLAG(IS_WIN)
172 
173   typedef StringType::value_type CharType;
174   typedef std::basic_string_view<CharType> StringPieceType;
175 
176   // Null-terminated array of separators used to separate components in paths.
177   // Each character in this array is a valid separator, but kSeparators[0] is
178   // treated as the canonical separator and is used when composing pathnames.
179   static constexpr CharType kSeparators[] =
180 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
181       FILE_PATH_LITERAL("\\/");
182 #else   // FILE_PATH_USES_WIN_SEPARATORS
183       FILE_PATH_LITERAL("/");
184 #endif  // FILE_PATH_USES_WIN_SEPARATORS
185 
186   // std::size(kSeparators), i.e., the number of separators in kSeparators plus
187   // one (the null terminator at the end of kSeparators).
188   static constexpr size_t kSeparatorsLength = std::size(kSeparators);
189 
190   // The special path component meaning "this directory."
191   static constexpr CharType kCurrentDirectory[] = FILE_PATH_LITERAL(".");
192 
193   // The special path component meaning "the parent directory."
194   static constexpr CharType kParentDirectory[] = FILE_PATH_LITERAL("..");
195 
196   // The character used to identify a file extension.
197   static constexpr CharType kExtensionSeparator = FILE_PATH_LITERAL('.');
198 
199   FilePath();
200   FilePath(const FilePath& that);
201   explicit FilePath(StringPieceType path);
202   ~FilePath();
203   FilePath& operator=(const FilePath& that);
204 
205   // Constructs FilePath with the contents of |that|, which is left in valid but
206   // unspecified state.
207   FilePath(FilePath&& that) noexcept;
208   // Replaces the contents with those of |that|, which is left in valid but
209   // unspecified state.
210   FilePath& operator=(FilePath&& that) noexcept;
211 
212   bool operator==(const FilePath& that) const;
213 
214   bool operator!=(const FilePath& that) const;
215 
216   // Required for some STL containers and operations
217   bool operator<(const FilePath& that) const {
218     return path_ < that.path_;
219   }
220 
value()221   const StringType& value() const LIFETIME_BOUND { return path_; }
222 
empty()223   [[nodiscard]] bool empty() const { return path_.empty(); }
224 
clear()225   void clear() { path_.clear(); }
226 
227   // Returns true if |character| is in kSeparators.
228   static bool IsSeparator(CharType character);
229 
230   // Returns a vector of all of the components of the provided path. It is
231   // equivalent to calling DirName().value() on the path's root component,
232   // and BaseName().value() on each child component.
233   //
234   // To make sure this is lossless so we can differentiate absolute and
235   // relative paths, the root slash will be included even though no other
236   // slashes will be. The precise behavior is:
237   //
238   // Posix:  "/foo/bar"  ->  [ "/", "foo", "bar" ]
239   // Windows:  "C:\foo\bar"  ->  [ "C:", "\\", "foo", "bar" ]
240   std::vector<FilePath::StringType> GetComponents() const;
241 
242   // Returns true if this FilePath is a parent or ancestor of the |child|.
243   // Absolute and relative paths are accepted i.e. /foo is a parent to /foo/bar,
244   // and foo is a parent to foo/bar. Any ancestor is considered a parent i.e. /a
245   // is a parent to both /a/b and /a/b/c.  Does not convert paths to absolute,
246   // follow symlinks or directory navigation (e.g. ".."). A path is *NOT* its
247   // own parent.
248   bool IsParent(const FilePath& child) const;
249 
250   // If IsParent(child) holds, appends to path (if non-NULL) the
251   // relative path to child and returns true.  For example, if parent
252   // holds "/Users/johndoe/Library/Application Support", child holds
253   // "/Users/johndoe/Library/Application Support/Google/Chrome/Default", and
254   // *path holds "/Users/johndoe/Library/Caches", then after
255   // parent.AppendRelativePath(child, path) is called *path will hold
256   // "/Users/johndoe/Library/Caches/Google/Chrome/Default".  Otherwise,
257   // returns false.
258   bool AppendRelativePath(const FilePath& child, FilePath* path) const;
259 
260   // Returns a FilePath corresponding to the directory containing the path
261   // named by this object, stripping away the file component.  If this object
262   // only contains one component, returns a FilePath identifying
263   // kCurrentDirectory.  If this object already refers to the root directory,
264   // returns a FilePath identifying the root directory. Please note that this
265   // doesn't resolve directory navigation, e.g. the result for "../a" is "..".
266   [[nodiscard]] FilePath DirName() const;
267 
268   // Returns a FilePath corresponding to the last path component of this
269   // object, either a file or a directory.  If this object already refers to
270   // the root directory, returns a FilePath identifying the root directory;
271   // this is the only situation in which BaseName will return an absolute path.
272   [[nodiscard]] FilePath BaseName() const;
273 
274   // Returns the extension of a file path.  This method works very similarly to
275   // FinalExtension(), except when the file path ends with a common
276   // double-extension.  For common double-extensions like ".tar.gz" and
277   // ".user.js", this method returns the combined extension.
278   //
279   // Common means that detecting double-extensions is based on a hard-coded
280   // allow-list (including but not limited to ".*.gz" and ".user.js") and isn't
281   // solely dependent on the number of dots.  Specifically, even if somebody
282   // invents a new Blah compression algorithm:
283   //   - calling this function with "foo.tar.bz2" will return ".tar.bz2", but
284   //   - calling this function with "foo.tar.blah" will return just ".blah"
285   //     until ".*.blah" is added to the hard-coded allow-list.
286   //
287   // That hard-coded allow-list is case-insensitive: ".GZ" and ".gz" are
288   // equivalent. However, the StringType returned is not canonicalized for
289   // case: "foo.TAR.bz2" input will produce ".TAR.bz2", not ".tar.bz2", and
290   // "bar.EXT", which is not a double-extension, will produce ".EXT".
291   //
292   // The following code should always work regardless of the value of path.
293   //   new_path = path.RemoveExtension().value().append(path.Extension());
294   //   ASSERT(new_path == path.value());
295   //
296   // NOTE: this is different from the original file_util implementation which
297   // returned the extension without a leading "." ("jpg" instead of ".jpg").
298   [[nodiscard]] StringType Extension() const;
299 
300   // Returns the final extension of a file path, or an empty string if the file
301   // path has no extension.  In most cases, the final extension of a file path
302   // refers to the part of the file path from the last dot to the end (including
303   // the dot itself).  For example, this method applied to "/pics/jojo.jpg"
304   // and "/pics/jojo." returns ".jpg" and ".", respectively.  However, if the
305   // base name of the file path is either "." or "..", this method returns an
306   // empty string.
307   //
308   // TODO(davidben): Check all our extension-sensitive code to see if
309   // we can rename this to Extension() and the other to something like
310   // LongExtension(), defaulting to short extensions and leaving the
311   // long "extensions" to logic like base::GetUniquePathNumber().
312   [[nodiscard]] StringType FinalExtension() const;
313 
314   // Returns "C:\pics\jojo" for path "C:\pics\jojo.jpg"
315   // NOTE: this is slightly different from the similar file_util implementation
316   // which returned simply 'jojo'.
317   [[nodiscard]] FilePath RemoveExtension() const;
318 
319   // Removes the path's file extension, as in RemoveExtension(), but
320   // ignores double extensions.
321   [[nodiscard]] FilePath RemoveFinalExtension() const;
322 
323   // Inserts |suffix| after the file name portion of |path| but before the
324   // extension.  Returns "" if BaseName() == "." or "..".
325   // Examples:
326   // path == "C:\pics\jojo.jpg" suffix == " (1)", returns "C:\pics\jojo (1).jpg"
327   // path == "jojo.jpg"         suffix == " (1)", returns "jojo (1).jpg"
328   // path == "C:\pics\jojo"     suffix == " (1)", returns "C:\pics\jojo (1)"
329   // path == "C:\pics.old\jojo" suffix == " (1)", returns "C:\pics.old\jojo (1)"
330   [[nodiscard]] FilePath InsertBeforeExtension(StringPieceType suffix) const;
331   [[nodiscard]] FilePath InsertBeforeExtensionASCII(
332       std::string_view suffix) const;
333 
334   // Adds |extension| to |file_name|. Returns the current FilePath if
335   // |extension| is empty. Returns "" if BaseName() == "." or "..".
336   [[nodiscard]] FilePath AddExtension(StringPieceType extension) const;
337 
338   // Like above, but takes the extension as an ASCII string. See AppendASCII for
339   // details on how this is handled.
340   [[nodiscard]] FilePath AddExtensionASCII(std::string_view extension) const;
341 
342   // Replaces the extension of |file_name| with |extension|.  If |file_name|
343   // does not have an extension, then |extension| is added.  If |extension| is
344   // empty, then the extension is removed from |file_name|.
345   // Returns "" if BaseName() == "." or "..".
346   [[nodiscard]] FilePath ReplaceExtension(StringPieceType extension) const;
347 
348   // Returns true if file path's Extension() matches `extension`. The test is
349   // case insensitive. Don't forget the leading period if appropriate.
350   bool MatchesExtension(StringPieceType extension) const;
351 
352   // Returns true if file path's FinalExtension() matches `extension`. The
353   // test is case insensitive. Don't forget the leading period if appropriate.
354   bool MatchesFinalExtension(StringPieceType extension) const;
355 
356   // Returns a FilePath by appending a separator and the supplied path
357   // component to this object's path.  Append takes care to avoid adding
358   // excessive separators if this object's path already ends with a separator.
359   // If this object's path is kCurrentDirectory ('.'), a new FilePath
360   // corresponding only to |component| is returned.  |component| must be a
361   // relative path; it is an error to pass an absolute path.
362   [[nodiscard]] FilePath Append(StringPieceType component) const;
363   [[nodiscard]] FilePath Append(const FilePath& component) const;
364   [[nodiscard]] FilePath Append(const SafeBaseName& component) const;
365 
366   // Although Windows StringType is std::wstring, since the encoding it uses for
367   // paths is well defined, it can handle ASCII path components as well.
368   // Mac uses UTF8, and since ASCII is a subset of that, it works there as well.
369   // On Linux, although it can use any 8-bit encoding for paths, we assume that
370   // ASCII is a valid subset, regardless of the encoding, since many operating
371   // system paths will always be ASCII.
372   [[nodiscard]] FilePath AppendASCII(std::string_view component) const;
373 
374   // Returns true if this FilePath contains an absolute path.  On Windows, an
375   // absolute path begins with either a drive letter specification followed by
376   // a separator character, or with two separator characters.  On POSIX
377   // platforms, an absolute path begins with a separator character.
378   bool IsAbsolute() const;
379 
380   // Returns true if this FilePath is a network path which starts with 2 path
381   // separators. See class documentation for 'Alternate root'.
382   bool IsNetwork() const;
383 
384   // Returns true if the patch ends with a path separator character.
385   [[nodiscard]] bool EndsWithSeparator() const;
386 
387   // Returns a copy of this FilePath that ends with a trailing separator. If
388   // the input path is empty, an empty FilePath will be returned.
389   [[nodiscard]] FilePath AsEndingWithSeparator() const;
390 
391   // Returns a copy of this FilePath that does not end with a trailing
392   // separator.
393   [[nodiscard]] FilePath StripTrailingSeparators() const;
394 
395   // Returns true if this FilePath contains an attempt to reference a parent
396   // directory (e.g. has a path component that is "..").
397   bool ReferencesParent() const;
398 
399   // Return a Unicode human-readable version of this path.
400   // Warning: you can *not*, in general, go from a display name back to a real
401   // path.  Only use this when displaying paths to users, not just when you
402   // want to stuff a std::u16string into some other API.
403   std::u16string LossyDisplayName() const;
404 
405   // Return the path as ASCII, or the empty string if the path is not ASCII.
406   // This should only be used for cases where the FilePath is representing a
407   // known-ASCII filename.
408   std::string MaybeAsASCII() const;
409 
410   // Return the path as UTF-8.
411   //
412   // This function is *unsafe* as there is no way to tell what encoding is
413   // used in file names on POSIX systems other than Mac and Chrome OS,
414   // although UTF-8 is practically used everywhere these days. To mitigate
415   // the encoding issue, this function internally calls
416   // SysNativeMBToWide() on POSIX systems other than Mac and Chrome OS,
417   // per assumption that the current locale's encoding is used in file
418   // names, but this isn't a perfect solution.
419   //
420   // Once it becomes safe to to stop caring about non-UTF-8 file names,
421   // the SysNativeMBToWide() hack will be removed from the code, along
422   // with "Unsafe" in the function name.
423   std::string AsUTF8Unsafe() const;
424 
425   // Similar to AsUTF8Unsafe, but returns UTF-16 instead.
426   std::u16string AsUTF16Unsafe() const;
427 
428   // Returns a FilePath object from a path name in ASCII.
429   static FilePath FromASCII(std::string_view ascii);
430 
431   // Returns a FilePath object from a path name in UTF-8. This function
432   // should only be used for cases where you are sure that the input
433   // string is UTF-8.
434   //
435   // Like AsUTF8Unsafe(), this function is unsafe. This function
436   // internally calls SysWideToNativeMB() on POSIX systems other than Mac
437   // and Chrome OS, to mitigate the encoding issue. See the comment at
438   // AsUTF8Unsafe() for details.
439   static FilePath FromUTF8Unsafe(std::string_view utf8);
440 
441   // Similar to FromUTF8Unsafe, but accepts UTF-16 instead.
442   static FilePath FromUTF16Unsafe(std::u16string_view utf16);
443 
444   void WriteToPickle(Pickle* pickle) const;
445   bool ReadFromPickle(PickleIterator* iter);
446 
447   // Normalize all path separators to backslash on Windows
448   // (if FILE_PATH_USES_WIN_SEPARATORS is true), or do nothing on POSIX systems.
449   [[nodiscard]] FilePath NormalizePathSeparators() const;
450 
451   // Normalize all path separattors to given type on Windows
452   // (if FILE_PATH_USES_WIN_SEPARATORS is true), or do nothing on POSIX systems.
453   [[nodiscard]] FilePath NormalizePathSeparatorsTo(CharType separator) const;
454 
455   // Compare two strings in the same way the file system does.
456   // Note that these always ignore case, even on file systems that are case-
457   // sensitive. If case-sensitive comparison is ever needed, add corresponding
458   // methods here.
459   // The methods are written as a static method so that they can also be used
460   // on parts of a file path, e.g., just the extension.
461   // CompareIgnoreCase() returns -1, 0 or 1 for less-than, equal-to and
462   // greater-than respectively.
463   static int CompareIgnoreCase(StringPieceType string1,
464                                StringPieceType string2);
CompareEqualIgnoreCase(StringPieceType string1,StringPieceType string2)465   static bool CompareEqualIgnoreCase(StringPieceType string1,
466                                      StringPieceType string2) {
467     return CompareIgnoreCase(string1, string2) == 0;
468   }
CompareLessIgnoreCase(StringPieceType string1,StringPieceType string2)469   static bool CompareLessIgnoreCase(StringPieceType string1,
470                                     StringPieceType string2) {
471     return CompareIgnoreCase(string1, string2) < 0;
472   }
473 
474   // Serialise this object into a trace.
475   void WriteIntoTrace(perfetto::TracedValue context) const;
476 
477 #if BUILDFLAG(IS_APPLE)
478   // Returns the string in the special canonical decomposed form as defined for
479   // HFS, which is close to, but not quite, decomposition form D. See
480   // http://developer.apple.com/mac/library/technotes/tn/tn1150.html#UnicodeSubtleties
481   // for further comments.
482   // Returns the empty string if the conversion failed.
483   static StringType GetHFSDecomposedForm(StringPieceType string);
484   static StringType GetHFSDecomposedForm(CFStringRef cfstring);
485 
486   // Special UTF-8 version of FastUnicodeCompare. Cf:
487   // http://developer.apple.com/mac/library/technotes/tn/tn1150.html#StringComparisonAlgorithm
488   // IMPORTANT: The input strings must be in the special HFS decomposed form!
489   // (cf. above GetHFSDecomposedForm method)
490   static int HFSFastUnicodeCompare(StringPieceType string1,
491                                    StringPieceType string2);
492 #endif
493 
494 #if BUILDFLAG(IS_ANDROID)
495   // On android, file selection dialog can return a file with content uri
496   // scheme(starting with content://). Content uri needs to be opened with
497   // ContentResolver to guarantee that the app has appropriate permissions
498   // to access it.
499   // Returns true if the path is a content uri, or false otherwise.
500   bool IsContentUri() const;
501 #endif
502 
503   // NOTE: When adding a new public method, consider adding it to
504   // file_path_fuzzer.cc as well.
505 
506  private:
507   // Remove trailing separators from this object.  If the path is absolute, it
508   // will never be stripped any more than to refer to the absolute root
509   // directory, so "////" will become "/", not "".  A leading pair of
510   // separators is never stripped, to support alternate roots.  This is used to
511   // support UNC paths on Windows.
512   void StripTrailingSeparatorsInternal();
513 
514   StringType path_;
515 };
516 
517 BASE_EXPORT std::ostream& operator<<(std::ostream& out,
518                                      const FilePath& file_path);
519 
520 }  // namespace base
521 
522 namespace std {
523 
524 template <>
525 struct hash<base::FilePath> {
526   typedef base::FilePath argument_type;
527   typedef std::size_t result_type;
528   result_type operator()(argument_type const& f) const {
529     return hash<base::FilePath::StringType>()(f.value());
530   }
531 };
532 
533 }  // namespace std
534 
535 #endif  // BASE_FILES_FILE_PATH_H_
536