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 const int _maxAscii = 0x7f; | 5 const int _maxAscii = 0x7f; |
6 const int _maxLatin1 = 0xff; | 6 const int _maxLatin1 = 0xff; |
7 const int _maxUtf16 = 0xffff; | 7 const int _maxUtf16 = 0xffff; |
8 const int _maxUnicode = 0x10ffff; | 8 const int _maxUnicode = 0x10ffff; |
9 | 9 |
10 patch class String { | 10 patch class String { |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 } | 889 } |
890 int length = this.length; | 890 int length = this.length; |
891 Iterator iterator = pattern.allMatches(this).iterator; | 891 Iterator iterator = pattern.allMatches(this).iterator; |
892 if (length == 0 && iterator.moveNext()) { | 892 if (length == 0 && iterator.moveNext()) { |
893 // A matched empty string input returns the empty list. | 893 // A matched empty string input returns the empty list. |
894 return <String>[]; | 894 return <String>[]; |
895 } | 895 } |
896 List<String> result = new List<String>(); | 896 List<String> result = new List<String>(); |
897 int startIndex = 0; | 897 int startIndex = 0; |
898 int previousIndex = 0; | 898 int previousIndex = 0; |
| 899 // 'pattern' may not be implemented correctly and therefore we cannot |
| 900 // call _substringUnhchecked unless it is a trustworthy type (e.g. String). |
899 while (true) { | 901 while (true) { |
900 if (startIndex == length || !iterator.moveNext()) { | 902 if (startIndex == length || !iterator.moveNext()) { |
901 result.add(this._substringUnchecked(previousIndex, length)); | 903 result.add(this.substring(previousIndex, length)); |
902 break; | 904 break; |
903 } | 905 } |
904 Match match = iterator.current; | 906 Match match = iterator.current; |
905 if (match.start == length) { | 907 if (match.start == length) { |
906 result.add(this._substringUnchecked(previousIndex, length)); | 908 result.add(this.substring(previousIndex, length)); |
907 break; | 909 break; |
908 } | 910 } |
909 int endIndex = match.end; | 911 int endIndex = match.end; |
910 if (startIndex == endIndex && endIndex == previousIndex) { | 912 if (startIndex == endIndex && endIndex == previousIndex) { |
911 ++startIndex; // empty match, advance and restart | 913 ++startIndex; // empty match, advance and restart |
912 continue; | 914 continue; |
913 } | 915 } |
914 result.add(this._substringUnchecked(previousIndex, match.start)); | 916 result.add(this.substring(previousIndex, match.start)); |
915 startIndex = previousIndex = endIndex; | 917 startIndex = previousIndex = endIndex; |
916 } | 918 } |
917 return result; | 919 return result; |
918 } | 920 } |
919 | 921 |
920 List<int> get codeUnits => new CodeUnits(this); | 922 List<int> get codeUnits => new CodeUnits(this); |
921 | 923 |
922 Runes get runes => new Runes(this); | 924 Runes get runes => new Runes(this); |
923 | 925 |
924 String toUpperCase() native "String_toUpperCase"; | 926 String toUpperCase() native "String_toUpperCase"; |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 for (int g in groups) { | 1316 for (int g in groups) { |
1315 result.add(group(g)); | 1317 result.add(group(g)); |
1316 } | 1318 } |
1317 return result; | 1319 return result; |
1318 } | 1320 } |
1319 | 1321 |
1320 final int start; | 1322 final int start; |
1321 final String input; | 1323 final String input; |
1322 final String pattern; | 1324 final String pattern; |
1323 } | 1325 } |
OLD | NEW |