Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 patch class Symbol { | |
| 6 final String _name; | |
| 7 /* patch */ const Symbol(String name) | |
| 8 : this._name = _validate(name); | |
| 9 | |
| 10 | |
| 11 static final RegExp _validationPattern = | |
| 12 new RegExp(r'^[a-zA-Z$][a-zA-Z$0-9_]*=?'); | |
| 13 | |
| 14 static _validate(String name) { | |
| 15 if (name is! String) throw new ArgumentError('name must be a String'); | |
| 16 if (name.isEmpty) return; | |
| 17 if (name.startsWith('_')) { | |
| 18 throw new ArgumentError('"$name" is a private identifier'); | |
| 19 } | |
| 20 if (!_validationPattern.hasMatch(name)) { | |
| 21 throw new ArgumentError( | |
| 22 '"$name" is not an identifier or an empty String'); | |
| 23 } | |
| 24 return name; | |
| 25 } | |
| 26 | |
| 27 /* patch */ bool operator ==(other) { | |
| 28 return _name == _name; | |
|
kasperl
2013/04/11 11:37:00
Shouldn't this be checking that other is a Symbol
ahe
2013/04/11 11:47:50
Done.
| |
| 29 } | |
| 30 | |
| 31 /* patch */ int get hashCode { | |
| 32 const arbitraryPrime = 664597; | |
| 33 return 0x1fffffff & (arbitraryPrime * _name.hashCode); | |
| 34 } | |
| 35 } | |
| OLD | NEW |