OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart._internal; | 5 library dart._internal; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'dart:core' hide Symbol; | 9 import 'dart:core' hide Symbol; |
10 import 'dart:core' as core; | 10 import 'dart:core' as core; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 /// Marks a function as an external implementation ("native" in the Dart VM). | 64 /// Marks a function as an external implementation ("native" in the Dart VM). |
65 /// | 65 /// |
66 /// Provides a backend-specific String that can be used to identify the | 66 /// Provides a backend-specific String that can be used to identify the |
67 /// function's implementation. | 67 /// function's implementation. |
68 class ExternalName { | 68 class ExternalName { |
69 final String name; | 69 final String name; |
70 const ExternalName(this.name); | 70 const ExternalName(this.name); |
71 } | 71 } |
| 72 |
| 73 // Shared hex-parsing utilities. |
| 74 |
| 75 /// Parses a single hex-digit as code unit. |
| 76 /// |
| 77 /// Returns a negative value if the character is not a valid hex-digit. |
| 78 int hexDigitValue(int char) { |
| 79 assert(char >= 0 && char <= 0xFFFF); |
| 80 const int digit0 = 0x30; |
| 81 const int a = 0x61; |
| 82 const int f = 0x66; |
| 83 int digit = char ^ digit0; |
| 84 if (digit <= 9) return digit; |
| 85 int letter = (char | 0x20); |
| 86 if (a <= letter && letter <= f) return letter - (a - 10); |
| 87 return -1; |
| 88 } |
| 89 |
| 90 /// Parses two hex digits in a string. |
| 91 /// |
| 92 /// Returns a negative value if either digit isn't valid. |
| 93 int parseHexByte(String source, int index) { |
| 94 assert(index + 2 <= source.length); |
| 95 int digit1 = hexDigitValue(source.codeUnitAt(index)); |
| 96 int digit2 = hexDigitValue(source.codeUnitAt(index + 1)); |
| 97 return digit1 * 16 + digit2 - (digit2 & 256); |
| 98 } |
OLD | NEW |