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.
5 #include "mojo/common/common_type_converters.h"
9 #include "base/strings/utf_string_conversions.h"
14 String TypeConverter
<String
, base::StringPiece
>::Convert(
15 const base::StringPiece
& input
) {
20 return String(input
.data(), input
.size());
23 base::StringPiece TypeConverter
<base::StringPiece
, String
>::Convert(
24 const String
& input
) {
29 String TypeConverter
<String
, base::string16
>::Convert(
30 const base::string16
& input
) {
31 return TypeConverter
<String
, base::StringPiece
>::Convert(
32 base::UTF16ToUTF8(input
));
35 base::string16 TypeConverter
<base::string16
, String
>::Convert(
36 const String
& input
) {
37 return base::UTF8ToUTF16(input
.To
<base::StringPiece
>());
40 std::string TypeConverter
<std::string
, Array
<uint8_t> >::Convert(
41 const Array
<uint8_t>& input
) {
42 if (input
.is_null() || input
.size() == 0u)
45 return std::string(reinterpret_cast<const char*>(&input
.front()),
49 Array
<uint8_t> TypeConverter
<Array
<uint8_t>, std::string
>::Convert(
50 const std::string
& input
) {
51 Array
<uint8_t> result(input
.size());
53 memcpy(&result
.front(), input
.c_str(), input
.size());