| OLD | NEW |
| 1 /// Misc things that were useful when porting the code from Python. | 1 /// Misc things that were useful when porting the code from Python. |
| 2 library utils; | 2 library utils; |
| 3 | 3 |
| 4 import 'constants.dart'; | 4 import 'constants.dart'; |
| 5 | 5 |
| 6 typedef bool Predicate(); | 6 typedef bool Predicate(); |
| 7 | 7 |
| 8 class Pair<F, S> { | 8 class Pair<F, S> { |
| 9 final F first; | 9 final F first; |
| 10 final S second; | 10 final S second; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 bool startsWithAny(String str, List<String> prefixes) { | 36 bool startsWithAny(String str, List<String> prefixes) { |
| 37 for (var prefix in prefixes) { | 37 for (var prefix in prefixes) { |
| 38 if (str.startsWith(prefix)) { | 38 if (str.startsWith(prefix)) { |
| 39 return true; | 39 return true; |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 return false; | 42 return false; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Like the python [:] operator. | 45 // Like the python [:] operator. |
| 46 List slice(List list, int start, [int end]) { | 46 List/*<T>*/ slice/*<T>*/(List/*<T>*/ list, int start, [int end]) { |
| 47 if (end == null) end = list.length; | 47 if (end == null) end = list.length; |
| 48 if (end < 0) end += list.length; | 48 if (end < 0) end += list.length; |
| 49 | 49 |
| 50 // Ensure the indexes are in bounds. | 50 // Ensure the indexes are in bounds. |
| 51 if (end < start) end = start; | 51 if (end < start) end = start; |
| 52 if (end > list.length) end = list.length; | 52 if (end > list.length) end = list.length; |
| 53 return list.sublist(start, end); | 53 return list.sublist(start, end); |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool allWhitespace(String str) { | 56 bool allWhitespace(String str) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 last = match + 1; | 115 last = match + 1; |
| 116 } | 116 } |
| 117 | 117 |
| 118 result.write(format.substring(last, format.length)); | 118 result.write(format.substring(last, format.length)); |
| 119 format = result.toString(); | 119 format = result.toString(); |
| 120 }); | 120 }); |
| 121 | 121 |
| 122 return format; | 122 return format; |
| 123 } | 123 } |
| OLD | NEW |