summaryrefslogtreecommitdiffstats
path: root/base/file_path.cc
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-02 04:55:23 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-02 04:55:23 +0000
commit45440519a239ffad82425e08115d909fd82a1e9d (patch)
treef7b042dad754c87efdf5fac6944a2a30a9461353 /base/file_path.cc
parentd9037729a6f2e4cb56e59bc69b145d6ddec1d13b (diff)
downloadchromium_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.cc')
-rw-r--r--base/file_path.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/base/file_path.cc b/base/file_path.cc
index 35361be..3666ff2 100644
--- a/base/file_path.cc
+++ b/base/file_path.cc
@@ -527,6 +527,14 @@ std::string FilePath::MaybeAsASCII() const {
return "";
}
+std::string FilePath::AsUTF8Unsafe() const {
+#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
+ return value();
+#else
+ return WideToUTF8(base::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.
@@ -534,6 +542,16 @@ std::string FilePath::MaybeAsASCII() const {
FilePath FilePath::FromWStringHack(const std::wstring& wstring) {
return FilePath(base::SysWideToNativeMB(wstring));
}
+
+// static
+FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) {
+#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
+ return FilePath(utf8);
+#else
+ return FilePath(base::SysWideToNativeMB(UTF8ToWide(utf8)));
+#endif
+}
+
#elif defined(OS_WIN)
string16 FilePath::LossyDisplayName() const {
return path_;
@@ -545,10 +563,19 @@ std::string FilePath::MaybeAsASCII() const {
return "";
}
+std::string FilePath::AsUTF8Unsafe() const {
+ return WideToUTF8(value());
+}
+
// static
FilePath FilePath::FromWStringHack(const std::wstring& wstring) {
return FilePath(wstring);
}
+
+// static
+FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) {
+ return FilePath(UTF8ToWide(utf8));
+}
#endif
void FilePath::WriteToPickle(Pickle* pickle) {