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

Side by Side Diff: base/value_conversions.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, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_path_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/value_conversions.h" 5 #include "base/value_conversions.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/sys_string_conversions.h"
9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 8 #include "base/values.h"
11 9
12 namespace base { 10 namespace base {
13 11
14 namespace {
15
16 // |Value| internally stores strings in UTF-8, so we have to convert from the 12 // |Value| internally stores strings in UTF-8, so we have to convert from the
17 // system native code to UTF-8 and back. 13 // system native code to UTF-8 and back.
18
19 std::string FilePathToUTF8(const FilePath& file_path) {
20 #if defined(OS_POSIX)
21 return WideToUTF8(SysNativeMBToWide(file_path.value()));
22 #else
23 return UTF16ToUTF8(file_path.value());
24 #endif
25 }
26
27 FilePath UTF8ToFilePath(const std::string& str) {
28 FilePath::StringType result;
29 #if defined(OS_POSIX)
30 result = SysWideToNativeMB(UTF8ToWide(str));
31 #elif defined(OS_WIN)
32 result = UTF8ToUTF16(str);
33 #endif
34 return FilePath(result);
35 }
36
37 } // namespace
38
39 StringValue* CreateFilePathValue(const FilePath& in_value) { 14 StringValue* CreateFilePathValue(const FilePath& in_value) {
40 return new StringValue(FilePathToUTF8(in_value)); 15 return new StringValue(in_value.AsUTF8Unsafe());
41 } 16 }
42 17
43 bool GetValueAsFilePath(const Value& value, FilePath* file_path) { 18 bool GetValueAsFilePath(const Value& value, FilePath* file_path) {
44 std::string str; 19 std::string str;
45 if (!value.GetAsString(&str)) 20 if (!value.GetAsString(&str))
46 return false; 21 return false;
47 if (file_path) 22 if (file_path)
48 *file_path = UTF8ToFilePath(str); 23 *file_path = FilePath::FromUTF8Unsafe(str);
49 return true; 24 return true;
50 } 25 }
51 26
52 } // namespace base 27 } // namespace base
OLDNEW
« no previous file with comments | « base/file_path_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698