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 * [_StringBase] contains common methods used by concrete String | 6 * [_StringBase] contains common methods used by concrete String |
7 * implementations, e.g., _OneByteString. | 7 * implementations, e.g., _OneByteString. |
8 */ | 8 */ |
9 class _StringBase { | 9 class _StringBase { |
10 | 10 |
11 factory _StringBase._uninstantiable() { | 11 factory _StringBase._uninstantiable() { |
12 throw const UnsupportedOperationException( | 12 throw new UnsupportedError( |
13 "_StringBase can't be instaniated"); | 13 "_StringBase can't be instaniated"); |
14 } | 14 } |
15 | 15 |
16 int get hashCode native "String_getHashCode"; | 16 int get hashCode native "String_getHashCode"; |
17 | 17 |
18 /** | 18 /** |
19 * Create the most efficient string representation for specified | 19 * Create the most efficient string representation for specified |
20 * [codePoints]. | 20 * [codePoints]. |
21 */ | 21 */ |
22 static String createFromCharCodes(List<int> charCodes) { | 22 static String createFromCharCodes(List<int> charCodes) { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 return _concatAll(stringsArray); | 349 return _concatAll(stringsArray); |
350 } | 350 } |
351 | 351 |
352 static String _concatAll(_ObjectArray<String> strings) | 352 static String _concatAll(_ObjectArray<String> strings) |
353 native "Strings_concatAll"; | 353 native "Strings_concatAll"; |
354 } | 354 } |
355 | 355 |
356 | 356 |
357 class _OneByteString extends _StringBase implements String { | 357 class _OneByteString extends _StringBase implements String { |
358 factory _OneByteString._uninstantiable() { | 358 factory _OneByteString._uninstantiable() { |
359 throw const UnsupportedOperationException( | 359 throw new UnsupportedError( |
360 "_OneByteString can only be allocated by the VM"); | 360 "_OneByteString can only be allocated by the VM"); |
361 } | 361 } |
362 | 362 |
363 // Checks for one-byte whitespaces only. | 363 // Checks for one-byte whitespaces only. |
364 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid | 364 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid |
365 // whitespaces for one byte strings. | 365 // whitespaces for one byte strings. |
366 bool _isWhitespace(int codePoint) { | 366 bool _isWhitespace(int codePoint) { |
367 return | 367 return |
368 (codePoint === 32) || // Space. | 368 (codePoint === 32) || // Space. |
369 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. | 369 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. |
370 } | 370 } |
371 | 371 |
372 } | 372 } |
373 | 373 |
374 | 374 |
375 class _TwoByteString extends _StringBase implements String { | 375 class _TwoByteString extends _StringBase implements String { |
376 factory _TwoByteString._uninstantiable() { | 376 factory _TwoByteString._uninstantiable() { |
377 throw const UnsupportedOperationException( | 377 throw new UnsupportedError( |
378 "_TwoByteString can only be allocated by the VM"); | 378 "_TwoByteString can only be allocated by the VM"); |
379 } | 379 } |
380 | 380 |
381 // Checks for one-byte whitespaces only. | 381 // Checks for one-byte whitespaces only. |
382 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid | 382 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid |
383 // whitespaces. Add checking for multi-byte whitespace codepoints. | 383 // whitespaces. Add checking for multi-byte whitespace codepoints. |
384 bool _isWhitespace(int codePoint) { | 384 bool _isWhitespace(int codePoint) { |
385 return | 385 return |
386 (codePoint === 32) || // Space. | 386 (codePoint === 32) || // Space. |
387 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. | 387 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. |
388 } | 388 } |
389 } | 389 } |
390 | 390 |
391 | 391 |
392 class _FourByteString extends _StringBase implements String { | 392 class _FourByteString extends _StringBase implements String { |
393 factory _FourByteString._uninstantiable() { | 393 factory _FourByteString._uninstantiable() { |
394 throw const UnsupportedOperationException( | 394 throw new UnsupportedError( |
395 "_FourByteString can only be allocated by the VM"); | 395 "_FourByteString can only be allocated by the VM"); |
396 } | 396 } |
397 | 397 |
398 // Checks for one-byte whitespaces only. | 398 // Checks for one-byte whitespaces only. |
399 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid | 399 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid |
400 // whitespaces. Add checking for multi-byte whitespace codepoints. | 400 // whitespaces. Add checking for multi-byte whitespace codepoints. |
401 bool _isWhitespace(int codePoint) { | 401 bool _isWhitespace(int codePoint) { |
402 return | 402 return |
403 (codePoint === 32) || // Space. | 403 (codePoint === 32) || // Space. |
404 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. | 404 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. |
405 } | 405 } |
406 } | 406 } |
407 | 407 |
408 | 408 |
409 class _ExternalOneByteString extends _StringBase implements String { | 409 class _ExternalOneByteString extends _StringBase implements String { |
410 factory _ExternalOneByteString._uninstantiable() { | 410 factory _ExternalOneByteString._uninstantiable() { |
411 throw const UnsupportedOperationException( | 411 throw new UnsupportedError( |
412 "_ExternalOneByteString can only be allocated by the VM"); | 412 "_ExternalOneByteString can only be allocated by the VM"); |
413 } | 413 } |
414 | 414 |
415 // Checks for one-byte whitespaces only. | 415 // Checks for one-byte whitespaces only. |
416 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid | 416 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid |
417 // whitespaces for one byte strings. | 417 // whitespaces for one byte strings. |
418 bool _isWhitespace(int codePoint) { | 418 bool _isWhitespace(int codePoint) { |
419 return | 419 return |
420 (codePoint === 32) || // Space. | 420 (codePoint === 32) || // Space. |
421 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. | 421 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. |
422 } | 422 } |
423 } | 423 } |
424 | 424 |
425 | 425 |
426 class _ExternalTwoByteString extends _StringBase implements String { | 426 class _ExternalTwoByteString extends _StringBase implements String { |
427 factory ExternalTwoByteString._uninstantiable() { | 427 factory ExternalTwoByteString._uninstantiable() { |
428 throw const UnsupportedOperationException( | 428 throw new UnsupportedError( |
429 "_ExternalTwoByteString can only be allocated by the VM"); | 429 "_ExternalTwoByteString can only be allocated by the VM"); |
430 } | 430 } |
431 | 431 |
432 // Checks for one-byte whitespaces only. | 432 // Checks for one-byte whitespaces only. |
433 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid | 433 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid |
434 // whitespaces. Add checking for multi-byte whitespace codepoints. | 434 // whitespaces. Add checking for multi-byte whitespace codepoints. |
435 bool _isWhitespace(int codePoint) { | 435 bool _isWhitespace(int codePoint) { |
436 return | 436 return |
437 (codePoint === 32) || // Space. | 437 (codePoint === 32) || // Space. |
438 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. | 438 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. |
439 } | 439 } |
440 } | 440 } |
441 | 441 |
442 | 442 |
443 class _ExternalFourByteString extends _StringBase implements String { | 443 class _ExternalFourByteString extends _StringBase implements String { |
444 factory _ExternalFourByteString._uninstantiable() { | 444 factory _ExternalFourByteString._uninstantiable() { |
445 throw const UnsupportedOperationException( | 445 throw new UnsupportedError( |
446 "ExternalFourByteString can only be allocated by the VM"); | 446 "ExternalFourByteString can only be allocated by the VM"); |
447 } | 447 } |
448 | 448 |
449 // Checks for one-byte whitespaces only. | 449 // Checks for one-byte whitespaces only. |
450 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid | 450 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid |
451 // whitespaces. Add checking for multi-byte whitespace codepoints. | 451 // whitespaces. Add checking for multi-byte whitespace codepoints. |
452 bool _isWhitespace(int codePoint) { | 452 bool _isWhitespace(int codePoint) { |
453 return | 453 return |
454 (codePoint === 32) || // Space. | 454 (codePoint === 32) || // Space. |
455 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. | 455 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. |
(...skipping 23 matching lines...) Expand all Loading... |
479 for (int g in groups) { | 479 for (int g in groups) { |
480 result.add(group(g)); | 480 result.add(group(g)); |
481 } | 481 } |
482 return result; | 482 return result; |
483 } | 483 } |
484 | 484 |
485 final int _start; | 485 final int _start; |
486 final String str; | 486 final String str; |
487 final String pattern; | 487 final String pattern; |
488 } | 488 } |
OLD | NEW |