Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: tonic/dart_string.cc

Issue 1244493002: Wholesale move sky/engine/tonic to tonic (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tonic/dart_string.h ('k') | tonic/dart_string_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 "tonic/dart_string.h"
6
7 #include "base/logging.h"
8
9 namespace blink {
10 namespace {
11
12 void FinalizeString(void* string_impl) {
13 DCHECK(string_impl);
14 reinterpret_cast<StringImpl*>(string_impl)->deref();
15 }
16
17 template <typename CharType>
18 String Externalize(Dart_Handle handle, intptr_t length) {
19 if (!length)
20 return StringImpl::empty();
21 CharType* buffer = nullptr;
22 RefPtr<StringImpl> string_impl =
23 StringImpl::createUninitialized(length, buffer);
24
25 string_impl->ref(); // Balanced in FinalizeString.
26
27 Dart_Handle result =
28 Dart_MakeExternalString(handle, buffer, length * sizeof(CharType),
29 string_impl.get(), FinalizeString);
30 DCHECK(!Dart_IsError(result));
31 return String(string_impl.release());
32 }
33
34 } // namespace
35
36 Dart_Handle CreateDartString(StringImpl* string_impl) {
37 if (!string_impl)
38 return Dart_EmptyString();
39
40 string_impl->ref(); // Balanced in FinalizeString.
41
42 if (string_impl->is8Bit()) {
43 return Dart_NewExternalLatin1String(string_impl->characters8(),
44 string_impl->length(), string_impl,
45 FinalizeString);
46 } else {
47 return Dart_NewExternalUTF16String(string_impl->characters16(),
48 string_impl->length(), string_impl,
49 FinalizeString);
50 }
51 }
52
53 String ExternalizeDartString(Dart_Handle handle) {
54 DCHECK(Dart_IsString(handle));
55 DCHECK(!Dart_IsExternalString(handle));
56 bool is_latin1 = Dart_IsStringLatin1(handle);
57 intptr_t length;
58 Dart_StringLength(handle, &length);
59 if (is_latin1)
60 return Externalize<LChar>(handle, length);
61 return Externalize<UChar>(handle, length);
62 }
63
64 } // namespace blink
OLDNEW
« no previous file with comments | « tonic/dart_string.h ('k') | tonic/dart_string_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698