| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/object.h" | 6 #include "vm/object.h" |
| 7 #include "vm/json_stream.h" | 7 #include "vm/json_stream.h" |
| 8 | 8 |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 JSONStream::JSONStream(TextBuffer* buffer) { | 12 JSONStream::JSONStream(TextBuffer* buffer) { |
| 13 ASSERT(buffer != NULL); | 13 ASSERT(buffer != NULL); |
| 14 buffer_ = buffer; | 14 buffer_ = buffer; |
| 15 open_objects_ = 0; | 15 open_objects_ = 0; |
| 16 arguments_ = NULL; |
| 17 num_arguments_ = 0; |
| 18 option_keys_ = NULL; |
| 19 option_values_ = NULL; |
| 20 num_options_ = 0; |
| 16 } | 21 } |
| 17 | 22 |
| 18 | 23 |
| 19 JSONStream::~JSONStream() { | 24 JSONStream::~JSONStream() { |
| 20 } | 25 } |
| 21 | 26 |
| 22 | 27 |
| 23 void JSONStream::Clear() { | 28 void JSONStream::Clear() { |
| 24 buffer_->Clear(); | 29 buffer_->Clear(); |
| 25 open_objects_ = 0; | 30 open_objects_ = 0; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 char* p = reinterpret_cast<char*>(malloc(len+1)); | 145 char* p = reinterpret_cast<char*>(malloc(len+1)); |
| 141 va_start(args, format); | 146 va_start(args, format); |
| 142 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 147 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 143 va_end(args); | 148 va_end(args); |
| 144 ASSERT(len == len2); | 149 ASSERT(len == len2); |
| 145 buffer_->Printf("\"%s\"", p); | 150 buffer_->Printf("\"%s\"", p); |
| 146 free(p); | 151 free(p); |
| 147 } | 152 } |
| 148 | 153 |
| 149 | 154 |
| 155 void JSONStream::SetArguments(const char** arguments, intptr_t num_arguments) { |
| 156 arguments_ = arguments; |
| 157 num_arguments_ = num_arguments; |
| 158 } |
| 159 |
| 160 |
| 161 void JSONStream::SetOptions(const char** option_keys, |
| 162 const char** option_values, |
| 163 intptr_t num_options) { |
| 164 option_keys_ = option_keys; |
| 165 option_values_ = option_values; |
| 166 num_options_ = num_options; |
| 167 } |
| 168 |
| 169 |
| 150 void JSONStream::PrintProperty(const char* name, const Object& o, bool ref) { | 170 void JSONStream::PrintProperty(const char* name, const Object& o, bool ref) { |
| 151 PrintPropertyName(name); | 171 PrintPropertyName(name); |
| 152 PrintValue(o, ref); | 172 PrintValue(o, ref); |
| 153 } | 173 } |
| 154 | 174 |
| 155 | 175 |
| 156 void JSONStream::PrintPropertyName(const char* name) { | 176 void JSONStream::PrintPropertyName(const char* name) { |
| 157 ASSERT(name != NULL); | 177 ASSERT(name != NULL); |
| 158 PrintCommaIfNeeded(); | 178 PrintCommaIfNeeded(); |
| 159 buffer_->Printf("\"%s\":", name); | 179 buffer_->Printf("\"%s\":", name); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 172 intptr_t length = buffer_->length(); | 192 intptr_t length = buffer_->length(); |
| 173 if (length == 0) { | 193 if (length == 0) { |
| 174 return false; | 194 return false; |
| 175 } | 195 } |
| 176 char ch = buffer[length-1]; | 196 char ch = buffer[length-1]; |
| 177 return ch != '[' && ch != '{' && ch != ':' && ch != ','; | 197 return ch != '[' && ch != '{' && ch != ':' && ch != ','; |
| 178 } | 198 } |
| 179 | 199 |
| 180 } // namespace dart | 200 } // namespace dart |
| 181 | 201 |
| OLD | NEW |