| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_ |
| 7 | 7 |
| 8 #include "mojo/public/cpp/bindings/string.h" | 8 #include "mojo/public/cpp/bindings/string.h" |
| 9 #include "mojo/public/cpp/bindings/string_traits.h" | 9 #include "mojo/public/cpp/bindings/string_traits.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 | 12 |
| 13 template <> | 13 template <> |
| 14 struct StringTraits<String> { | 14 struct StringTraits<String> { |
| 15 static bool IsNull(const String& input) { return input.is_null(); } | 15 static bool IsNull(const String& input) { return input.is_null(); } |
| 16 static void SetToNull(String* output) { *output = nullptr; } |
| 16 | 17 |
| 17 static size_t GetSize(const String& input) { return input.size(); } | 18 static size_t GetSize(const String& input) { return input.size(); } |
| 18 | 19 |
| 19 static const char* GetData(const String& input) { return input.data(); } | 20 static const char* GetData(const String& input) { return input.data(); } |
| 20 | 21 |
| 21 static bool Read(StringDataView input, String* output) { | 22 static bool Read(StringDataView input, String* output) { |
| 22 if (!input.is_null()) { | 23 String result(input.storage(), input.size()); |
| 23 String result(input.storage(), input.size()); | 24 result.Swap(output); |
| 24 result.Swap(output); | |
| 25 } else { | |
| 26 *output = nullptr; | |
| 27 } | |
| 28 return true; | 25 return true; |
| 29 } | 26 } |
| 30 }; | 27 }; |
| 31 | 28 |
| 32 } // namespace mojo | 29 } // namespace mojo |
| 33 | 30 |
| 34 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_ | 31 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_ |
| OLD | NEW |