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

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

Issue 15333006: Rewrite double.parse. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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
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 in the Zl category:
212 // U+0020 SPACE
213 // U+00A0 NO-BREAK SPACE
214 // U+1680 OGHAM SPACE MARK
215 // U+180E MONGOLIAN VOWEL SEPARATOR
216 // U+2000 EN QUAD
217 // U+2001 EM QUAD
218 // U+2002 EN SPACE
219 // U+2003 EM SPACE
220 // U+2004 THREE-PER-EM SPACE
221 // U+2005 FOUR-PER-EM SPACE
222 // U+2006 SIX-PER-EM SPACE
223 // U+2007 FIGURE SPACE
224 // U+2008 PUNCTUATION SPACE
225 // U+2009 THIN SPACE
226 // U+200A HAIR SPACE
227 // U+202F NARROW NO-BREAK SPACE
228 // U+205F MEDIUM MATHEMATICAL SPACE
229 // U+3000 IDEOGRAPHIC SPACE
230 //
231 // Characters in the Zl category: 0x2028
232 // Characters in the Zp category: 0x2029
233 // BOM: 0xFEFF
234 static bool _isTwoByteWhitespace(int codePoint) {
235 if (codePoint < 256) return _isOneByteWhitespace(codePoint);
236 return (codePoint == 0x1680) ||
237 (codePoint == 0x180E) ||
238 ((0x2000 <= codePoint) && (codePoint <= 0x200A)) ||
239 (codePoint == 0x202F) ||
240 (codePoint == 0x205F) ||
241 (codePoint == 0x3000) ||
242 (codePoint == 0x2028) ||
243 (codePoint == 0x2029) ||
244 (codePoint == 0xFEFF);
209 } 245 }
210 246
211 String trim() { 247 String trim() {
212 final int len = this.length; 248 final int len = this.length;
213 int first = 0; 249 int first = 0;
214 for (; first < len; first++) { 250 for (; first < len; first++) {
215 if (!_isWhitespace(this.codeUnitAt(first))) { 251 if (!_isWhitespace(this.codeUnitAt(first))) {
216 break; 252 break;
217 } 253 }
218 } 254 }
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 } 602 }
567 603
568 604
569 class _TwoByteString extends _StringBase implements String { 605 class _TwoByteString extends _StringBase implements String {
570 factory _TwoByteString._uninstantiable() { 606 factory _TwoByteString._uninstantiable() {
571 throw new UnsupportedError( 607 throw new UnsupportedError(
572 "_TwoByteString can only be allocated by the VM"); 608 "_TwoByteString can only be allocated by the VM");
573 } 609 }
574 610
575 bool _isWhitespace(int codePoint) { 611 bool _isWhitespace(int codePoint) {
576 // For now we only check for one byte white space characters. 612 return _StringBase._isTwoByteWhitespace(codePoint);
577 return _StringBase._isOneByteWhitespace(codePoint);
578 } 613 }
579 } 614 }
580 615
581 616
582 class _ExternalOneByteString extends _StringBase implements String { 617 class _ExternalOneByteString extends _StringBase implements String {
583 factory _ExternalOneByteString._uninstantiable() { 618 factory _ExternalOneByteString._uninstantiable() {
584 throw new UnsupportedError( 619 throw new UnsupportedError(
585 "_ExternalOneByteString can only be allocated by the VM"); 620 "_ExternalOneByteString can only be allocated by the VM");
586 } 621 }
587 622
588 bool _isWhitespace(int codePoint) { 623 bool _isWhitespace(int codePoint) {
589 return _StringBase._isOneByteWhitespace(codePoint); 624 return _StringBase._isOneByteWhitespace(codePoint);
590 } 625 }
591 } 626 }
592 627
593 628
594 class _ExternalTwoByteString extends _StringBase implements String { 629 class _ExternalTwoByteString extends _StringBase implements String {
595 factory _ExternalTwoByteString._uninstantiable() { 630 factory _ExternalTwoByteString._uninstantiable() {
596 throw new UnsupportedError( 631 throw new UnsupportedError(
597 "_ExternalTwoByteString can only be allocated by the VM"); 632 "_ExternalTwoByteString can only be allocated by the VM");
598 } 633 }
599 634
600 bool _isWhitespace(int codePoint) { 635 bool _isWhitespace(int codePoint) {
601 // For now we only check for one byte white space characters. 636 return _StringBase._isTwoByteWhitespace(codePoint);
602 return _StringBase._isOneByteWhitespace(codePoint);
603 } 637 }
604 } 638 }
605 639
606 640
607 class _StringMatch implements Match { 641 class _StringMatch implements Match {
608 const _StringMatch(int this.start, 642 const _StringMatch(int this.start,
609 String this.str, 643 String this.str,
610 String this.pattern); 644 String this.pattern);
611 645
612 int get end => start + pattern.length; 646 int get end => start + pattern.length;
(...skipping 26 matching lines...) Expand all
639 class _CodeUnits extends Object with ListMixin<int>, 673 class _CodeUnits extends Object with ListMixin<int>,
640 UnmodifiableListMixin<int> { 674 UnmodifiableListMixin<int> {
641 /** The string that this is the code units of. */ 675 /** The string that this is the code units of. */
642 String _string; 676 String _string;
643 677
644 _CodeUnits(this._string); 678 _CodeUnits(this._string);
645 679
646 int get length => _string.length; 680 int get length => _string.length;
647 int operator[](int i) => _string.codeUnitAt(i); 681 int operator[](int i) => _string.codeUnitAt(i);
648 } 682 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698