Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of _js_helper; | 5 part of _js_helper; |
| 6 | 6 |
| 7 class StringMatch implements Match { | 7 class StringMatch implements Match { |
| 8 const StringMatch(int this.start, | 8 const StringMatch(int this.start, |
| 9 String this.input, | 9 String this.input, |
| 10 String this.pattern); | 10 String this.pattern); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 } | 186 } |
| 187 buffer.write(onNonMatch(receiver.substring(startIndex, position))); | 187 buffer.write(onNonMatch(receiver.substring(startIndex, position))); |
| 188 buffer.write(onMatch(new StringMatch(position, receiver, pattern))); | 188 buffer.write(onMatch(new StringMatch(position, receiver, pattern))); |
| 189 startIndex = position + patternLength; | 189 startIndex = position + patternLength; |
| 190 } | 190 } |
| 191 buffer.write(onNonMatch(receiver.substring(startIndex))); | 191 buffer.write(onNonMatch(receiver.substring(startIndex))); |
| 192 return buffer.toString(); | 192 return buffer.toString(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 | 195 |
| 196 stringReplaceFirstUnchecked(receiver, from, to, [int startIndex = 0]) { | 196 stringReplaceFirstUnchecked(receiver, from, to, int startIndex) { |
| 197 if (from is String) { | 197 if (from is String) { |
| 198 var index = receiver.indexOf(from, startIndex); | 198 var index = receiver.indexOf(from, startIndex); |
|
floitsch
2015/02/11 11:49:14
we are missing types here... (and in your code).
Lasse Reichstein Nielsen
2015/02/12 09:17:16
Added.
You are also missing types on all the funct
| |
| 199 if (index < 0) return receiver; | 199 if (index < 0) return receiver; |
| 200 return '${receiver.substring(0, index)}$to' | 200 return '${receiver.substring(0, index)}$to' |
| 201 '${receiver.substring(index + from.length)}'; | 201 '${receiver.substring(index + from.length)}'; |
| 202 } else if (from is JSSyntaxRegExp) { | 202 } |
| 203 if (from is JSSyntaxRegExp) { | |
| 203 return startIndex == 0 ? | 204 return startIndex == 0 ? |
| 204 stringReplaceJS(receiver, regExpGetNative(from), to) : | 205 stringReplaceJS(receiver, regExpGetNative(from), to) : |
| 205 stringReplaceFirstRE(receiver, from, to, startIndex); | 206 stringReplaceFirstRE(receiver, from, to, startIndex); |
| 206 } else { | |
| 207 checkNull(from); | |
| 208 // TODO(floitsch): implement generic String.replace (with patterns). | |
| 209 throw "String.replace(Pattern) UNIMPLEMENTED"; | |
| 210 } | 207 } |
| 208 checkNull(from); | |
| 209 var matches = from.allMatches(receiver, startIndex).iterator; | |
| 210 if (!matches.moveNext()) return receiver; | |
| 211 var match = matches.current; | |
| 212 return '${receiver.substring(0, match.start)}$to' | |
| 213 '${receiver.substring(match.end)}'; | |
| 214 } | |
| 215 | |
| 216 stringReplaceFirstMappedUnchecked(receiver, from, replace, | |
| 217 int startIndex) { | |
| 218 var matches = from.allMatches(receiver, startIndex).iterator; | |
| 219 if (!matches.moveNext()) return receiver; | |
| 220 var match = matches.current; | |
| 221 var replacement = "${replace(match)}"; | |
| 222 return '${receiver.substring(0, match.start)}$replacement' | |
| 223 '${receiver.substring(match.end)}'; | |
| 211 } | 224 } |
| 212 | 225 |
| 213 stringJoinUnchecked(array, separator) { | 226 stringJoinUnchecked(array, separator) { |
| 214 return JS('String', r'#.join(#)', array, separator); | 227 return JS('String', r'#.join(#)', array, separator); |
| 215 } | 228 } |
| OLD | NEW |