diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-02 04:55:23 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-02 04:55:23 +0000 |
commit | 45440519a239ffad82425e08115d909fd82a1e9d (patch) | |
tree | f7b042dad754c87efdf5fac6944a2a30a9461353 /base/file_path.h | |
parent | d9037729a6f2e4cb56e59bc69b145d6ddec1d13b (diff) | |
download | chromium_src-45440519a239ffad82425e08115d909fd82a1e9d.zip chromium_src-45440519a239ffad82425e08115d909fd82a1e9d.tar.gz chromium_src-45440519a239ffad82425e08115d909fd82a1e9d.tar.bz2 |
Add FilePath::FromUTF8Unsafe() and FilePath::AsUTF8Unsafe().
The logic is moved from value_conversions.cc.
FilePath::FromUTF8Unsafe() should only be used when you are
sure that the input string is UTF-8. See the function comments
for why they have "Unsafe" in their names.
BUG=none
TEST=base_unittests
Review URL: http://codereview.chromium.org/8402008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_path.h')
-rw-r--r-- | base/file_path.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/base/file_path.h b/base/file_path.h index 6396833..8342c30 100644 --- a/base/file_path.h +++ b/base/file_path.h @@ -17,6 +17,7 @@ // // * The encoding need not be specified on POSIX systems, although some // POSIX-compliant systems do specify an encoding. Mac OS X uses UTF-8. +// Chrome OS also uses UTF-8. // Linux does not specify an encoding, but in practice, the locale's // character set may be used. // @@ -294,6 +295,21 @@ class BASE_EXPORT FilePath { // known-ASCII filename. std::string MaybeAsASCII() const; + // Return the path as UTF-8. + // + // This function is *unsafe* as there is no way to tell what encoding is + // used in file names on POSIX systems other than Mac and Chrome OS, + // although UTF-8 is practically used everywhere these days. To mitigate + // the encoding issue, this function internally calls + // SysNativeMBToWide() on POSIX systems other than Mac and Chrome OS, + // per assumption that the current locale's encoding is used in file + // names, but this isn't a perfect solution. + // + // Once it becomes safe to to stop caring about non-UTF-8 file names, + // the SysNativeMBToWide() hack will be removed from the code, along + // with "Unsafe" in the function name. + std::string AsUTF8Unsafe() const; + // Older Chromium code assumes that paths are always wstrings. // This function converts wstrings to FilePaths, and is // useful to smooth porting that old code to the FilePath API. @@ -312,6 +328,16 @@ class BASE_EXPORT FilePath { // ever use the result of that again as a path. static FilePath FromWStringHack(const std::wstring& wstring); + // Returns a FilePath object from a path name in UTF-8. This function + // should only be used for cases where you are sure that the input + // string is UTF-8. + // + // Like AsUTF8Unsafe(), this function is unsafe. This function + // internally calls SysWideToNativeMB() on POSIX systems other than Mac + // and Chrome OS, to mitigate the encoding issue. See the comment at + // AsUTF8Unsafe() for details. + static FilePath FromUTF8Unsafe(const std::string& utf8); + void WriteToPickle(Pickle* pickle); bool ReadFromPickle(Pickle* pickle, void** iter); |