| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/common/common_type_converters.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 namespace mojo { | |
| 12 | |
| 13 std::string TypeConverter<std::string, Array<uint8_t>>::Convert( | |
| 14 const Array<uint8_t>& input) { | |
| 15 if (input.is_null() || input.empty()) | |
| 16 return std::string(); | |
| 17 | |
| 18 return std::string(reinterpret_cast<const char*>(&input.front()), | |
| 19 input.size()); | |
| 20 } | |
| 21 | |
| 22 Array<uint8_t> TypeConverter<Array<uint8_t>, std::string>::Convert( | |
| 23 const std::string& input) { | |
| 24 Array<uint8_t> result(input.size()); | |
| 25 if (!input.empty()) | |
| 26 memcpy(&result.front(), input.c_str(), input.size()); | |
| 27 return result; | |
| 28 } | |
| 29 | |
| 30 Array<uint8_t> TypeConverter<Array<uint8_t>, base::StringPiece>::Convert( | |
| 31 const base::StringPiece& input) { | |
| 32 Array<uint8_t> result(input.size()); | |
| 33 if (!input.empty()) | |
| 34 memcpy(&result.front(), input.data(), input.size()); | |
| 35 return result; | |
| 36 } | |
| 37 | |
| 38 base::string16 TypeConverter<base::string16, Array<uint8_t>>::Convert( | |
| 39 const Array<uint8_t>& input) { | |
| 40 if (input.is_null() || input.empty()) | |
| 41 return base::string16(); | |
| 42 | |
| 43 return base::string16(reinterpret_cast<const base::char16*>(&input.front()), | |
| 44 input.size() / sizeof(base::char16)); | |
| 45 } | |
| 46 | |
| 47 Array<uint8_t> TypeConverter<Array<uint8_t>, base::string16>::Convert( | |
| 48 const base::string16& input) { | |
| 49 Array<uint8_t> result(input.size() * sizeof(base::char16)); | |
| 50 if (!input.empty()) | |
| 51 memcpy(&result.front(), input.c_str(), input.size() * sizeof(base::char16)); | |
| 52 return result; | |
| 53 } | |
| 54 | |
| 55 } // namespace mojo | |
| OLD | NEW |