Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 // TODO(jmesserly): it'd be nice to have SortedMap in corelib. | 54 // TODO(jmesserly): it'd be nice to have SortedMap in corelib. |
| 55 List keys = map.getKeys(); | 55 List keys = map.getKeys(); |
| 56 keys.sort((x, y) => x.compareTo(y)); | 56 keys.sort((x, y) => x.compareTo(y)); |
| 57 final values = []; | 57 final values = []; |
| 58 for (var k in keys) { | 58 for (var k in keys) { |
| 59 values.add(map[k]); | 59 values.add(map[k]); |
| 60 } | 60 } |
| 61 return values; | 61 return values; |
| 62 } | 62 } |
| 63 | 63 |
| 64 /** True if this is a triple quoted Dart string literal. */ | |
| 65 bool isMultilineString(String text) { | |
| 66 return text.startsWith('"""') || text.startsWith("'''"); | |
| 67 } | |
| 68 | |
| 69 bool isRawMultilineString(String text) { | |
| 70 return text.startsWith('@"""') || text.startsWith("@'''"); | |
| 71 } | |
| 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 | |
| 82 // TODO(jmesserly): it'd be nice to deal with this in the tokenizer, rather than | |
|
Jennifer Messerly
2012/01/09 20:16:26
yay, another todo--
| |
| 83 // taking another pass over the string. | |
| 84 String parseStringLiteral(String lit) { | |
| 85 if (lit.startsWith('@')) { | |
| 86 if (isRawMultilineString(lit)) { | |
| 87 return stripLeadingNewline(lit.substring(4, lit.length - 3)); | |
| 88 } else { | |
| 89 return lit.substring(2, lit.length - 1); | |
| 90 } | |
| 91 } else if (isMultilineString(lit)) { | |
| 92 lit = lit.substring(3, lit.length - 3).replaceAll('\\\$', '\$'); | |
| 93 return stripLeadingNewline(lit); | |
| 94 } else { | |
| 95 return lit.substring(1, lit.length - 1).replaceAll('\\\$', '\$'); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 // The first newline in a multiline string is removed. | |
| 100 String stripLeadingNewline(String text) { | |
| 101 if (text.startsWith('\n')) { | |
| 102 return text.substring(1); | |
| 103 } else if (text.startsWith('\r')) { | |
| 104 if (text.startsWith('\r\n')) { | |
| 105 return text.substring(2); | |
| 106 } else { | |
| 107 return text.substring(1); | |
| 108 } | |
| 109 } else { | |
| 110 return text; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 /** | 64 /** |
| 115 * A [FixedCollection] is a collection of [length] items all of which have the | 65 * A [FixedCollection] is a collection of [length] items all of which have the |
| 116 * identical [value] | 66 * identical [value] |
| 117 */ | 67 */ |
| 118 class FixedCollection<E> implements Collection<E> { | 68 class FixedCollection<E> implements Collection<E> { |
| 119 final E value; | 69 final E value; |
| 120 final int length; | 70 final int length; |
| 121 const FixedCollection(this.value, this.length); | 71 const FixedCollection(this.value, this.length); |
| 122 | 72 |
| 123 Iterator<E> iterator() => new FixedIterator<E>(value, length); | 73 Iterator<E> iterator() => new FixedIterator<E>(value, length); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 141 _index++; | 91 _index++; |
| 142 return value; | 92 return value; |
| 143 } | 93 } |
| 144 } | 94 } |
| 145 | 95 |
| 146 // Color constants used for generating messages. | 96 // Color constants used for generating messages. |
| 147 String _GREEN_COLOR = '\u001b[32m'; | 97 String _GREEN_COLOR = '\u001b[32m'; |
| 148 String _RED_COLOR = '\u001b[31m'; | 98 String _RED_COLOR = '\u001b[31m'; |
| 149 String _MAGENTA_COLOR = '\u001b[35m'; | 99 String _MAGENTA_COLOR = '\u001b[35m'; |
| 150 String _NO_COLOR = '\u001b[0m'; | 100 String _NO_COLOR = '\u001b[0m'; |
| OLD | NEW |