OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/common/common_type_converters.h" | 5 #include "mojo/common/common_type_converters.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "url/gurl.h" | |
11 | 10 |
12 namespace mojo { | 11 namespace mojo { |
13 | 12 |
14 // static | 13 // static |
15 String TypeConverter<String, base::StringPiece>::Convert( | 14 String TypeConverter<String, base::StringPiece>::Convert( |
16 const base::StringPiece& input) { | 15 const base::StringPiece& input) { |
17 if (input.empty()) { | 16 if (input.empty()) { |
18 char c = 0; | 17 char c = 0; |
19 return String(&c, 0); | 18 return String(&c, 0); |
20 } | 19 } |
(...skipping 10 matching lines...) Expand all Loading... |
31 const base::string16& input) { | 30 const base::string16& input) { |
32 return TypeConverter<String, base::StringPiece>::Convert( | 31 return TypeConverter<String, base::StringPiece>::Convert( |
33 base::UTF16ToUTF8(input)); | 32 base::UTF16ToUTF8(input)); |
34 } | 33 } |
35 // static | 34 // static |
36 base::string16 TypeConverter<base::string16, String>::Convert( | 35 base::string16 TypeConverter<base::string16, String>::Convert( |
37 const String& input) { | 36 const String& input) { |
38 return base::UTF8ToUTF16(input.To<base::StringPiece>()); | 37 return base::UTF8ToUTF16(input.To<base::StringPiece>()); |
39 } | 38 } |
40 | 39 |
41 String TypeConverter<String, GURL>::Convert(const GURL& input) { | |
42 return String(input.spec()); | |
43 } | |
44 | |
45 GURL TypeConverter<GURL, String>::Convert(const String& input) { | |
46 return GURL(input.get()); | |
47 } | |
48 | |
49 std::string TypeConverter<std::string, Array<uint8_t> >::Convert( | 40 std::string TypeConverter<std::string, Array<uint8_t> >::Convert( |
50 const Array<uint8_t>& input) { | 41 const Array<uint8_t>& input) { |
51 if (input.is_null()) | 42 if (input.is_null()) |
52 return std::string(); | 43 return std::string(); |
53 | 44 |
54 return std::string(reinterpret_cast<const char*>(&input.front()), | 45 return std::string(reinterpret_cast<const char*>(&input.front()), |
55 input.size()); | 46 input.size()); |
56 } | 47 } |
57 | 48 |
58 Array<uint8_t> TypeConverter<Array<uint8_t>, std::string>::Convert( | 49 Array<uint8_t> TypeConverter<Array<uint8_t>, std::string>::Convert( |
59 const std::string& input) { | 50 const std::string& input) { |
60 Array<uint8_t> result(input.size()); | 51 Array<uint8_t> result(input.size()); |
61 memcpy(&result.front(), input.c_str(), input.size()); | 52 memcpy(&result.front(), input.c_str(), input.size()); |
62 return result.Pass(); | 53 return result.Pass(); |
63 } | 54 } |
64 | 55 |
65 } // namespace mojo | 56 } // namespace mojo |
OLD | NEW |