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

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

Issue 9301037: Made multiline string literals ignore an initial newline. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « no previous file | frog/leg/scanner/string_scanner.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;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return new Utf8String(bytes, offset, length); 102 return new Utf8String(bytes, offset, length);
103 } 103 }
104 104
105 static Utf8String fromString(String string) { 105 static Utf8String fromString(String string) {
106 throw "not implemented yet"; 106 throw "not implemented yet";
107 } 107 }
108 108
109 Iterator<int> iterator() => new Utf8Decoder(bytes, 0, length); 109 Iterator<int> iterator() => new Utf8Decoder(bytes, 0, length);
110 110
111 SourceString copyWithoutQuotes(int initial, int terminal) { 111 SourceString copyWithoutQuotes(int initial, int terminal) {
112 assert(0 <= initial && initial <= 4); 112 assert((){
113 assert(initial !== 1 || bytes[offset] === $SQ || 113 // Only allow dropping ASCII characters, to guarantee that
114 bytes[offset] === $DQ); 114 // the resulting Utf8String is still valid.
115 assert(initial !== 2 || (bytes[offset] === $AT && 115 for (int i = 0; i < initial; i++) {
116 (bytes[offset + 1] === $SQ || 116 if (bytes[offset + i] >= 0x80) return false;
117 bytes[offset + 1] === $DQ))); 117 }
118 assert(initial !== 3 || ((bytes[offset] === $SQ || 118 for (int i = 0; i < terminal; i++) {
119 bytes[offset] === $DQ) && 119 if (bytes[offset + length - terminal + i] >= 0x80) return false;
120 bytes[offset] === bytes[offset + 1] && 120 }
121 bytes[offset] === bytes[offset + 2])); 121 return true;
122 assert(initial !== 4 || (bytes[offset] === $AT && 122 }());
ahe 2012/01/31 14:08:32 You don't need to call the function.
123 (bytes[offset + 1] === $SQ ||
124 bytes[offset + 1] === $DQ) &&
125 bytes[offset + 2] === bytes[offset + 1] &&
126 bytes[offset + 3] === bytes[offset + 1]));
127 assert(terminal === 0 || terminal === 1 || terminal === 3);
128 assert(terminal === 0 || ((bytes[end - 1] == $AT ||
129 bytes[end - 1] === $DQ) &&
130 (terminal === 1 ||
131 bytes[end - 2] === bytes[end - 1] &&
132 bytes[end - 3] === bytes[end - 1])));
133 // TODO(lrn): Check that first and last bytes use the same type of quotes. 123 // TODO(lrn): Check that first and last bytes use the same type of quotes.
134 return new Utf8String(bytes, offset + initial, 124 return new Utf8String(bytes, offset + initial,
135 length - initial - terminal); 125 length - initial - terminal);
136 } 126 }
137 } 127 }
138 128
139 /** 129 /**
140 * A ByteString-valued token. 130 * A ByteString-valued token.
141 */ 131 */
142 class ByteStringToken extends Token { 132 class ByteStringToken extends Token {
143 final ByteString value; 133 final ByteString value;
144 134
145 ByteStringToken(PrecedenceInfo info, ByteString this.value, int charOffset) 135 ByteStringToken(PrecedenceInfo info, ByteString this.value, int charOffset)
146 : super(info, charOffset); 136 : super(info, charOffset);
147 137
148 String toString() => value.toString(); 138 String toString() => value.toString();
149 } 139 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/scanner/string_scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698