| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 static Interner INTERNER = new NullInterner(); | 122 static Interner INTERNER = new NullInterner(); |
| 123 | 123 |
| 124 static endsWith3(String str, int c1, int c2, int c3) { | 124 static endsWith3(String str, int c1, int c2, int c3) { |
| 125 var length = str.length; | 125 var length = str.length; |
| 126 return length >= 3 && | 126 return length >= 3 && |
| 127 str.codeUnitAt(length - 3) == c1 && | 127 str.codeUnitAt(length - 3) == c1 && |
| 128 str.codeUnitAt(length - 2) == c2 && | 128 str.codeUnitAt(length - 2) == c2 && |
| 129 str.codeUnitAt(length - 1) == c3; | 129 str.codeUnitAt(length - 1) == c3; |
| 130 } | 130 } |
| 131 |
| 131 static endsWithChar(String str, int c) { | 132 static endsWithChar(String str, int c) { |
| 132 int length = str.length; | 133 int length = str.length; |
| 133 return length > 0 && str.codeUnitAt(length - 1) == c; | 134 return length > 0 && str.codeUnitAt(length - 1) == c; |
| 134 } | 135 } |
| 136 |
| 135 static int indexOf1(String str, int start, int c) { | 137 static int indexOf1(String str, int start, int c) { |
| 136 int index = start; | 138 int index = start; |
| 137 int last = str.length; | 139 int last = str.length; |
| 138 while (index < last) { | 140 while (index < last) { |
| 139 if (str.codeUnitAt(index) == c) { | 141 if (str.codeUnitAt(index) == c) { |
| 140 return index; | 142 return index; |
| 141 } | 143 } |
| 142 index++; | 144 index++; |
| 143 } | 145 } |
| 144 return -1; | 146 return -1; |
| 145 } | 147 } |
| 148 |
| 146 static int indexOf2(String str, int start, int c1, int c2) { | 149 static int indexOf2(String str, int start, int c1, int c2) { |
| 147 int index = start; | 150 int index = start; |
| 148 int last = str.length - 1; | 151 int last = str.length - 1; |
| 149 while (index < last) { | 152 while (index < last) { |
| 150 if (str.codeUnitAt(index) == c1 && str.codeUnitAt(index + 1) == c2) { | 153 if (str.codeUnitAt(index) == c1 && str.codeUnitAt(index + 1) == c2) { |
| 151 return index; | 154 return index; |
| 152 } | 155 } |
| 153 index++; | 156 index++; |
| 154 } | 157 } |
| 155 return -1; | 158 return -1; |
| 156 } | 159 } |
| 160 |
| 157 static int indexOf4( | 161 static int indexOf4( |
| 158 String string, int start, int c1, int c2, int c3, int c4) { | 162 String string, int start, int c1, int c2, int c3, int c4) { |
| 159 int index = start; | 163 int index = start; |
| 160 int last = string.length - 3; | 164 int last = string.length - 3; |
| 161 while (index < last) { | 165 while (index < last) { |
| 162 if (string.codeUnitAt(index) == c1 && | 166 if (string.codeUnitAt(index) == c1 && |
| 163 string.codeUnitAt(index + 1) == c2 && | 167 string.codeUnitAt(index + 1) == c2 && |
| 164 string.codeUnitAt(index + 2) == c3 && | 168 string.codeUnitAt(index + 2) == c3 && |
| 165 string.codeUnitAt(index + 3) == c4) { | 169 string.codeUnitAt(index + 3) == c4) { |
| 166 return index; | 170 return index; |
| 167 } | 171 } |
| 168 index++; | 172 index++; |
| 169 } | 173 } |
| 170 return -1; | 174 return -1; |
| 171 } | 175 } |
| 176 |
| 172 static int indexOf5( | 177 static int indexOf5( |
| 173 String str, int start, int c1, int c2, int c3, int c4, int c5) { | 178 String str, int start, int c1, int c2, int c3, int c4, int c5) { |
| 174 int index = start; | 179 int index = start; |
| 175 int last = str.length - 4; | 180 int last = str.length - 4; |
| 176 while (index < last) { | 181 while (index < last) { |
| 177 if (str.codeUnitAt(index) == c1 && | 182 if (str.codeUnitAt(index) == c1 && |
| 178 str.codeUnitAt(index + 1) == c2 && | 183 str.codeUnitAt(index + 1) == c2 && |
| 179 str.codeUnitAt(index + 2) == c3 && | 184 str.codeUnitAt(index + 2) == c3 && |
| 180 str.codeUnitAt(index + 3) == c4 && | 185 str.codeUnitAt(index + 3) == c4 && |
| 181 str.codeUnitAt(index + 4) == c5) { | 186 str.codeUnitAt(index + 4) == c5) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 196 int last = string.length; | 201 int last = string.length; |
| 197 while (index < last) { | 202 while (index < last) { |
| 198 int c = string.codeUnitAt(index); | 203 int c = string.codeUnitAt(index); |
| 199 if (!Character.isLetterOrDigit(c)) { | 204 if (!Character.isLetterOrDigit(c)) { |
| 200 return index; | 205 return index; |
| 201 } | 206 } |
| 202 index++; | 207 index++; |
| 203 } | 208 } |
| 204 return last; | 209 return last; |
| 205 } | 210 } |
| 211 |
| 206 static String intern(String string) => INTERNER.intern(string); | 212 static String intern(String string) => INTERNER.intern(string); |
| 207 static bool isEmpty(String s) { | 213 static bool isEmpty(String s) { |
| 208 return s == null || s.isEmpty; | 214 return s == null || s.isEmpty; |
| 209 } | 215 } |
| 216 |
| 210 static bool isTagName(String s) { | 217 static bool isTagName(String s) { |
| 211 if (s == null || s.length == 0) { | 218 if (s == null || s.length == 0) { |
| 212 return false; | 219 return false; |
| 213 } | 220 } |
| 214 int sz = s.length; | 221 int sz = s.length; |
| 215 for (int i = 0; i < sz; i++) { | 222 for (int i = 0; i < sz; i++) { |
| 216 int c = s.codeUnitAt(i); | 223 int c = s.codeUnitAt(i); |
| 217 if (!Character.isLetter(c)) { | 224 if (!Character.isLetter(c)) { |
| 218 if (i == 0) { | 225 if (i == 0) { |
| 219 return false; | 226 return false; |
| 220 } | 227 } |
| 221 if (!Character.isDigit(c) && c != 0x2D) { | 228 if (!Character.isDigit(c) && c != 0x2D) { |
| 222 return false; | 229 return false; |
| 223 } | 230 } |
| 224 } | 231 } |
| 225 } | 232 } |
| 226 return true; | 233 return true; |
| 227 } | 234 } |
| 235 |
| 228 /** | 236 /** |
| 229 * Produce a string containing all of the names in the given array, surrounded
by single quotes, | 237 * Produce a string containing all of the names in the given array, surrounded
by single quotes, |
| 230 * and separated by commas. The list must contain at least two elements. | 238 * and separated by commas. The list must contain at least two elements. |
| 231 * | 239 * |
| 232 * @param names the names to be printed | 240 * @param names the names to be printed |
| 233 * @return the result of printing the names | 241 * @return the result of printing the names |
| 234 */ | 242 */ |
| 235 static String printListOfQuotedNames(List<String> names) { | 243 static String printListOfQuotedNames(List<String> names) { |
| 236 if (names == null) { | 244 if (names == null) { |
| 237 throw new IllegalArgumentException("The list must not be null"); | 245 throw new IllegalArgumentException("The list must not be null"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 248 for (int i = 1; i < count - 1; i++) { | 256 for (int i = 1; i < count - 1; i++) { |
| 249 buffer.write(", '"); | 257 buffer.write(", '"); |
| 250 buffer.write(names[i]); | 258 buffer.write(names[i]); |
| 251 buffer.write("'"); | 259 buffer.write("'"); |
| 252 } | 260 } |
| 253 buffer.write(" and '"); | 261 buffer.write(" and '"); |
| 254 buffer.write(names[count - 1]); | 262 buffer.write(names[count - 1]); |
| 255 buffer.write("'"); | 263 buffer.write("'"); |
| 256 return buffer.toString(); | 264 return buffer.toString(); |
| 257 } | 265 } |
| 266 |
| 258 static startsWith2(String str, int start, int c1, int c2) { | 267 static startsWith2(String str, int start, int c1, int c2) { |
| 259 return str.length - start >= 2 && | 268 return str.length - start >= 2 && |
| 260 str.codeUnitAt(start) == c1 && | 269 str.codeUnitAt(start) == c1 && |
| 261 str.codeUnitAt(start + 1) == c2; | 270 str.codeUnitAt(start + 1) == c2; |
| 262 } | 271 } |
| 272 |
| 263 static startsWith3(String str, int start, int c1, int c2, int c3) { | 273 static startsWith3(String str, int start, int c1, int c2, int c3) { |
| 264 return str.length - start >= 3 && | 274 return str.length - start >= 3 && |
| 265 str.codeUnitAt(start) == c1 && | 275 str.codeUnitAt(start) == c1 && |
| 266 str.codeUnitAt(start + 1) == c2 && | 276 str.codeUnitAt(start + 1) == c2 && |
| 267 str.codeUnitAt(start + 2) == c3; | 277 str.codeUnitAt(start + 2) == c3; |
| 268 } | 278 } |
| 279 |
| 269 static startsWith4(String str, int start, int c1, int c2, int c3, int c4) { | 280 static startsWith4(String str, int start, int c1, int c2, int c3, int c4) { |
| 270 return str.length - start >= 4 && | 281 return str.length - start >= 4 && |
| 271 str.codeUnitAt(start) == c1 && | 282 str.codeUnitAt(start) == c1 && |
| 272 str.codeUnitAt(start + 1) == c2 && | 283 str.codeUnitAt(start + 1) == c2 && |
| 273 str.codeUnitAt(start + 2) == c3 && | 284 str.codeUnitAt(start + 2) == c3 && |
| 274 str.codeUnitAt(start + 3) == c4; | 285 str.codeUnitAt(start + 3) == c4; |
| 275 } | 286 } |
| 287 |
| 276 static startsWith5( | 288 static startsWith5( |
| 277 String str, int start, int c1, int c2, int c3, int c4, int c5) { | 289 String str, int start, int c1, int c2, int c3, int c4, int c5) { |
| 278 return str.length - start >= 5 && | 290 return str.length - start >= 5 && |
| 279 str.codeUnitAt(start) == c1 && | 291 str.codeUnitAt(start) == c1 && |
| 280 str.codeUnitAt(start + 1) == c2 && | 292 str.codeUnitAt(start + 1) == c2 && |
| 281 str.codeUnitAt(start + 2) == c3 && | 293 str.codeUnitAt(start + 2) == c3 && |
| 282 str.codeUnitAt(start + 3) == c4 && | 294 str.codeUnitAt(start + 3) == c4 && |
| 283 str.codeUnitAt(start + 4) == c5; | 295 str.codeUnitAt(start + 4) == c5; |
| 284 } | 296 } |
| 297 |
| 285 static startsWith6( | 298 static startsWith6( |
| 286 String str, int start, int c1, int c2, int c3, int c4, int c5, int c6) { | 299 String str, int start, int c1, int c2, int c3, int c4, int c5, int c6) { |
| 287 return str.length - start >= 6 && | 300 return str.length - start >= 6 && |
| 288 str.codeUnitAt(start) == c1 && | 301 str.codeUnitAt(start) == c1 && |
| 289 str.codeUnitAt(start + 1) == c2 && | 302 str.codeUnitAt(start + 1) == c2 && |
| 290 str.codeUnitAt(start + 2) == c3 && | 303 str.codeUnitAt(start + 2) == c3 && |
| 291 str.codeUnitAt(start + 3) == c4 && | 304 str.codeUnitAt(start + 3) == c4 && |
| 292 str.codeUnitAt(start + 4) == c5 && | 305 str.codeUnitAt(start + 4) == c5 && |
| 293 str.codeUnitAt(start + 5) == c6; | 306 str.codeUnitAt(start + 5) == c6; |
| 294 } | 307 } |
| 308 |
| 295 static startsWithChar(String str, int c) { | 309 static startsWithChar(String str, int c) { |
| 296 return str.length != 0 && str.codeUnitAt(0) == c; | 310 return str.length != 0 && str.codeUnitAt(0) == c; |
| 297 } | 311 } |
| 298 | 312 |
| 299 static String substringBefore(String str, String separator) { | 313 static String substringBefore(String str, String separator) { |
| 300 if (str == null || str.isEmpty) { | 314 if (str == null || str.isEmpty) { |
| 301 return str; | 315 return str; |
| 302 } | 316 } |
| 303 if (separator == null) { | 317 if (separator == null) { |
| 304 return str; | 318 return str; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 322 } | 336 } |
| 323 } | 337 } |
| 324 | 338 |
| 325 class UUID { | 339 class UUID { |
| 326 static int __nextId = 0; | 340 static int __nextId = 0; |
| 327 final String id; | 341 final String id; |
| 328 UUID(this.id); | 342 UUID(this.id); |
| 329 String toString() => id; | 343 String toString() => id; |
| 330 static UUID randomUUID() => new UUID((__nextId).toString()); | 344 static UUID randomUUID() => new UUID((__nextId).toString()); |
| 331 } | 345 } |
| OLD | NEW |