OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef PLATFORM_JSON_H_ | 5 #ifndef PLATFORM_JSON_H_ |
6 #define PLATFORM_JSON_H_ | 6 #define PLATFORM_JSON_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 | 10 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 // TextBuffer maintains a dynamic character buffer with a printf-style way to | 120 // TextBuffer maintains a dynamic character buffer with a printf-style way to |
121 // append text. | 121 // append text. |
122 class TextBuffer : ValueObject { | 122 class TextBuffer : ValueObject { |
123 public: | 123 public: |
124 explicit TextBuffer(intptr_t buf_size); | 124 explicit TextBuffer(intptr_t buf_size); |
125 ~TextBuffer(); | 125 ~TextBuffer(); |
126 | 126 |
127 intptr_t Printf(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 127 intptr_t Printf(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
128 void AddChar(char ch); | 128 void AddChar(char ch); |
129 void AddUTF8(uint32_t ch); | 129 void EscapeAndAddCodeUnit(uint32_t cu); |
130 void AddEscapedChar(uint32_t ch); | |
131 void AddString(const char* s); | 130 void AddString(const char* s); |
132 void AddEscapedString(const char* s); | 131 void AddEscapedString(const char* s); |
133 | 132 |
134 void Clear(); | 133 void Clear(); |
135 | 134 |
136 char* buf() { return buf_; } | 135 char* buf() { return buf_; } |
137 intptr_t length() { return msg_len_; } | 136 intptr_t length() { return msg_len_; } |
138 | 137 |
139 // Steal ownership of the buffer pointer. | 138 // Steal ownership of the buffer pointer. |
140 // NOTE: TextBuffer is empty afterwards. | 139 // NOTE: TextBuffer is empty afterwards. |
141 const char* Steal(); | 140 const char* Steal(); |
142 | 141 |
143 private: | 142 private: |
144 void EnsureCapacity(intptr_t len); | 143 void EnsureCapacity(intptr_t len); |
145 char* buf_; | 144 char* buf_; |
146 intptr_t buf_size_; | 145 intptr_t buf_size_; |
147 intptr_t msg_len_; | 146 intptr_t msg_len_; |
148 }; | 147 }; |
149 | 148 |
150 } // namespace dart | 149 } // namespace dart |
151 | 150 |
152 #endif // PLATFORM_JSON_H_ | 151 #endif // PLATFORM_JSON_H_ |
OLD | NEW |