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 patch class Symbol { | 5 patch class Symbol { |
6 final String _name; | |
7 /* patch */ const Symbol(String name) | 6 /* patch */ const Symbol(String name) |
Søren Gjesse
2013/04/15 14:08:31
Four space indent.
ahe
2013/04/15 14:29:55
Done.
| |
8 : this._name = _validate(name); | 7 : this._name = _validate(name); |
9 | 8 |
10 | |
11 static final RegExp _validationPattern = | 9 static final RegExp _validationPattern = |
12 new RegExp(r'^[a-zA-Z$][a-zA-Z$0-9_]*=?'); | 10 new RegExp(r'^(?:[a-zA-Z$][a-zA-Z$0-9_]*\.)*(?:[a-zA-Z$][a-zA-Z$0-9_]*=?|' |
11 r'-|' | |
12 r'unary-|' | |
13 r'\[\]=|' | |
14 r'~|' | |
15 r'==|' | |
16 r'\[\]|' | |
17 r'\*|' | |
18 r'/|' | |
19 r'%|' | |
20 r'~/|' | |
21 r'\+|' | |
22 r'<<|' | |
23 r'>>|' | |
24 r'>=|' | |
25 r'>|' | |
26 r'<=|' | |
27 r'<|' | |
28 r'&|' | |
29 r'\^|' | |
30 r'\|' | |
31 r')$'); | |
13 | 32 |
14 static _validate(String name) { | 33 static _validate(String name) { |
15 if (name is! String) throw new ArgumentError('name must be a String'); | 34 if (name is! String) throw new ArgumentError('name must be a String'); |
16 if (name.isEmpty) return; | 35 if (name.isEmpty) return name; |
17 if (name.startsWith('_')) { | 36 if (name.startsWith('_')) { |
18 throw new ArgumentError('"$name" is a private identifier'); | 37 throw new ArgumentError('"$name" is a private identifier'); |
19 } | 38 } |
20 if (!_validationPattern.hasMatch(name)) { | 39 if (!_validationPattern.hasMatch(name)) { |
21 throw new ArgumentError( | 40 throw new ArgumentError( |
22 » '"$name" is not an identifier or an empty String'); | 41 '"$name" is not an identifier or an empty String'); |
23 } | 42 } |
24 return name; | 43 return name; |
25 } | 44 } |
26 | |
27 /* patch */ bool operator ==(other) { | |
28 return other is Symbol && _name == other._name; | |
29 } | |
30 | |
31 /* patch */ int get hashCode { | |
32 const arbitraryPrime = 664597; | |
33 return 0x1fffffff & (arbitraryPrime * _name.hashCode); | |
34 } | |
35 } | 45 } |
OLD | NEW |