| 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 patch class String { | 5 patch class String { |
| 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { | 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { |
| 7 return _StringBase.createFromCharCodes(charCodes); | 7 return _StringBase.createFromCharCodes(charCodes); |
| 8 } | 8 } |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 bool operator ==(Object other) { | 83 bool operator ==(Object other) { |
| 84 if (identical(this, other)) { | 84 if (identical(this, other)) { |
| 85 return true; | 85 return true; |
| 86 } | 86 } |
| 87 if ((other is !String) || | 87 if ((other is !String) || |
| 88 (this.length != other.length)) { | 88 (this.length != other.length)) { |
| 89 // TODO(5413632): Compare hash codes when both are present. | 89 // TODO(5413632): Compare hash codes when both are present. |
| 90 return false; | 90 return false; |
| 91 } | 91 } |
| 92 return this.compareTo(other) == 0; | 92 final len = this.length; |
| 93 for (int i = 0; i < len; i++) { |
| 94 if (this.codeUnitAt(i) != other.codeUnitAt(i)) { |
| 95 return false; |
| 96 } |
| 97 } |
| 98 return true; |
| 93 } | 99 } |
| 94 | 100 |
| 101 |
| 95 int compareTo(String other) { | 102 int compareTo(String other) { |
| 96 int thisLength = this.length; | 103 int thisLength = this.length; |
| 97 int otherLength = other.length; | 104 int otherLength = other.length; |
| 98 int len = (thisLength < otherLength) ? thisLength : otherLength; | 105 int len = (thisLength < otherLength) ? thisLength : otherLength; |
| 99 for (int i = 0; i < len; i++) { | 106 for (int i = 0; i < len; i++) { |
| 100 int thisCodePoint = this.codeUnitAt(i); | 107 int thisCodePoint = this.codeUnitAt(i); |
| 101 int otherCodePoint = other.codeUnitAt(i); | 108 int otherCodePoint = other.codeUnitAt(i); |
| 102 if (thisCodePoint < otherCodePoint) { | 109 if (thisCodePoint < otherCodePoint) { |
| 103 return -1; | 110 return -1; |
| 104 } | 111 } |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 throw new UnsupportedError( | 523 throw new UnsupportedError( |
| 517 "_OneByteString can only be allocated by the VM"); | 524 "_OneByteString can only be allocated by the VM"); |
| 518 } | 525 } |
| 519 | 526 |
| 520 int get hashCode native "String_getHashCode"; | 527 int get hashCode native "String_getHashCode"; |
| 521 | 528 |
| 522 bool _isWhitespace(int codePoint) { | 529 bool _isWhitespace(int codePoint) { |
| 523 return _StringBase._isOneByteWhitespace(codePoint); | 530 return _StringBase._isOneByteWhitespace(codePoint); |
| 524 } | 531 } |
| 525 | 532 |
| 533 bool operator ==(Object other) { |
| 534 return super == other; |
| 535 } |
| 536 |
| 526 String _substringUncheckedNative(int startIndex, int endIndex) | 537 String _substringUncheckedNative(int startIndex, int endIndex) |
| 527 native "OneByteString_substringUnchecked"; | 538 native "OneByteString_substringUnchecked"; |
| 528 | 539 |
| 529 List<String> _splitWithCharCode(int charCode) | 540 List<String> _splitWithCharCode(int charCode) |
| 530 native "OneByteString_splitWithCharCode"; | 541 native "OneByteString_splitWithCharCode"; |
| 531 | 542 |
| 532 List<String> split(Pattern pattern) { | 543 List<String> split(Pattern pattern) { |
| 533 if ((pattern._cid == _OneByteString._classId) && (pattern.length == 1)) { | 544 if ((pattern._cid == _OneByteString._classId) && (pattern.length == 1)) { |
| 534 return _splitWithCharCode(pattern.codeUnitAt(0)); | 545 return _splitWithCharCode(pattern.codeUnitAt(0)); |
| 535 } | 546 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 579 |
| 569 class _TwoByteString extends _StringBase implements String { | 580 class _TwoByteString extends _StringBase implements String { |
| 570 factory _TwoByteString._uninstantiable() { | 581 factory _TwoByteString._uninstantiable() { |
| 571 throw new UnsupportedError( | 582 throw new UnsupportedError( |
| 572 "_TwoByteString can only be allocated by the VM"); | 583 "_TwoByteString can only be allocated by the VM"); |
| 573 } | 584 } |
| 574 | 585 |
| 575 bool _isWhitespace(int codePoint) { | 586 bool _isWhitespace(int codePoint) { |
| 576 return _StringBase._isTwoByteWhitespace(codePoint); | 587 return _StringBase._isTwoByteWhitespace(codePoint); |
| 577 } | 588 } |
| 589 |
| 590 bool operator ==(Object other) { |
| 591 return super == other; |
| 592 } |
| 578 } | 593 } |
| 579 | 594 |
| 580 | 595 |
| 581 class _ExternalOneByteString extends _StringBase implements String { | 596 class _ExternalOneByteString extends _StringBase implements String { |
| 582 factory _ExternalOneByteString._uninstantiable() { | 597 factory _ExternalOneByteString._uninstantiable() { |
| 583 throw new UnsupportedError( | 598 throw new UnsupportedError( |
| 584 "_ExternalOneByteString can only be allocated by the VM"); | 599 "_ExternalOneByteString can only be allocated by the VM"); |
| 585 } | 600 } |
| 586 | 601 |
| 587 bool _isWhitespace(int codePoint) { | 602 bool _isWhitespace(int codePoint) { |
| 588 return _StringBase._isOneByteWhitespace(codePoint); | 603 return _StringBase._isOneByteWhitespace(codePoint); |
| 589 } | 604 } |
| 605 |
| 606 bool operator ==(Object other) { |
| 607 return super == other; |
| 608 } |
| 590 } | 609 } |
| 591 | 610 |
| 592 | 611 |
| 593 class _ExternalTwoByteString extends _StringBase implements String { | 612 class _ExternalTwoByteString extends _StringBase implements String { |
| 594 factory _ExternalTwoByteString._uninstantiable() { | 613 factory _ExternalTwoByteString._uninstantiable() { |
| 595 throw new UnsupportedError( | 614 throw new UnsupportedError( |
| 596 "_ExternalTwoByteString can only be allocated by the VM"); | 615 "_ExternalTwoByteString can only be allocated by the VM"); |
| 597 } | 616 } |
| 598 | 617 |
| 599 bool _isWhitespace(int codePoint) { | 618 bool _isWhitespace(int codePoint) { |
| 600 return _StringBase._isTwoByteWhitespace(codePoint); | 619 return _StringBase._isTwoByteWhitespace(codePoint); |
| 601 } | 620 } |
| 621 |
| 622 bool operator ==(Object other) { |
| 623 return super == other; |
| 624 } |
| 602 } | 625 } |
| 603 | 626 |
| 604 | 627 |
| 605 class _StringMatch implements Match { | 628 class _StringMatch implements Match { |
| 606 const _StringMatch(int this.start, | 629 const _StringMatch(int this.start, |
| 607 String this.input, | 630 String this.input, |
| 608 String this.pattern); | 631 String this.pattern); |
| 609 | 632 |
| 610 int get end => start + pattern.length; | 633 int get end => start + pattern.length; |
| 611 String operator[](int g) => group(g); | 634 String operator[](int g) => group(g); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 637 class _CodeUnits extends Object with ListMixin<int>, | 660 class _CodeUnits extends Object with ListMixin<int>, |
| 638 UnmodifiableListMixin<int> { | 661 UnmodifiableListMixin<int> { |
| 639 /** The string that this is the code units of. */ | 662 /** The string that this is the code units of. */ |
| 640 String _string; | 663 String _string; |
| 641 | 664 |
| 642 _CodeUnits(this._string); | 665 _CodeUnits(this._string); |
| 643 | 666 |
| 644 int get length => _string.length; | 667 int get length => _string.length; |
| 645 int operator[](int i) => _string.codeUnitAt(i); | 668 int operator[](int i) => _string.codeUnitAt(i); |
| 646 } | 669 } |
| OLD | NEW |