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/value_conversions.cc | |
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/value_conversions.cc')
-rw-r--r-- | base/value_conversions.cc | 29 |
1 files changed, 2 insertions, 27 deletions
diff --git a/base/value_conversions.cc b/base/value_conversions.cc index 64513d0..f4957a4 100644 --- a/base/value_conversions.cc +++ b/base/value_conversions.cc @@ -5,39 +5,14 @@ #include "base/value_conversions.h" #include "base/file_path.h" -#include "base/sys_string_conversions.h" -#include "base/utf_string_conversions.h" #include "base/values.h" namespace base { -namespace { - // |Value| internally stores strings in UTF-8, so we have to convert from the // system native code to UTF-8 and back. - -std::string FilePathToUTF8(const FilePath& file_path) { -#if defined(OS_POSIX) - return WideToUTF8(SysNativeMBToWide(file_path.value())); -#else - return UTF16ToUTF8(file_path.value()); -#endif -} - -FilePath UTF8ToFilePath(const std::string& str) { - FilePath::StringType result; -#if defined(OS_POSIX) - result = SysWideToNativeMB(UTF8ToWide(str)); -#elif defined(OS_WIN) - result = UTF8ToUTF16(str); -#endif - return FilePath(result); -} - -} // namespace - StringValue* CreateFilePathValue(const FilePath& in_value) { - return new StringValue(FilePathToUTF8(in_value)); + return new StringValue(in_value.AsUTF8Unsafe()); } bool GetValueAsFilePath(const Value& value, FilePath* file_path) { @@ -45,7 +20,7 @@ bool GetValueAsFilePath(const Value& value, FilePath* file_path) { if (!value.GetAsString(&str)) return false; if (file_path) - *file_path = UTF8ToFilePath(str); + *file_path = FilePath::FromUTF8Unsafe(str); return true; } |