| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library analyzer.src.summary.flat_buffers; | 5 library analyzer.src.summary.flat_buffers; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:math'; | 9 import 'dart:math'; |
| 10 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 class StringReader extends Reader<String> { | 660 class StringReader extends Reader<String> { |
| 661 const StringReader() : super(); | 661 const StringReader() : super(); |
| 662 | 662 |
| 663 @override | 663 @override |
| 664 int get size => 4; | 664 int get size => 4; |
| 665 | 665 |
| 666 @override | 666 @override |
| 667 String read(BufferPointer ref) { | 667 String read(BufferPointer ref) { |
| 668 BufferPointer object = ref.derefObject(); | 668 BufferPointer object = ref.derefObject(); |
| 669 int length = object._getUint32(); | 669 int length = object._getUint32(); |
| 670 return UTF8 | 670 Uint8List bytes = ref._buffer.buffer.asUint8List(object._offset + 4, length)
; |
| 671 .decode(ref._buffer.buffer.asUint8List(object._offset + 4, length)); | 671 if (_isLatin(bytes)) { |
| 672 return new String.fromCharCodes(bytes); |
| 673 } |
| 674 return UTF8.decode(bytes); |
| 675 } |
| 676 |
| 677 static bool _isLatin(Uint8List bytes) { |
| 678 int length = bytes.length; |
| 679 for (int i = 0; i < length; i++) { |
| 680 if (bytes[i] > 127) { |
| 681 return false; |
| 682 } |
| 683 } |
| 684 return true; |
| 672 } | 685 } |
| 673 } | 686 } |
| 674 | 687 |
| 675 /** | 688 /** |
| 676 * An abstract reader for tables. | 689 * An abstract reader for tables. |
| 677 */ | 690 */ |
| 678 abstract class TableReader<T> extends Reader<T> { | 691 abstract class TableReader<T> extends Reader<T> { |
| 679 const TableReader(); | 692 const TableReader(); |
| 680 | 693 |
| 681 @override | 694 @override |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 // Table size. | 948 // Table size. |
| 936 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN); | 949 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN); |
| 937 bufOffset += 2; | 950 bufOffset += 2; |
| 938 // Field offsets. | 951 // Field offsets. |
| 939 for (int fieldOffset in fieldOffsets) { | 952 for (int fieldOffset in fieldOffsets) { |
| 940 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN); | 953 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN); |
| 941 bufOffset += 2; | 954 bufOffset += 2; |
| 942 } | 955 } |
| 943 } | 956 } |
| 944 } | 957 } |
| OLD | NEW |