Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / mojo / public / bindings / lib / array.cc
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/public/bindings/array.h"
6
7 namespace mojo {
8
9 // static
10 String TypeConverter<String, std::string>::ConvertFrom(const std::string& input,
11                                                        Buffer* buf) {
12   String::Builder result(input.size(), buf);
13   if (!input.empty())
14     memcpy(&result[0], input.data(), input.size());
15   return result.Finish();
16 }
17 // static
18 std::string TypeConverter<String, std::string>::ConvertTo(const String& input) {
19   if (input.is_null() || input.size() == 0)
20     return std::string();
21
22   return std::string(&input[0], &input[0] + input.size());
23 }
24
25 // static
26 String TypeConverter<String, const char*>::ConvertFrom(const char* input,
27                                                        Buffer* buf) {
28   if (!input)
29     return String();
30
31   size_t size = strlen(input);
32   String::Builder result(size, buf);
33   if (size != 0)
34     memcpy(&result[0], input, size);
35   return result.Finish();
36 }
37
38 }  // namespace mojo