| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 convert.hex.encoder; | 5 library convert.hex.encoder; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
| 9 | 9 |
| 10 import 'package:charcode/ascii.dart'; | 10 import 'package:charcode/ascii.dart'; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 buffer[bufferIndex++] = _codeUnitForDigit((byte & 0xF0) >> 4); | 68 buffer[bufferIndex++] = _codeUnitForDigit((byte & 0xF0) >> 4); |
| 69 buffer[bufferIndex++] = _codeUnitForDigit(byte & 0x0F); | 69 buffer[bufferIndex++] = _codeUnitForDigit(byte & 0x0F); |
| 70 } | 70 } |
| 71 | 71 |
| 72 if (byteOr >= 0 && byteOr <= 255) return new String.fromCharCodes(buffer); | 72 if (byteOr >= 0 && byteOr <= 255) return new String.fromCharCodes(buffer); |
| 73 | 73 |
| 74 // If there was an invalid byte, find it and throw an exception. | 74 // If there was an invalid byte, find it and throw an exception. |
| 75 for (var i = start; i < end; i++) { | 75 for (var i = start; i < end; i++) { |
| 76 var byte = bytes[i]; | 76 var byte = bytes[i]; |
| 77 if (byte >= 0 && byte <= 0xff) continue; | 77 if (byte >= 0 && byte <= 0xff) continue; |
| 78 throw new FormatException("Invalid byte 0x${byte.toRadixString(16)}.", | 78 throw new FormatException( |
| 79 "Invalid byte ${byte < 0 ? "-" : ""}0x${byte.abs().toRadixString(16)}.", |
| 79 bytes, i); | 80 bytes, i); |
| 80 } | 81 } |
| 81 | 82 |
| 82 throw 'unreachable'; | 83 throw 'unreachable'; |
| 83 } | 84 } |
| 84 | 85 |
| 85 /// Returns the ASCII/Unicode code unit corresponding to the hexadecimal digit | 86 /// Returns the ASCII/Unicode code unit corresponding to the hexadecimal digit |
| 86 /// [digit]. | 87 /// [digit]. |
| 87 int _codeUnitForDigit(int digit) => digit < 10 ? digit + $0 : digit + $a - 10; | 88 int _codeUnitForDigit(int digit) => digit < 10 ? digit + $0 : digit + $a - 10; |
| OLD | NEW |