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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/String16_cpp.template

Issue 2251343003: [DevTools] Generate separate copies of inspector_protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <cstdlib>
6 #include <cstring>
7 #include <string>
8
9 namespace blink {
10 namespace protocol {
11
12 namespace internal {
13
14 void intToStr(int number, char* buffer, size_t length)
15 {
16 std::snprintf(buffer, length, "%d", number);
17 }
18
19 void doubleToStr(double number, char* buffer, size_t length)
20 {
21 std::snprintf(buffer, length, "%f", number);
22 }
23
24 void doubleToStr3(double number, char* buffer, size_t length)
25 {
26 std::snprintf(buffer, length, "%.3g", number);
27 }
28
29 void doubleToStr6(double number, char* buffer, size_t length)
30 {
31 std::snprintf(buffer, length, "%.6g", number);
32 }
33
34 double strToDouble(const char* buffer, bool* ok)
35 {
36 char* endptr;
37 double result = std::strtod(buffer, &endptr);
38 if (ok)
39 *ok = !(*endptr);
40 return result;
41 }
42
43 int strToInt(const char* buffer, bool* ok)
44 {
45 char* endptr;
46 int result = std::strtol(buffer, &endptr, 10);
47 if (ok)
48 *ok = !(*endptr);
49 return result;
50 }
51
52 } // namespace internal
53
54 String16Builder::String16Builder()
55 {
56 }
57
58 void String16Builder::append(const String16& s)
59 {
60 m_buffer.insert(m_buffer.end(), s.characters16(), s.characters16() + s.lengt h());
61 }
62
63 void String16Builder::append(UChar c)
64 {
65 m_buffer.push_back(c);
66 }
67
68 void String16Builder::append(char c)
69 {
70 UChar u = c;
71 m_buffer.push_back(u);
72 }
73
74 void String16Builder::append(const UChar* characters, size_t length)
75 {
76 m_buffer.insert(m_buffer.end(), characters, characters + length);
77 }
78
79 void String16Builder::append(const char* characters, size_t length)
80 {
81 m_buffer.reserve(m_buffer.size() + length);
82 for (size_t i = 0; i < length; ++i, ++characters) {
83 UChar u = *characters;
84 m_buffer.push_back(u);
85 }
86 }
87
88 String16 String16Builder::toString()
89 {
90 return String16(m_buffer.data(), m_buffer.size());
91 }
92
93 void String16Builder::reserveCapacity(size_t capacity)
94 {
95 m_buffer.reserve(capacity);
96 }
97
98 } // namespace protocol
99 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698