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

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

Issue 15348003: Fix string.trim (adding more runes). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update comment with whitespace property. 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 | sdk/lib/core/string.dart » ('j') | 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 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) { 203 static bool _isOneByteWhitespace(int codePoint) {
206 return 204 return
207 (codePoint == 32) || // Space. 205 (codePoint == 32) || // Space.
208 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. 206 ((9 <= codePoint) && (codePoint <= 13)) || // CR, LF, TAB, etc.
207 (codePoint == 0x85) || // NEL
208 (codePoint == 0xA0); // NBSP
209 }
210
211 // Characters with Whitespace property (Unicode 6.2).
212 // 0009..000D ; White_Space # Cc <control-0009>..<control-000D>
213 // 0020 ; White_Space # Zs SPACE
214 // 0085 ; White_Space # Cc <control-0085>
215 // 00A0 ; White_Space # Zs NO-BREAK SPACE
216 // 1680 ; White_Space # Zs OGHAM SPACE MARK
217 // 180E ; White_Space # Zs MONGOLIAN VOWEL SEPARATOR
218 // 2000..200A ; White_Space # Zs EN QUAD..HAIR SPACE
219 // 2028 ; White_Space # Zl LINE SEPARATOR
220 // 2029 ; White_Space # Zp PARAGRAPH SEPARATOR
221 // 202F ; White_Space # Zs NARROW NO-BREAK SPACE
222 // 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE
223 // 3000 ; White_Space # Zs IDEOGRAPHIC SPACE
224 //
225 // BOM: 0xFEFF
226 static bool _isTwoByteWhitespace(int codePoint) {
227 if (codePoint < 256) return _isOneByteWhitespace(codePoint);
228 return (codePoint == 0x1680) ||
229 (codePoint == 0x180E) ||
230 ((0x2000 <= codePoint) && (codePoint <= 0x200A)) ||
231 (codePoint == 0x2028) ||
232 (codePoint == 0x2029) ||
233 (codePoint == 0x202F) ||
234 (codePoint == 0x205F) ||
235 (codePoint == 0x3000) ||
236 (codePoint == 0xFEFF);
209 } 237 }
210 238
211 String trim() { 239 String trim() {
212 final int len = this.length; 240 final int len = this.length;
213 int first = 0; 241 int first = 0;
214 for (; first < len; first++) { 242 for (; first < len; first++) {
215 if (!_isWhitespace(this.codeUnitAt(first))) { 243 if (!_isWhitespace(this.codeUnitAt(first))) {
216 break; 244 break;
217 } 245 }
218 } 246 }
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 } 594 }
567 595
568 596
569 class _TwoByteString extends _StringBase implements String { 597 class _TwoByteString extends _StringBase implements String {
570 factory _TwoByteString._uninstantiable() { 598 factory _TwoByteString._uninstantiable() {
571 throw new UnsupportedError( 599 throw new UnsupportedError(
572 "_TwoByteString can only be allocated by the VM"); 600 "_TwoByteString can only be allocated by the VM");
573 } 601 }
574 602
575 bool _isWhitespace(int codePoint) { 603 bool _isWhitespace(int codePoint) {
576 // For now we only check for one byte white space characters. 604 return _StringBase._isTwoByteWhitespace(codePoint);
577 return _StringBase._isOneByteWhitespace(codePoint);
578 } 605 }
579 } 606 }
580 607
581 608
582 class _ExternalOneByteString extends _StringBase implements String { 609 class _ExternalOneByteString extends _StringBase implements String {
583 factory _ExternalOneByteString._uninstantiable() { 610 factory _ExternalOneByteString._uninstantiable() {
584 throw new UnsupportedError( 611 throw new UnsupportedError(
585 "_ExternalOneByteString can only be allocated by the VM"); 612 "_ExternalOneByteString can only be allocated by the VM");
586 } 613 }
587 614
588 bool _isWhitespace(int codePoint) { 615 bool _isWhitespace(int codePoint) {
589 return _StringBase._isOneByteWhitespace(codePoint); 616 return _StringBase._isOneByteWhitespace(codePoint);
590 } 617 }
591 } 618 }
592 619
593 620
594 class _ExternalTwoByteString extends _StringBase implements String { 621 class _ExternalTwoByteString extends _StringBase implements String {
595 factory _ExternalTwoByteString._uninstantiable() { 622 factory _ExternalTwoByteString._uninstantiable() {
596 throw new UnsupportedError( 623 throw new UnsupportedError(
597 "_ExternalTwoByteString can only be allocated by the VM"); 624 "_ExternalTwoByteString can only be allocated by the VM");
598 } 625 }
599 626
600 bool _isWhitespace(int codePoint) { 627 bool _isWhitespace(int codePoint) {
601 // For now we only check for one byte white space characters. 628 return _StringBase._isTwoByteWhitespace(codePoint);
602 return _StringBase._isOneByteWhitespace(codePoint);
603 } 629 }
604 } 630 }
605 631
606 632
607 class _StringMatch implements Match { 633 class _StringMatch implements Match {
608 const _StringMatch(int this.start, 634 const _StringMatch(int this.start,
609 String this.str, 635 String this.str,
610 String this.pattern); 636 String this.pattern);
611 637
612 int get end => start + pattern.length; 638 int get end => start + pattern.length;
(...skipping 26 matching lines...) Expand all
639 class _CodeUnits extends Object with ListMixin<int>, 665 class _CodeUnits extends Object with ListMixin<int>,
640 UnmodifiableListMixin<int> { 666 UnmodifiableListMixin<int> {
641 /** The string that this is the code units of. */ 667 /** The string that this is the code units of. */
642 String _string; 668 String _string;
643 669
644 _CodeUnits(this._string); 670 _CodeUnits(this._string);
645 671
646 int get length => _string.length; 672 int get length => _string.length;
647 int operator[](int i) => _string.codeUnitAt(i); 673 int operator[](int i) => _string.codeUnitAt(i);
648 } 674 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/core/string.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698