Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2560)

Unified Diff: base/file_path.cc

Issue 8402008: Add FilePath::FromUTF8Unsafe() and FilePath::AsUTF8Unsafe(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_path.h ('k') | base/file_path_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_path.cc
diff --git a/base/file_path.cc b/base/file_path.cc
index 35361bef7594c5e2223343d46d4ec745edec3675..3666ff2e82a4c465d86f6319ddefe7d4f428053b 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) {
« no previous file with comments | « base/file_path.h ('k') | base/file_path_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698