| 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 21 matching lines...) Expand all Loading... |
| 32 const base::string16& input) { | 32 const base::string16& input) { |
| 33 return TypeConverter<String, base::StringPiece>::Convert( | 33 return TypeConverter<String, base::StringPiece>::Convert( |
| 34 base::UTF16ToUTF8(input)); | 34 base::UTF16ToUTF8(input)); |
| 35 } | 35 } |
| 36 // static | 36 // static |
| 37 base::string16 TypeConverter<base::string16, String>::Convert( | 37 base::string16 TypeConverter<base::string16, String>::Convert( |
| 38 const String& input) { | 38 const String& input) { |
| 39 return base::UTF8ToUTF16(input.To<base::StringPiece>()); | 39 return base::UTF8ToUTF16(input.To<base::StringPiece>()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 std::string TypeConverter<std::string, Array<uint8_t> >::Convert( | 42 std::string TypeConverter<std::string, Array<uint8_t>>::Convert( |
| 43 const Array<uint8_t>& input) { | 43 const Array<uint8_t>& input) { |
| 44 if (input.is_null() || input.size() == 0u) | 44 if (input.is_null() || input.empty()) |
| 45 return std::string(); | 45 return std::string(); |
| 46 | 46 |
| 47 return std::string(reinterpret_cast<const char*>(&input.front()), | 47 return std::string(reinterpret_cast<const char*>(&input.front()), |
| 48 input.size()); | 48 input.size()); |
| 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.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 base::string16 TypeConverter<base::string16, Array<uint8_t>>::Convert( |
| 60 const Array<uint8_t>& input) { |
| 61 if (input.is_null() || input.empty()) |
| 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.empty()) |
| 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 |