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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 // the encoding issue, this function internally calls | 322 // the encoding issue, this function internally calls |
323 // SysNativeMBToWide() on POSIX systems other than Mac and Chrome OS, | 323 // SysNativeMBToWide() on POSIX systems other than Mac and Chrome OS, |
324 // per assumption that the current locale's encoding is used in file | 324 // per assumption that the current locale's encoding is used in file |
325 // names, but this isn't a perfect solution. | 325 // names, but this isn't a perfect solution. |
326 // | 326 // |
327 // Once it becomes safe to to stop caring about non-UTF-8 file names, | 327 // Once it becomes safe to to stop caring about non-UTF-8 file names, |
328 // the SysNativeMBToWide() hack will be removed from the code, along | 328 // the SysNativeMBToWide() hack will be removed from the code, along |
329 // with "Unsafe" in the function name. | 329 // with "Unsafe" in the function name. |
330 std::string AsUTF8Unsafe() const; | 330 std::string AsUTF8Unsafe() const; |
331 | 331 |
| 332 // Similar to AsUTF8Unsafe, but returns UTF-16 instead. |
| 333 string16 AsUTF16Unsafe() const; |
| 334 |
332 // Older Chromium code assumes that paths are always wstrings. | 335 // Older Chromium code assumes that paths are always wstrings. |
333 // This function converts wstrings to FilePaths, and is | 336 // This function converts wstrings to FilePaths, and is |
334 // useful to smooth porting that old code to the FilePath API. | 337 // useful to smooth porting that old code to the FilePath API. |
335 // It has "Hack" its name so people feel bad about using it. | 338 // It has "Hack" its name so people feel bad about using it. |
336 // http://code.google.com/p/chromium/issues/detail?id=24672 | 339 // http://code.google.com/p/chromium/issues/detail?id=24672 |
337 // | 340 // |
338 // If you are trying to be a good citizen and remove these, ask yourself: | 341 // If you are trying to be a good citizen and remove these, ask yourself: |
339 // - Am I interacting with other Chrome code that deals with files? Then | 342 // - Am I interacting with other Chrome code that deals with files? Then |
340 // try to convert the API into using FilePath. | 343 // try to convert the API into using FilePath. |
341 // - Am I interacting with OS-native calls? Then use value() to get at an | 344 // - Am I interacting with OS-native calls? Then use value() to get at an |
342 // OS-native string format. | 345 // OS-native string format. |
343 // - Am I using well-known file names, like "config.ini"? Then use the | 346 // - Am I using well-known file names, like "config.ini"? Then use the |
344 // ASCII functions (we require paths to always be supersets of ASCII). | 347 // ASCII functions (we require paths to always be supersets of ASCII). |
345 // - Am I displaying a string to the user in some UI? Then use the | 348 // - Am I displaying a string to the user in some UI? Then use the |
346 // LossyDisplayName() function, but keep in mind that you can't | 349 // LossyDisplayName() function, but keep in mind that you can't |
347 // ever use the result of that again as a path. | 350 // ever use the result of that again as a path. |
348 static FilePath FromWStringHack(const std::wstring& wstring); | 351 static FilePath FromWStringHack(const std::wstring& wstring); |
349 | 352 |
350 // Returns a FilePath object from a path name in UTF-8. This function | 353 // Returns a FilePath object from a path name in UTF-8. This function |
351 // should only be used for cases where you are sure that the input | 354 // should only be used for cases where you are sure that the input |
352 // string is UTF-8. | 355 // string is UTF-8. |
353 // | 356 // |
354 // Like AsUTF8Unsafe(), this function is unsafe. This function | 357 // Like AsUTF8Unsafe(), this function is unsafe. This function |
355 // internally calls SysWideToNativeMB() on POSIX systems other than Mac | 358 // internally calls SysWideToNativeMB() on POSIX systems other than Mac |
356 // and Chrome OS, to mitigate the encoding issue. See the comment at | 359 // and Chrome OS, to mitigate the encoding issue. See the comment at |
357 // AsUTF8Unsafe() for details. | 360 // AsUTF8Unsafe() for details. |
358 static FilePath FromUTF8Unsafe(const std::string& utf8); | 361 static FilePath FromUTF8Unsafe(const std::string& utf8); |
359 | 362 |
| 363 // Similar to FromUTF8Unsafe, but accepts UTF-16 instead. |
| 364 static FilePath FromUTF16Unsafe(const string16& utf16); |
| 365 |
360 void WriteToPickle(Pickle* pickle) const; | 366 void WriteToPickle(Pickle* pickle) const; |
361 bool ReadFromPickle(PickleIterator* iter); | 367 bool ReadFromPickle(PickleIterator* iter); |
362 | 368 |
363 // Normalize all path separators to backslash on Windows | 369 // Normalize all path separators to backslash on Windows |
364 // (if FILE_PATH_USES_WIN_SEPARATORS is true), or do nothing on POSIX systems. | 370 // (if FILE_PATH_USES_WIN_SEPARATORS is true), or do nothing on POSIX systems. |
365 FilePath NormalizePathSeparators() const; | 371 FilePath NormalizePathSeparators() const; |
366 | 372 |
367 // Compare two strings in the same way the file system does. | 373 // Compare two strings in the same way the file system does. |
368 // Note that these always ignore case, even on file systems that are case- | 374 // Note that these always ignore case, even on file systems that are case- |
369 // sensitive. If case-sensitive comparison is ever needed, add corresponding | 375 // sensitive. If case-sensitive comparison is ever needed, add corresponding |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 449 |
444 inline size_t hash_value(const base::FilePath& f) { | 450 inline size_t hash_value(const base::FilePath& f) { |
445 return hash_value(f.value()); | 451 return hash_value(f.value()); |
446 } | 452 } |
447 | 453 |
448 #endif // COMPILER | 454 #endif // COMPILER |
449 | 455 |
450 } // namespace BASE_HASH_NAMESPACE | 456 } // namespace BASE_HASH_NAMESPACE |
451 | 457 |
452 #endif // BASE_FILES_FILE_PATH_H_ | 458 #endif // BASE_FILES_FILE_PATH_H_ |
OLD | NEW |