| 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 /* patch */ const Symbol(String name) | 6 /* patch */ const Symbol(String name) |
| 7 : this._name = _validate(name); | 7 : this._name = validate(name); |
| 8 | |
| 9 static final RegExp _validationPattern = | |
| 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')$'); | |
| 32 | |
| 33 static _validate(String name) { | |
| 34 if (name.isEmpty) return name; | |
| 35 if (name.startsWith('_')) { | |
| 36 throw new ArgumentError('"$name" is a private identifier'); | |
| 37 } | |
| 38 if (!_validationPattern.hasMatch(name)) { | |
| 39 throw new ArgumentError( | |
| 40 '"$name" is not an identifier or an empty String'); | |
| 41 } | |
| 42 return name; | |
| 43 } | |
| 44 } | 8 } |
| OLD | NEW |