| 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 #include "mojo/public/cpp/bindings/string_traits_wtf.h" | 5 #include "mojo/public/cpp/bindings/string_traits_wtf.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #if DCHECK_IS_ON() | 36 #if DCHECK_IS_ON() |
| 37 DCHECK_EQ(adaptor->original_size_in_bytes, | 37 DCHECK_EQ(adaptor->original_size_in_bytes, |
| 38 static_cast<size_t>(input.sizeInBytes())); | 38 static_cast<size_t>(input.sizeInBytes())); |
| 39 #endif | 39 #endif |
| 40 return adaptor; | 40 return adaptor; |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 // static | 45 // static |
| 46 void StringTraits<WTF::String>::SetToNull(WTF::String* output) { |
| 47 if (output->isNull()) |
| 48 return; |
| 49 |
| 50 WTF::String result; |
| 51 output->swap(result); |
| 52 } |
| 53 |
| 54 // static |
| 46 void* StringTraits<WTF::String>::SetUpContext(const WTF::String& input) { | 55 void* StringTraits<WTF::String>::SetUpContext(const WTF::String& input) { |
| 47 return new UTF8AdaptorInfo(input); | 56 return new UTF8AdaptorInfo(input); |
| 48 } | 57 } |
| 49 | 58 |
| 50 // static | 59 // static |
| 51 void StringTraits<WTF::String>::TearDownContext(const WTF::String& input, | 60 void StringTraits<WTF::String>::TearDownContext(const WTF::String& input, |
| 52 void* context) { | 61 void* context) { |
| 53 delete ToAdaptor(input, context); | 62 delete ToAdaptor(input, context); |
| 54 } | 63 } |
| 55 | 64 |
| 56 // static | 65 // static |
| 57 size_t StringTraits<WTF::String>::GetSize(const WTF::String& input, | 66 size_t StringTraits<WTF::String>::GetSize(const WTF::String& input, |
| 58 void* context) { | 67 void* context) { |
| 59 return ToAdaptor(input, context)->utf8_adaptor.length(); | 68 return ToAdaptor(input, context)->utf8_adaptor.length(); |
| 60 } | 69 } |
| 61 | 70 |
| 62 // static | 71 // static |
| 63 const char* StringTraits<WTF::String>::GetData(const WTF::String& input, | 72 const char* StringTraits<WTF::String>::GetData(const WTF::String& input, |
| 64 void* context) { | 73 void* context) { |
| 65 return ToAdaptor(input, context)->utf8_adaptor.data(); | 74 return ToAdaptor(input, context)->utf8_adaptor.data(); |
| 66 } | 75 } |
| 67 | 76 |
| 68 // static | 77 // static |
| 69 bool StringTraits<WTF::String>::Read(StringDataView input, | 78 bool StringTraits<WTF::String>::Read(StringDataView input, |
| 70 WTF::String* output) { | 79 WTF::String* output) { |
| 71 if (!input.is_null()) { | 80 WTF::String result = WTF::String::fromUTF8(input.storage(), input.size()); |
| 72 WTF::String result = WTF::String::fromUTF8(input.storage(), input.size()); | 81 output->swap(result); |
| 73 output->swap(result); | |
| 74 } else if (!output->isNull()) { | |
| 75 WTF::String result; | |
| 76 output->swap(result); | |
| 77 } | |
| 78 return true; | 82 return true; |
| 79 } | 83 } |
| 80 | 84 |
| 81 } // namespace mojo | 85 } // namespace mojo |
| OLD | NEW |