OLD | NEW |
1 library java.engine; | 1 library java.engine; |
2 | 2 |
3 import 'interner.dart'; | 3 import 'interner.dart'; |
4 import 'java_core.dart'; | 4 import 'java_core.dart'; |
5 | 5 |
6 /** | 6 /** |
7 * A predicate is a one-argument function that returns a boolean value. | 7 * A predicate is a one-argument function that returns a boolean value. |
8 */ | 8 */ |
9 typedef bool Predicate<E>(E argument); | 9 typedef bool Predicate<E>(E argument); |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 return ""; | 114 return ""; |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 class StringUtilities { | 118 class StringUtilities { |
119 static const String EMPTY = ''; | 119 static const String EMPTY = ''; |
120 static const List<String> EMPTY_ARRAY = const <String>[]; | 120 static const List<String> EMPTY_ARRAY = const <String>[]; |
121 | 121 |
122 static Interner INTERNER = new NullInterner(); | 122 static Interner INTERNER = new NullInterner(); |
123 | 123 |
| 124 /** |
| 125 * Compute line starts for the given [content]. |
| 126 * Lines end with `\r`, `\n` or `\r\n`. |
| 127 */ |
| 128 static List<int> computeLineStarts(String content) { |
| 129 List<int> lineStarts = <int>[0]; |
| 130 int length = content.length; |
| 131 int unit; |
| 132 for (int index = 0; index < length; index++) { |
| 133 unit = content.codeUnitAt(index); |
| 134 // Special-case \r\n. |
| 135 if (unit == 0x0D /* \r */) { |
| 136 // Peek ahead to detect a following \n. |
| 137 if ((index + 1 < length) && content.codeUnitAt(index + 1) == 0x0A) { |
| 138 // Line start will get registered at next index at the \n. |
| 139 } else { |
| 140 lineStarts.add(index + 1); |
| 141 } |
| 142 } |
| 143 // \n |
| 144 if (unit == 0x0A) { |
| 145 lineStarts.add(index + 1); |
| 146 } |
| 147 } |
| 148 return lineStarts; |
| 149 } |
| 150 |
124 static endsWith3(String str, int c1, int c2, int c3) { | 151 static endsWith3(String str, int c1, int c2, int c3) { |
125 var length = str.length; | 152 var length = str.length; |
126 return length >= 3 && | 153 return length >= 3 && |
127 str.codeUnitAt(length - 3) == c1 && | 154 str.codeUnitAt(length - 3) == c1 && |
128 str.codeUnitAt(length - 2) == c2 && | 155 str.codeUnitAt(length - 2) == c2 && |
129 str.codeUnitAt(length - 1) == c3; | 156 str.codeUnitAt(length - 1) == c3; |
130 } | 157 } |
131 | 158 |
132 static endsWithChar(String str, int c) { | 159 static endsWithChar(String str, int c) { |
133 int length = str.length; | 160 int length = str.length; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 363 } |
337 } | 364 } |
338 | 365 |
339 class UUID { | 366 class UUID { |
340 static int __nextId = 0; | 367 static int __nextId = 0; |
341 final String id; | 368 final String id; |
342 UUID(this.id); | 369 UUID(this.id); |
343 String toString() => id; | 370 String toString() => id; |
344 static UUID randomUUID() => new UUID((__nextId).toString()); | 371 static UUID randomUUID() => new UUID((__nextId).toString()); |
345 } | 372 } |
OLD | NEW |