blob: f6cc8ad098fa4de03f6b2002d9e44966652fd263 [file] [log] [blame]
yzshendec89e062016-05-13 17:29:171// Copyright 2016 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#ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STL_H_
6#define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STL_H_
7
8#include <string>
9
10#include "mojo/public/cpp/bindings/string_traits.h"
11
12namespace mojo {
13
14template <>
15struct StringTraits<std::string> {
16 static bool IsNull(const std::string& input) {
17 // std::string is always converted to non-null mojom string.
18 return false;
19 }
20
21 static void SetToNull(std::string* output) {
22 // std::string doesn't support null state. Set it to empty instead.
23 output->clear();
24 }
25
26 static size_t GetSize(const std::string& input) { return input.size(); }
27
28 static const char* GetData(const std::string& input) { return input.data(); }
29
30 static bool Read(StringDataView input, std::string* output) {
31 output->assign(input.storage(), input.size());
32 return true;
33 }
34};
35
36} // namespace mojo
37
38#endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STL_H_