| 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 buffer_.Printf("%" Pd64 "", i); | 270 buffer_.Printf("%" Pd64 "", i); |
| 271 } | 271 } |
| 272 | 272 |
| 273 | 273 |
| 274 void JSONStream::PrintValue(double d) { | 274 void JSONStream::PrintValue(double d) { |
| 275 PrintCommaIfNeeded(); | 275 PrintCommaIfNeeded(); |
| 276 buffer_.Printf("%f", d); | 276 buffer_.Printf("%f", d); |
| 277 } | 277 } |
| 278 | 278 |
| 279 | 279 |
| 280 static const char base64_digits[65] = |
| 281 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
| 282 static const char base64_pad = '='; |
| 283 |
| 284 |
| 285 void JSONStream::PrintValueBase64(const uint8_t* bytes, intptr_t length) { |
| 286 PrintCommaIfNeeded(); |
| 287 buffer_.AddChar('"'); |
| 288 |
| 289 intptr_t odd_bits = length % 3; |
| 290 intptr_t even_bits = length - odd_bits; |
| 291 for (intptr_t i = 0; i < even_bits; i += 3) { |
| 292 intptr_t triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]; |
| 293 buffer_.AddChar(base64_digits[triplet >> 18]); |
| 294 buffer_.AddChar(base64_digits[(triplet >> 12) & 63]); |
| 295 buffer_.AddChar(base64_digits[(triplet >> 6) & 63]); |
| 296 buffer_.AddChar(base64_digits[triplet & 63]); |
| 297 } |
| 298 if (odd_bits == 1) { |
| 299 intptr_t triplet = bytes[even_bits] << 16; |
| 300 buffer_.AddChar(base64_digits[triplet >> 18]); |
| 301 buffer_.AddChar(base64_digits[(triplet >> 12) & 63]); |
| 302 buffer_.AddChar(base64_pad); |
| 303 buffer_.AddChar(base64_pad); |
| 304 } else if (odd_bits == 2) { |
| 305 intptr_t triplet = (bytes[even_bits] << 16) | (bytes[even_bits + 1] << 8); |
| 306 buffer_.AddChar(base64_digits[triplet >> 18]); |
| 307 buffer_.AddChar(base64_digits[(triplet >> 12) & 63]); |
| 308 buffer_.AddChar(base64_digits[(triplet >> 6) & 63]); |
| 309 buffer_.AddChar(base64_pad); |
| 310 } |
| 311 |
| 312 buffer_.AddChar('"'); |
| 313 } |
| 314 |
| 315 |
| 280 void JSONStream::PrintValue(const char* s) { | 316 void JSONStream::PrintValue(const char* s) { |
| 281 PrintCommaIfNeeded(); | 317 PrintCommaIfNeeded(); |
| 282 buffer_.AddChar('"'); | 318 buffer_.AddChar('"'); |
| 283 AddEscapedUTF8String(s); | 319 AddEscapedUTF8String(s); |
| 284 buffer_.AddChar('"'); | 320 buffer_.AddChar('"'); |
| 285 } | 321 } |
| 286 | 322 |
| 287 | 323 |
| 288 bool JSONStream::PrintValueStr(const String& s, intptr_t limit) { | 324 bool JSONStream::PrintValueStr(const String& s, intptr_t limit) { |
| 289 PrintCommaIfNeeded(); | 325 PrintCommaIfNeeded(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 PrintValue(d); | 422 PrintValue(d); |
| 387 } | 423 } |
| 388 | 424 |
| 389 | 425 |
| 390 void JSONStream::PrintProperty(const char* name, const char* s) { | 426 void JSONStream::PrintProperty(const char* name, const char* s) { |
| 391 PrintPropertyName(name); | 427 PrintPropertyName(name); |
| 392 PrintValue(s); | 428 PrintValue(s); |
| 393 } | 429 } |
| 394 | 430 |
| 395 | 431 |
| 432 void JSONStream::PrintPropertyBase64(const char* name, |
| 433 const uint8_t* b, |
| 434 intptr_t len) { |
| 435 PrintPropertyName(name); |
| 436 PrintValueBase64(b, len); |
| 437 } |
| 438 |
| 439 |
| 396 bool JSONStream::PrintPropertyStr(const char* name, | 440 bool JSONStream::PrintPropertyStr(const char* name, |
| 397 const String& s, | 441 const String& s, |
| 398 intptr_t limit) { | 442 intptr_t limit) { |
| 399 PrintPropertyName(name); | 443 PrintPropertyName(name); |
| 400 return PrintValueStr(s, limit); | 444 return PrintValueStr(s, limit); |
| 401 } | 445 } |
| 402 | 446 |
| 403 | 447 |
| 404 void JSONStream::PrintPropertyNoEscape(const char* name, const char* s) { | 448 void JSONStream::PrintPropertyNoEscape(const char* name, const char* s) { |
| 405 PrintPropertyName(name); | 449 PrintPropertyName(name); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 665 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 622 va_end(args); | 666 va_end(args); |
| 623 ASSERT(len == len2); | 667 ASSERT(len == len2); |
| 624 stream_->buffer_.AddChar('"'); | 668 stream_->buffer_.AddChar('"'); |
| 625 stream_->AddEscapedUTF8String(p); | 669 stream_->AddEscapedUTF8String(p); |
| 626 stream_->buffer_.AddChar('"'); | 670 stream_->buffer_.AddChar('"'); |
| 627 free(p); | 671 free(p); |
| 628 } | 672 } |
| 629 | 673 |
| 630 } // namespace dart | 674 } // namespace dart |
| OLD | NEW |