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

Side by Side Diff: dart/frog/leg/scanner/byte_strings.dart

Issue 9447100: Return null from stringValue and call slowToString() instead of toString(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: changes Created 8 years, 10 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
« no previous file with comments | « dart/frog/leg/resolver.dart ('k') | dart/frog/leg/scanner/keyword.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** 5 /**
6 * An abstract string representation. 6 * An abstract string representation.
7 */ 7 */
8 class ByteString implements SourceString { 8 class ByteString implements SourceString {
9 final List<int> bytes; 9 final List<int> bytes;
10 final int offset; 10 final int offset;
11 final int length; 11 final int length;
12 int _hashCode; 12 int _hashCode;
13 13
14 ByteString(List<int> this.bytes, int this.offset, int this.length); 14 ByteString(List<int> this.bytes, int this.offset, int this.length);
15 15
16 abstract String get charset(); 16 abstract String get charset();
17 17
18 String toString() => new String.fromCharCodes( 18 String slowToString() => new String.fromCharCodes(
19 new Utf8Decoder(bytes, offset, length).decodeRest()); 19 new Utf8Decoder(bytes, offset, length).decodeRest());
20 20
21 String toString() => "ByteString(${slowToString()})";
22
21 bool operator ==(other) { 23 bool operator ==(other) {
22 throw "should be overridden in subclass"; 24 throw "should be overridden in subclass";
23 } 25 }
24 26
25 Iterator<int> iterator() => new Utf8Decoder(bytes, offset, length); 27 Iterator<int> iterator() => new Utf8Decoder(bytes, offset, length);
26 28
27 int hashCode() { 29 int hashCode() {
28 if (_hashCode === null) { 30 if (_hashCode === null) {
29 _hashCode = computeHashCode(); 31 _hashCode = computeHashCode();
30 } 32 }
31 return _hashCode; 33 return _hashCode;
32 } 34 }
33 35
34 int computeHashCode() { 36 int computeHashCode() {
35 int code = 1; 37 int code = 1;
36 int end = offset + length; 38 int end = offset + length;
37 for (int i = offset; i < end; i++) { 39 for (int i = offset; i < end; i++) {
38 code += 19 * code + bytes[i]; 40 code += 19 * code + bytes[i];
39 } 41 }
40 return code; 42 return code;
41 } 43 }
42 44
43 printOn(StringBuffer sb) { 45 printOn(StringBuffer sb) {
44 sb.add(toString()); 46 sb.add(slowToString());
45 } 47 }
46 48
47 bool isEmpty() => length == 0; 49 bool isEmpty() => length == 0;
48 } 50 }
49 51
50 /** 52 /**
51 * A string that consists purely of 7bit ASCII characters. 53 * A string that consists purely of 7bit ASCII characters.
52 */ 54 */
53 class AsciiString extends ByteString { 55 class AsciiString extends ByteString {
54 final String charset = "ASCII"; 56 final String charset = "ASCII";
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 * A ByteString-valued token. 132 * A ByteString-valued token.
131 */ 133 */
132 class ByteStringToken extends Token { 134 class ByteStringToken extends Token {
133 final ByteString value; 135 final ByteString value;
134 136
135 ByteStringToken(PrecedenceInfo info, ByteString this.value, int charOffset) 137 ByteStringToken(PrecedenceInfo info, ByteString this.value, int charOffset)
136 : super(info, charOffset); 138 : super(info, charOffset);
137 139
138 String toString() => value.toString(); 140 String toString() => value.toString();
139 } 141 }
OLDNEW
« no previous file with comments | « dart/frog/leg/resolver.dart ('k') | dart/frog/leg/scanner/keyword.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698