diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-20 21:29:54 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-20 21:29:54 +0000 |
commit | 65e269ff59a9d86191f8c2f23f9ad210f14a3d79 (patch) | |
tree | 8a99ad87846130151dec33485b1c86d4e0f3f61c /base/files | |
parent | 06098bb82164237ea5bf340ffa645aba83b13b68 (diff) | |
download | chromium_src-65e269ff59a9d86191f8c2f23f9ad210f14a3d79.zip chromium_src-65e269ff59a9d86191f8c2f23f9ad210f14a3d79.tar.gz chromium_src-65e269ff59a9d86191f8c2f23f9ad210f14a3d79.tar.bz2 |
Add FilePath::{As,From}UTF16Unsafe
R=brettw@chromium.org
Review URL: https://codereview.chromium.org/17509002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207576 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/files')
-rw-r--r-- | base/files/file_path.cc | 26 | ||||
-rw-r--r-- | base/files/file_path.h | 6 |
2 files changed, 32 insertions, 0 deletions
diff --git a/base/files/file_path.cc b/base/files/file_path.cc index 743cbb5..ef0cde6 100644 --- a/base/files/file_path.cc +++ b/base/files/file_path.cc @@ -577,6 +577,14 @@ std::string FilePath::AsUTF8Unsafe() const { #endif } +string16 FilePath::AsUTF16Unsafe() const { +#if defined(OS_MACOSX) || defined(OS_CHROMEOS) + return UTF8ToUTF16(value()); +#else + return WideToUTF16(SysNativeMBToWide(value())); +#endif +} + // The *Hack functions are temporary while we fix the remainder of the code. // Remember to remove the #includes at the top when you remove these. @@ -594,6 +602,15 @@ FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) { #endif } +// static +FilePath FilePath::FromUTF16Unsafe(const string16& utf16) { +#if defined(OS_MACOSX) || defined(OS_CHROMEOS) + return FilePath(UTF16ToUTF8(utf16)); +#else + return FilePath(SysWideToNativeMB(UTF16ToWide(utf16))); +#endif +} + #elif defined(OS_WIN) string16 FilePath::LossyDisplayName() const { return path_; @@ -609,6 +626,10 @@ std::string FilePath::AsUTF8Unsafe() const { return WideToUTF8(value()); } +string16 FilePath::AsUTF16Unsafe() const { + return value(); +} + // static FilePath FilePath::FromWStringHack(const std::wstring& wstring) { return FilePath(wstring); @@ -618,6 +639,11 @@ FilePath FilePath::FromWStringHack(const std::wstring& wstring) { FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) { return FilePath(UTF8ToWide(utf8)); } + +// static +FilePath FilePath::FromUTF16Unsafe(const string16& utf16) { + return FilePath(utf16); +} #endif void FilePath::WriteToPickle(Pickle* pickle) const { diff --git a/base/files/file_path.h b/base/files/file_path.h index 0fb2285..8b69ea4 100644 --- a/base/files/file_path.h +++ b/base/files/file_path.h @@ -329,6 +329,9 @@ class BASE_EXPORT FilePath { // with "Unsafe" in the function name. std::string AsUTF8Unsafe() const; + // Similar to AsUTF8Unsafe, but returns UTF-16 instead. + string16 AsUTF16Unsafe() 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. @@ -357,6 +360,9 @@ class BASE_EXPORT FilePath { // AsUTF8Unsafe() for details. static FilePath FromUTF8Unsafe(const std::string& utf8); + // Similar to FromUTF8Unsafe, but accepts UTF-16 instead. + static FilePath FromUTF16Unsafe(const string16& utf16); + void WriteToPickle(Pickle* pickle) const; bool ReadFromPickle(PickleIterator* iter); |