| 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 /** | 5 /** |
| 6 * Generic utility functions. Stuff that should possibly be in core. | 6 * Generic utility functions. Stuff that should possibly be in core. |
| 7 */ | 7 */ |
| 8 #library('utils'); | 8 #library('utils'); |
| 9 | 9 |
| 10 /** Thrown by methods that parse text when the text isn't a valid. */ | 10 /** Thrown by methods that parse text when the text isn't a valid. */ |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 var buffer = new StringBuffer(); | 93 var buffer = new StringBuffer(); |
| 94 var start = 0; | 94 var start = 0; |
| 95 for (var match in matcher.allMatches(source)) { | 95 for (var match in matcher.allMatches(source)) { |
| 96 buffer.add(source.substring(start, match.start())); | 96 buffer.add(source.substring(start, match.start())); |
| 97 start = match.end(); | 97 start = match.end(); |
| 98 buffer.add(fn(match)); | 98 buffer.add(fn(match)); |
| 99 } | 99 } |
| 100 buffer.add(source.substring(start)); | 100 buffer.add(source.substring(start)); |
| 101 return buffer.toString(); | 101 return buffer.toString(); |
| 102 } | 102 } |
| 103 |
| 104 /** |
| 105 * Returns whether or not [str] ends with [matcher]. |
| 106 */ |
| 107 bool endsWithPattern(String str, Pattern matcher) { |
| 108 for (var match in matcher.allMatches(str)) { |
| 109 if (match.end() == str.length) return true; |
| 110 } |
| 111 return false; |
| 112 } |
| OLD | NEW |