| 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 | 6 |
| 7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
| 9 #include "vm/json_stream.h" | 9 #include "vm/json_stream.h" |
| 10 #include "vm/message.h" | 10 #include "vm/message.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 | 211 |
| 212 void JSONStream::PrintValue(const char* s) { | 212 void JSONStream::PrintValue(const char* s) { |
| 213 PrintCommaIfNeeded(); | 213 PrintCommaIfNeeded(); |
| 214 buffer_.AddChar('"'); | 214 buffer_.AddChar('"'); |
| 215 AddEscapedUTF8String(s); | 215 AddEscapedUTF8String(s); |
| 216 buffer_.AddChar('"'); | 216 buffer_.AddChar('"'); |
| 217 } | 217 } |
| 218 | 218 |
| 219 | 219 |
| 220 void JSONStream::PrintValue(const char* s, intptr_t len) { |
| 221 PrintCommaIfNeeded(); |
| 222 buffer_.AddChar('"'); |
| 223 AddEscapedUTF8String(s, len); |
| 224 buffer_.AddChar('"'); |
| 225 } |
| 226 |
| 227 |
| 220 void JSONStream::PrintValueNoEscape(const char* s) { | 228 void JSONStream::PrintValueNoEscape(const char* s) { |
| 221 PrintCommaIfNeeded(); | 229 PrintCommaIfNeeded(); |
| 222 buffer_.Printf("%s", s); | 230 buffer_.Printf("%s", s); |
| 223 } | 231 } |
| 224 | 232 |
| 225 | 233 |
| 226 void JSONStream::PrintfValue(const char* format, ...) { | 234 void JSONStream::PrintfValue(const char* format, ...) { |
| 227 PrintCommaIfNeeded(); | 235 PrintCommaIfNeeded(); |
| 228 | 236 |
| 229 va_list args; | 237 va_list args; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 PrintValue(d); | 303 PrintValue(d); |
| 296 } | 304 } |
| 297 | 305 |
| 298 | 306 |
| 299 void JSONStream::PrintProperty(const char* name, const char* s) { | 307 void JSONStream::PrintProperty(const char* name, const char* s) { |
| 300 PrintPropertyName(name); | 308 PrintPropertyName(name); |
| 301 PrintValue(s); | 309 PrintValue(s); |
| 302 } | 310 } |
| 303 | 311 |
| 304 | 312 |
| 313 void JSONStream::PrintProperty(const char* name, const char* s, intptr_t len) { |
| 314 PrintPropertyName(name); |
| 315 PrintValue(s, len); |
| 316 } |
| 317 |
| 318 |
| 305 void JSONStream::PrintPropertyNoEscape(const char* name, const char* s) { | 319 void JSONStream::PrintPropertyNoEscape(const char* name, const char* s) { |
| 306 PrintPropertyName(name); | 320 PrintPropertyName(name); |
| 307 PrintValueNoEscape(s); | 321 PrintValueNoEscape(s); |
| 308 } | 322 } |
| 309 | 323 |
| 310 | 324 |
| 311 void JSONStream::PrintProperty(const char* name, const DebuggerEvent* event) { | 325 void JSONStream::PrintProperty(const char* name, const DebuggerEvent* event) { |
| 312 PrintPropertyName(name); | 326 PrintPropertyName(name); |
| 313 PrintValue(event); | 327 PrintValue(event); |
| 314 } | 328 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 char ch = buffer[length-1]; | 419 char ch = buffer[length-1]; |
| 406 return (ch != '[') && (ch != '{') && (ch != ':') && (ch != ','); | 420 return (ch != '[') && (ch != '{') && (ch != ':') && (ch != ','); |
| 407 } | 421 } |
| 408 | 422 |
| 409 | 423 |
| 410 void JSONStream::AddEscapedUTF8String(const char* s) { | 424 void JSONStream::AddEscapedUTF8String(const char* s) { |
| 411 if (s == NULL) { | 425 if (s == NULL) { |
| 412 return; | 426 return; |
| 413 } | 427 } |
| 414 intptr_t len = strlen(s); | 428 intptr_t len = strlen(s); |
| 429 AddEscapedUTF8String(s, len); |
| 430 } |
| 431 |
| 432 |
| 433 void JSONStream::AddEscapedUTF8String(const char* s, intptr_t len) { |
| 434 if (s == NULL) { |
| 435 return; |
| 436 } |
| 415 const uint8_t* s8 = reinterpret_cast<const uint8_t*>(s); | 437 const uint8_t* s8 = reinterpret_cast<const uint8_t*>(s); |
| 416 intptr_t i = 0; | 438 intptr_t i = 0; |
| 417 for (; i < len; ) { | 439 for (; i < len; ) { |
| 418 // Extract next UTF8 character. | 440 // Extract next UTF8 character. |
| 419 int32_t ch = 0; | 441 int32_t ch = 0; |
| 420 int32_t ch_len = Utf8::Decode(&s8[i], len - i, &ch); | 442 int32_t ch_len = Utf8::Decode(&s8[i], len - i, &ch); |
| 421 ASSERT(ch_len != 0); | 443 ASSERT(ch_len != 0); |
| 422 buffer_.AddEscapedChar(ch); | 444 buffer_.AddEscapedChar(ch); |
| 423 // Move i forward. | 445 // Move i forward. |
| 424 i += ch_len; | 446 i += ch_len; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 484 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 463 va_end(args); | 485 va_end(args); |
| 464 ASSERT(len == len2); | 486 ASSERT(len == len2); |
| 465 stream_->buffer_.AddChar('"'); | 487 stream_->buffer_.AddChar('"'); |
| 466 stream_->AddEscapedUTF8String(p); | 488 stream_->AddEscapedUTF8String(p); |
| 467 stream_->buffer_.AddChar('"'); | 489 stream_->buffer_.AddChar('"'); |
| 468 free(p); | 490 free(p); |
| 469 } | 491 } |
| 470 | 492 |
| 471 } // namespace dart | 493 } // namespace dart |
| OLD | NEW |