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

Side by Side Diff: frog/utils.dart

Issue 8729018: Fixing string compile-time constant evaluation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: john comments Created 9 years 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 | « frog/member.dart ('k') | tests/language/src/ConstStringTest.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 // Collection<T> supports most of the ES 5 Array methods, but it's missing 5 // Collection<T> supports most of the ES 5 Array methods, but it's missing
6 // map and reduce. 6 // map and reduce.
7 7
8 // TODO(jmesserly): we might want a version of this that return an iterable, 8 // TODO(jmesserly): we might want a version of this that return an iterable,
9 // however JS, Python and Ruby versions are all eager. 9 // however JS, Python and Ruby versions are all eager.
10 List map(Iterable source, mapper(source)) { 10 List map(Iterable source, mapper(source)) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 /** True if this is a triple quoted Dart string literal. */ 64 /** True if this is a triple quoted Dart string literal. */
65 bool isMultilineString(String text) { 65 bool isMultilineString(String text) {
66 return text.startsWith('"""') || text.startsWith("'''"); 66 return text.startsWith('"""') || text.startsWith("'''");
67 } 67 }
68 68
69 bool isRawMultilineString(String text) { 69 bool isRawMultilineString(String text) {
70 return text.startsWith('@"""') || text.startsWith("@'''"); 70 return text.startsWith('@"""') || text.startsWith("@'''");
71 } 71 }
72 72
73 /**
74 * Convert a single-quote string to be a double-quote string by replacing " with
75 * \" and \' with '.
76 */
77 String toDoubleQuote(String s) {
78 return s.replaceAll('"', '\\"').replaceAll("\\'", "'");
79 }
80
81
73 // TODO(jmesserly): it'd be nice to deal with this in the tokenizer, rather than 82 // TODO(jmesserly): it'd be nice to deal with this in the tokenizer, rather than
74 // taking another pass over the string. 83 // taking another pass over the string.
75 String parseStringLiteral(String lit) { 84 String parseStringLiteral(String lit) {
76 if (lit.startsWith('@')) { 85 if (lit.startsWith('@')) {
77 if (isRawMultilineString(lit)) { 86 if (isRawMultilineString(lit)) {
78 return stripLeadingNewline(lit.substring(4, lit.length - 3)); 87 return stripLeadingNewline(lit.substring(4, lit.length - 3));
79 } else { 88 } else {
80 return lit.substring(2, lit.length - 1); 89 return lit.substring(2, lit.length - 1);
81 } 90 }
82 } else if (isMultilineString(lit)) { 91 } else if (isMultilineString(lit)) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 final int length; 135 final int length;
127 int _index = 0; 136 int _index = 0;
128 FixedIterator(this.value, this.length); 137 FixedIterator(this.value, this.length);
129 138
130 bool hasNext() => _index < length; 139 bool hasNext() => _index < length;
131 E next() { 140 E next() {
132 _index++; 141 _index++;
133 return value; 142 return value;
134 } 143 }
135 } 144 }
OLDNEW
« no previous file with comments | « frog/member.dart ('k') | tests/language/src/ConstStringTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698