Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: base/file_path.h

Issue 274043: Arcane bits of path trivia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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
11 // --------------- ---------------------------------- 11 // --------------- ----------------------------------
12 // Fundamental type char[] wchar_t[] 12 // Fundamental type char[] wchar_t[]
13 // Encoding unspecified* UTF-16 13 // Encoding unspecified* UTF-16
14 // Separator / \, tolerant of / 14 // Separator / \, tolerant of /
15 // Drive letters no case-insensitive A-Z followed by : 15 // Drive letters no case-insensitive A-Z followed by :
16 // Alternate root // (surprise!) \\, for UNC paths 16 // Alternate root // (surprise!) \\, for UNC paths
17 // 17 //
18 // * The encoding need not be specified on POSIX systems, although some 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. 19 // POSIX-compliant systems do specify an encoding. Mac OS X uses UTF-8.
20 // Linux does not specify an encoding, but in practice, the locale's 20 // Linux does not specify an encoding, but in practice, the locale's
21 // character set may be used. 21 // character set may be used.
22 // 22 //
23 // For more arcane bits of path trivia, see below.
24 //
23 // FilePath objects are intended to be used anywhere paths are. An 25 // FilePath objects are intended to be used anywhere paths are. An
24 // application may pass FilePath objects around internally, masking the 26 // application may pass FilePath objects around internally, masking the
25 // underlying differences between systems, only differing in implementation 27 // underlying differences between systems, only differing in implementation
26 // where interfacing directly with the system. For example, a single 28 // where interfacing directly with the system. For example, a single
27 // OpenFile(const FilePath &) function may be made available, allowing all 29 // OpenFile(const FilePath &) function may be made available, allowing all
28 // callers to operate without regard to the underlying implementation. On 30 // callers to operate without regard to the underlying implementation. On
29 // POSIX-like platforms, OpenFile might wrap fopen, and on Windows, it might 31 // POSIX-like platforms, OpenFile might wrap fopen, and on Windows, it might
30 // wrap _wfopen_s, perhaps both by calling file_path.value().c_str(). This 32 // wrap _wfopen_s, perhaps both by calling file_path.value().c_str(). This
31 // allows each platform to pass pathnames around without requiring conversions 33 // allows each platform to pass pathnames around without requiring conversions
32 // between encodings, which has an impact on performance, but more imporantly, 34 // between encodings, which has an impact on performance, but more imporantly,
(...skipping 28 matching lines...) Expand all
61 // | FilePath log_file_path(kLogFileName); 63 // | FilePath log_file_path(kLogFileName);
62 // | [...] 64 // | [...]
63 // | } 65 // | }
64 // 66 //
65 // WARNING: FilePaths should ALWAYS be displayed with LTR directionality, even 67 // WARNING: FilePaths should ALWAYS be displayed with LTR directionality, even
66 // when the UI language is RTL. This means you always need to pass filepaths 68 // when the UI language is RTL. This means you always need to pass filepaths
67 // through l10n_util::WrapPathWithLTRFormatting() before displaying it in the 69 // through l10n_util::WrapPathWithLTRFormatting() before displaying it in the
68 // RTL UI. 70 // RTL UI.
69 // 71 //
70 // This is a very common source of bugs, please try to keep this in mind. 72 // This is a very common source of bugs, please try to keep this in mind.
73 //
74 // ARCANE BITS OF PATH TRIVIA
75 //
76 // - A double leading slash is actually part of the POSIX standard. Systems
77 // are allowed to treat // as an alternate root, as Windows does for UNC
78 // (network share) paths. Most POSIX systems don't do anything special
79 // with two leading slashes, but FilePath handles this case properly
80 // in case it ever comes across such a system. FilePath needs this support
81 // for Windows UNC paths, anyway.
82 // References:
83 // The Open Group Base Specifications Issue 7, sections 3.266 ("Pathname")
84 // and 4.12 ("Pathname Resolution"), available at:
85 // http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag _03_266
86 // http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag _04_12
87 //
88 // - Windows treats c:\\ the same way it treats \\. This was intended to
89 // allow older applications that require drive letters to support UNC paths
90 // like \\server\share\path, by permitting c:\\server\share\path as an
91 // equivalent. Since the OS treats these paths specially, FilePath needs
92 // to do the same. Since Windows can use either / or \ as the separator,
93 // FilePath treats c://, c:\\, //, and \\ all equivalently.
94 // Reference:
95 // The Old New Thing, "Why is a drive letter permitted in front of UNC
96 // paths (sometimes)?", available at:
97 // http://blogs.msdn.com/oldnewthing/archive/2005/11/22/495740.aspx
98
71 #ifndef BASE_FILE_PATH_H_ 99 #ifndef BASE_FILE_PATH_H_
72 #define BASE_FILE_PATH_H_ 100 #define BASE_FILE_PATH_H_
73 101
74 #include <string> 102 #include <string>
75 #include <vector> 103 #include <vector>
76 104
77 #include "base/basictypes.h" 105 #include "base/basictypes.h"
78 #include "base/compiler_specific.h" 106 #include "base/compiler_specific.h"
79 #include "base/hash_tables.h" 107 #include "base/hash_tables.h"
80 #include "base/string_piece.h" // For implicit conversions. 108 #include "base/string_piece.h" // For implicit conversions.
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 namespace stdext { 324 namespace stdext {
297 325
298 inline size_t hash_value(const FilePath& f) { 326 inline size_t hash_value(const FilePath& f) {
299 return hash_value(f.value()); 327 return hash_value(f.value());
300 } 328 }
301 329
302 } // namespace stdext 330 } // namespace stdext
303 #endif // COMPILER 331 #endif // COMPILER
304 332
305 #endif // BASE_FILE_PATH_H_ 333 #endif // BASE_FILE_PATH_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698