| 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" |
| 11 #include "third_party/WebKit/Source/wtf/text/StringUTF8Adaptor.h" | 11 #include "third_party/WebKit/Source/wtf/text/StringUTF8Adaptor.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 struct UTF8AdaptorInfo { | 16 struct UTF8AdaptorInfo { |
| 17 explicit UTF8AdaptorInfo(const WTF::String& input) : utf8_adaptor(input) { | 17 explicit UTF8AdaptorInfo(const WTF::String& input) : utf8_adaptor(input) { |
| 18 #if DCHECK_IS_ON() | 18 #if DCHECK_IS_ON() |
| 19 original_size_in_bytes = static_cast<size_t>(input.sizeInBytes()); | 19 original_size_in_bytes = input.charactersSizeInBytes(); |
| 20 #endif | 20 #endif |
| 21 } | 21 } |
| 22 | 22 |
| 23 ~UTF8AdaptorInfo() {} | 23 ~UTF8AdaptorInfo() {} |
| 24 | 24 |
| 25 WTF::StringUTF8Adaptor utf8_adaptor; | 25 WTF::StringUTF8Adaptor utf8_adaptor; |
| 26 | 26 |
| 27 #if DCHECK_IS_ON() | 27 #if DCHECK_IS_ON() |
| 28 // For sanity check only. | 28 // For sanity check only. |
| 29 size_t original_size_in_bytes; | 29 size_t original_size_in_bytes; |
| 30 #endif | 30 #endif |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 UTF8AdaptorInfo* ToAdaptor(const WTF::String& input, void* context) { | 33 UTF8AdaptorInfo* ToAdaptor(const WTF::String& input, void* context) { |
| 34 UTF8AdaptorInfo* adaptor = static_cast<UTF8AdaptorInfo*>(context); | 34 UTF8AdaptorInfo* adaptor = static_cast<UTF8AdaptorInfo*>(context); |
| 35 | 35 |
| 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, input.charactersSizeInBytes()); |
| 38 static_cast<size_t>(input.sizeInBytes())); | |
| 39 #endif | 38 #endif |
| 40 return adaptor; | 39 return adaptor; |
| 41 } | 40 } |
| 42 | 41 |
| 43 } // namespace | 42 } // namespace |
| 44 | 43 |
| 45 // static | 44 // static |
| 46 void StringTraits<WTF::String>::SetToNull(WTF::String* output) { | 45 void StringTraits<WTF::String>::SetToNull(WTF::String* output) { |
| 47 if (output->isNull()) | 46 if (output->isNull()) |
| 48 return; | 47 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 76 | 75 |
| 77 // static | 76 // static |
| 78 bool StringTraits<WTF::String>::Read(StringDataView input, | 77 bool StringTraits<WTF::String>::Read(StringDataView input, |
| 79 WTF::String* output) { | 78 WTF::String* output) { |
| 80 WTF::String result = WTF::String::fromUTF8(input.storage(), input.size()); | 79 WTF::String result = WTF::String::fromUTF8(input.storage(), input.size()); |
| 81 output->swap(result); | 80 output->swap(result); |
| 82 return true; | 81 return true; |
| 83 } | 82 } |
| 84 | 83 |
| 85 } // namespace mojo | 84 } // namespace mojo |
| OLD | NEW |