| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Chrome OS also uses UTF-8. |
| 20 // Linux does not specify an encoding, but in practice, the locale's | 21 // Linux does not specify an encoding, but in practice, the locale's |
| 21 // character set may be used. | 22 // character set may be used. |
| 22 // | 23 // |
| 23 // For more arcane bits of path trivia, see below. | 24 // For more arcane bits of path trivia, see below. |
| 24 // | 25 // |
| 25 // FilePath objects are intended to be used anywhere paths are. An | 26 // FilePath objects are intended to be used anywhere paths are. An |
| 26 // application may pass FilePath objects around internally, masking the | 27 // application may pass FilePath objects around internally, masking the |
| 27 // underlying differences between systems, only differing in implementation | 28 // underlying differences between systems, only differing in implementation |
| 28 // where interfacing directly with the system. For example, a single | 29 // where interfacing directly with the system. For example, a single |
| 29 // OpenFile(const FilePath &) function may be made available, allowing all | 30 // OpenFile(const FilePath &) function may be made available, allowing all |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // Warning: you can *not*, in general, go from a display name back to a real | 288 // Warning: you can *not*, in general, go from a display name back to a real |
| 288 // path. Only use this when displaying paths to users, not just when you | 289 // path. Only use this when displaying paths to users, not just when you |
| 289 // want to stuff a string16 into some other API. | 290 // want to stuff a string16 into some other API. |
| 290 string16 LossyDisplayName() const; | 291 string16 LossyDisplayName() const; |
| 291 | 292 |
| 292 // Return the path as ASCII, or the empty string if the path is not ASCII. | 293 // Return the path as ASCII, or the empty string if the path is not ASCII. |
| 293 // This should only be used for cases where the FilePath is representing a | 294 // This should only be used for cases where the FilePath is representing a |
| 294 // known-ASCII filename. | 295 // known-ASCII filename. |
| 295 std::string MaybeAsASCII() const; | 296 std::string MaybeAsASCII() const; |
| 296 | 297 |
| 298 // Return the path as UTF-8. |
| 299 // |
| 300 // This function is *unsafe* as there is no way to tell what encoding is |
| 301 // used in file names on POSIX systems other than Mac and Chrome OS, |
| 302 // although UTF-8 is practically used everywhere these days. To mitigate |
| 303 // the encoding issue, this function internally calls |
| 304 // SysNativeMBToWide() on POSIX systems other than Mac and Chrome OS, |
| 305 // per assumption that the current locale's encoding is used in file |
| 306 // names, but this isn't a perfect solution. |
| 307 // |
| 308 // Once it becomes safe to to stop caring about non-UTF-8 file names, |
| 309 // the SysNativeMBToWide() hack will be removed from the code, along |
| 310 // with "Unsafe" in the function name. |
| 311 std::string AsUTF8Unsafe() const; |
| 312 |
| 297 // Older Chromium code assumes that paths are always wstrings. | 313 // Older Chromium code assumes that paths are always wstrings. |
| 298 // This function converts wstrings to FilePaths, and is | 314 // This function converts wstrings to FilePaths, and is |
| 299 // useful to smooth porting that old code to the FilePath API. | 315 // useful to smooth porting that old code to the FilePath API. |
| 300 // It has "Hack" its name so people feel bad about using it. | 316 // It has "Hack" its name so people feel bad about using it. |
| 301 // http://code.google.com/p/chromium/issues/detail?id=24672 | 317 // http://code.google.com/p/chromium/issues/detail?id=24672 |
| 302 // | 318 // |
| 303 // If you are trying to be a good citizen and remove these, ask yourself: | 319 // If you are trying to be a good citizen and remove these, ask yourself: |
| 304 // - Am I interacting with other Chrome code that deals with files? Then | 320 // - Am I interacting with other Chrome code that deals with files? Then |
| 305 // try to convert the API into using FilePath. | 321 // try to convert the API into using FilePath. |
| 306 // - Am I interacting with OS-native calls? Then use value() to get at an | 322 // - Am I interacting with OS-native calls? Then use value() to get at an |
| 307 // OS-native string format. | 323 // OS-native string format. |
| 308 // - Am I using well-known file names, like "config.ini"? Then use the | 324 // - Am I using well-known file names, like "config.ini"? Then use the |
| 309 // ASCII functions (we require paths to always be supersets of ASCII). | 325 // ASCII functions (we require paths to always be supersets of ASCII). |
| 310 // - Am I displaying a string to the user in some UI? Then use the | 326 // - Am I displaying a string to the user in some UI? Then use the |
| 311 // LossyDisplayName() function, but keep in mind that you can't | 327 // LossyDisplayName() function, but keep in mind that you can't |
| 312 // ever use the result of that again as a path. | 328 // ever use the result of that again as a path. |
| 313 static FilePath FromWStringHack(const std::wstring& wstring); | 329 static FilePath FromWStringHack(const std::wstring& wstring); |
| 314 | 330 |
| 331 // Returns a FilePath object from a path name in UTF-8. This function |
| 332 // should only be used for cases where you are sure that the input |
| 333 // string is UTF-8. |
| 334 // |
| 335 // Like AsUTF8Unsafe(), this function is unsafe. This function |
| 336 // internally calls SysWideToNativeMB() on POSIX systems other than Mac |
| 337 // and Chrome OS, to mitigate the encoding issue. See the comment at |
| 338 // AsUTF8Unsafe() for details. |
| 339 static FilePath FromUTF8Unsafe(const std::string& utf8); |
| 340 |
| 315 void WriteToPickle(Pickle* pickle); | 341 void WriteToPickle(Pickle* pickle); |
| 316 bool ReadFromPickle(Pickle* pickle, void** iter); | 342 bool ReadFromPickle(Pickle* pickle, void** iter); |
| 317 | 343 |
| 318 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 344 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 319 // Normalize all path separators to backslash. | 345 // Normalize all path separators to backslash. |
| 320 FilePath NormalizeWindowsPathSeparators() const; | 346 FilePath NormalizeWindowsPathSeparators() const; |
| 321 #endif | 347 #endif |
| 322 | 348 |
| 323 // Compare two strings in the same way the file system does. | 349 // Compare two strings in the same way the file system does. |
| 324 // Note that these always ignore case, even on file systems that are case- | 350 // Note that these always ignore case, even on file systems that are case- |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 420 |
| 395 inline size_t hash_value(const FilePath& f) { | 421 inline size_t hash_value(const FilePath& f) { |
| 396 return hash_value(f.value()); | 422 return hash_value(f.value()); |
| 397 } | 423 } |
| 398 | 424 |
| 399 #endif // COMPILER | 425 #endif // COMPILER |
| 400 | 426 |
| 401 } // namespace BASE_HASH_NAMESPACE | 427 } // namespace BASE_HASH_NAMESPACE |
| 402 | 428 |
| 403 #endif // BASE_FILE_PATH_H_ | 429 #endif // BASE_FILE_PATH_H_ |
| OLD | NEW |