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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 } | 49 } |
50 | 50 |
51 Array<uint8_t> TypeConverter<Array<uint8_t>, std::string>::Convert( | 51 Array<uint8_t> TypeConverter<Array<uint8_t>, std::string>::Convert( |
52 const std::string& input) { | 52 const std::string& input) { |
53 Array<uint8_t> result(input.size()); | 53 Array<uint8_t> result(input.size()); |
54 if (input.size() > 0) | 54 if (input.size() > 0) |
55 memcpy(&result.front(), input.c_str(), input.size()); | 55 memcpy(&result.front(), input.c_str(), input.size()); |
56 return result; | 56 return result; |
57 } | 57 } |
58 | 58 |
59 base::string16 TypeConverter<base::string16, Array<uint8_t> >::Convert( | |
dcheng
2016/03/18 06:35:29
Nit: >>
jam
2016/03/18 16:48:33
Done.
| |
60 const Array<uint8_t>& input) { | |
61 if (input.is_null() || input.size() == 0u) | |
dcheng
2016/03/18 06:35:29
Nit: input.empty()
jam
2016/03/18 16:48:33
Done.
| |
62 return base::string16(); | |
63 | |
64 return base::string16(reinterpret_cast<const base::char16*>(&input.front()), | |
65 input.size() / sizeof(base::char16)); | |
66 } | |
67 | |
68 Array<uint8_t> TypeConverter<Array<uint8_t>, base::string16>::Convert( | |
69 const base::string16& input) { | |
70 Array<uint8_t> result(input.size() * sizeof(base::char16)); | |
71 if (input.size() > 0) | |
dcheng
2016/03/18 06:35:29
Nit: input.empty()
jam
2016/03/18 16:48:33
Done.
| |
72 memcpy(&result.front(), input.c_str(), input.size() * sizeof(base::char16)); | |
73 return result; | |
74 } | |
75 | |
59 } // namespace mojo | 76 } // namespace mojo |
OLD | NEW |