Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: runtime/lib/string_patch.dart

Issue 15339002: Reuse _isOneByteWhitespace in all the classes for implementing _isWhitespace. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 192 }
193 if ((startIndex + 1) == endIndex) { 193 if ((startIndex + 1) == endIndex) {
194 return this[startIndex]; 194 return this[startIndex];
195 } 195 }
196 return _substringUncheckedNative(startIndex, endIndex); 196 return _substringUncheckedNative(startIndex, endIndex);
197 } 197 }
198 198
199 String _substringUncheckedNative(int startIndex, int endIndex) 199 String _substringUncheckedNative(int startIndex, int endIndex)
200 native "StringBase_substringUnchecked"; 200 native "StringBase_substringUnchecked";
201 201
202 // Checks for one-byte whitespaces only.
203 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
204 // whitespaces for one byte strings.
205 static bool _isOneByteWhitespace(int codePoint) {
206 return
207 (codePoint == 32) || // Space.
208 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
209 }
210
202 String trim() { 211 String trim() {
203 final int len = this.length; 212 final int len = this.length;
204 int first = 0; 213 int first = 0;
205 for (; first < len; first++) { 214 for (; first < len; first++) {
206 if (!_isWhitespace(this.codeUnitAt(first))) { 215 if (!_isWhitespace(this.codeUnitAt(first))) {
207 break; 216 break;
208 } 217 }
209 } 218 }
210 if (len == first) { 219 if (len == first) {
211 // String contains only whitespaces. 220 // String contains only whitespaces.
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 class _OneByteString extends _StringBase implements String { 512 class _OneByteString extends _StringBase implements String {
504 static final int _classId = "A"._cid; 513 static final int _classId = "A"._cid;
505 514
506 factory _OneByteString._uninstantiable() { 515 factory _OneByteString._uninstantiable() {
507 throw new UnsupportedError( 516 throw new UnsupportedError(
508 "_OneByteString can only be allocated by the VM"); 517 "_OneByteString can only be allocated by the VM");
509 } 518 }
510 519
511 int get hashCode native "String_getHashCode"; 520 int get hashCode native "String_getHashCode";
512 521
513 // Checks for one-byte whitespaces only.
514 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
515 // whitespaces for one byte strings.
516 bool _isWhitespace(int codePoint) { 522 bool _isWhitespace(int codePoint) {
517 return 523 return _StringBase._isOneByteWhitespace(codePoint);
518 (codePoint == 32) || // Space.
519 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
520 } 524 }
521 525
522 String _substringUncheckedNative(int startIndex, int endIndex) 526 String _substringUncheckedNative(int startIndex, int endIndex)
523 native "OneByteString_substringUnchecked"; 527 native "OneByteString_substringUnchecked";
524 528
525 List<String> _splitWithCharCode(int charCode) 529 List<String> _splitWithCharCode(int charCode)
526 native "OneByteString_splitWithCharCode"; 530 native "OneByteString_splitWithCharCode";
527 531
528 List<String> split(Pattern pattern) { 532 List<String> split(Pattern pattern) {
529 if ((pattern._cid == _OneByteString._classId) && (pattern.length == 1)) { 533 if ((pattern._cid == _OneByteString._classId) && (pattern.length == 1)) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 void _setAt(int index, int codePoint) native "OneByteString_setAt"; 565 void _setAt(int index, int codePoint) native "OneByteString_setAt";
562 } 566 }
563 567
564 568
565 class _TwoByteString extends _StringBase implements String { 569 class _TwoByteString extends _StringBase implements String {
566 factory _TwoByteString._uninstantiable() { 570 factory _TwoByteString._uninstantiable() {
567 throw new UnsupportedError( 571 throw new UnsupportedError(
568 "_TwoByteString can only be allocated by the VM"); 572 "_TwoByteString can only be allocated by the VM");
569 } 573 }
570 574
571 // Checks for one-byte whitespaces only.
572 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
573 // whitespaces. Add checking for multi-byte whitespace codepoints.
574 bool _isWhitespace(int codePoint) { 575 bool _isWhitespace(int codePoint) {
575 return 576 // For now we only check for one byte white space characters.
576 (codePoint == 32) || // Space. 577 return _StringBase._isOneByteWhitespace(codePoint);
577 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
578 } 578 }
579 } 579 }
580 580
581 581
582 class _ExternalOneByteString extends _StringBase implements String { 582 class _ExternalOneByteString extends _StringBase implements String {
583 factory _ExternalOneByteString._uninstantiable() { 583 factory _ExternalOneByteString._uninstantiable() {
584 throw new UnsupportedError( 584 throw new UnsupportedError(
585 "_ExternalOneByteString can only be allocated by the VM"); 585 "_ExternalOneByteString can only be allocated by the VM");
586 } 586 }
587 587
588 // Checks for one-byte whitespaces only.
589 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
590 // whitespaces for one byte strings.
591 bool _isWhitespace(int codePoint) { 588 bool _isWhitespace(int codePoint) {
592 return 589 return _StringBase._isOneByteWhitespace(codePoint);
593 (codePoint == 32) || // Space.
594 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
595 } 590 }
596 } 591 }
597 592
598 593
599 class _ExternalTwoByteString extends _StringBase implements String { 594 class _ExternalTwoByteString extends _StringBase implements String {
600 factory _ExternalTwoByteString._uninstantiable() { 595 factory _ExternalTwoByteString._uninstantiable() {
601 throw new UnsupportedError( 596 throw new UnsupportedError(
602 "_ExternalTwoByteString can only be allocated by the VM"); 597 "_ExternalTwoByteString can only be allocated by the VM");
603 } 598 }
604 599
605 // Checks for one-byte whitespaces only. 600 // Checks for one-byte whitespaces only.
606 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid 601 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
607 // whitespaces. Add checking for multi-byte whitespace codepoints. 602 // whitespaces. Add checking for multi-byte whitespace codepoints.
608 bool _isWhitespace(int codePoint) { 603 bool _isWhitespace(int codePoint) {
609 return 604 // For now we only check for one byte white space characters.
610 (codePoint == 32) || // Space. 605 return _StringBase._isOneByteWhitespace(codePoint);
611 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
612 } 606 }
613 } 607 }
614 608
615 609
616 class _StringMatch implements Match { 610 class _StringMatch implements Match {
617 const _StringMatch(int this.start, 611 const _StringMatch(int this.start,
618 String this.str, 612 String this.str,
619 String this.pattern); 613 String this.pattern);
620 614
621 int get end => start + pattern.length; 615 int get end => start + pattern.length;
(...skipping 26 matching lines...) Expand all
648 class _CodeUnits extends Object with ListMixin<int>, 642 class _CodeUnits extends Object with ListMixin<int>,
649 UnmodifiableListMixin<int> { 643 UnmodifiableListMixin<int> {
650 /** The string that this is the code units of. */ 644 /** The string that this is the code units of. */
651 String _string; 645 String _string;
652 646
653 _CodeUnits(this._string); 647 _CodeUnits(this._string);
654 648
655 int get length => _string.length; 649 int get length => _string.length;
656 int operator[](int i) => _string.codeUnitAt(i); 650 int operator[](int i) => _string.codeUnitAt(i);
657 } 651 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698