Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: dart/runtime/lib/symbol_patch.dart

Issue 14142003: Add Symbol class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Implement hashCode and equals Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698