| 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.empty()) | 54 if (!input.empty()) |
| 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 Array<uint8_t> TypeConverter<Array<uint8_t>, base::StringPiece>::Convert( |
| 60 const base::StringPiece& input) { |
| 61 Array<uint8_t> result(input.size()); |
| 62 if (!input.empty()) |
| 63 memcpy(&result.front(), input.data(), input.size()); |
| 64 return result; |
| 65 } |
| 66 |
| 59 base::string16 TypeConverter<base::string16, Array<uint8_t>>::Convert( | 67 base::string16 TypeConverter<base::string16, Array<uint8_t>>::Convert( |
| 60 const Array<uint8_t>& input) { | 68 const Array<uint8_t>& input) { |
| 61 if (input.is_null() || input.empty()) | 69 if (input.is_null() || input.empty()) |
| 62 return base::string16(); | 70 return base::string16(); |
| 63 | 71 |
| 64 return base::string16(reinterpret_cast<const base::char16*>(&input.front()), | 72 return base::string16(reinterpret_cast<const base::char16*>(&input.front()), |
| 65 input.size() / sizeof(base::char16)); | 73 input.size() / sizeof(base::char16)); |
| 66 } | 74 } |
| 67 | 75 |
| 68 Array<uint8_t> TypeConverter<Array<uint8_t>, base::string16>::Convert( | 76 Array<uint8_t> TypeConverter<Array<uint8_t>, base::string16>::Convert( |
| 69 const base::string16& input) { | 77 const base::string16& input) { |
| 70 Array<uint8_t> result(input.size() * sizeof(base::char16)); | 78 Array<uint8_t> result(input.size() * sizeof(base::char16)); |
| 71 if (!input.empty()) | 79 if (!input.empty()) |
| 72 memcpy(&result.front(), input.c_str(), input.size() * sizeof(base::char16)); | 80 memcpy(&result.front(), input.c_str(), input.size() * sizeof(base::char16)); |
| 73 return result; | 81 return result; |
| 74 } | 82 } |
| 75 | 83 |
| 76 } // namespace mojo | 84 } // namespace mojo |
| OLD | NEW |