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

Side by Side Diff: dart/frog/leg/lib/string_helper.dart

Issue 9852018: Minor tweaks to the core library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add types Created 8 years, 9 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 class StringMatch implements Match { 5 class StringMatch implements Match {
6 const StringMatch(int this._start, 6 const StringMatch(int this._start,
7 String this.str, 7 String this.str,
8 String this.pattern); 8 String this.pattern);
9 9
10 int start() => _start; 10 int start() => _start;
(...skipping 14 matching lines...) Expand all
25 result.add(group(g)); 25 result.add(group(g));
26 } 26 }
27 return result; 27 return result;
28 } 28 }
29 29
30 final int _start; 30 final int _start;
31 final String str; 31 final String str;
32 final String pattern; 32 final String pattern;
33 } 33 }
34 34
35 allMatchesInStringUnchecked(receiver, str) { 35 List<Match> allMatchesInStringUnchecked(String needle, String haystack) {
36 var result = new List(); 36 // Copied from StringBase.allMatches in
37 var length = receiver.length; 37 // ../../../runtime/lib/string.dart
38 if (length === 0) { 38 List<Match> result = new List<Match>();
39 return result; 39 int length = haystack.length;
40 } 40 int patternLength = needle.length;
41 41 int startIndex = 0;
42 var strLength = str.length; 42 while (true) {
43 for (var i = 0; i < strLength;) { 43 int position = haystack.indexOf(needle, startIndex);
44 var index = str.indexOf(receiver, i); 44 if (position == -1) {
45 if (index < 0) { 45 break;
46 return result;
47 } 46 }
48 result.add(new StringMatch(index, str, receiver)); 47 result.add(new StringMatch(position, haystack, needle));
49 i = index + length; 48 int endIndex = position + patternLength;
49 if (endIndex == length) {
50 break;
51 } else if (position == endIndex) {
52 ++startIndex; // empty match, advance and restart
53 } else {
54 startIndex = endIndex;
55 }
50 } 56 }
51 return result; 57 return result;
52 } 58 }
53 59
54 stringContainsUnchecked(receiver, other, startIndex) { 60 stringContainsUnchecked(receiver, other, startIndex) {
55 if (other is String) { 61 if (other is String) {
56 return receiver.indexOf(other, startIndex) !== -1; 62 return receiver.indexOf(other, startIndex) !== -1;
57 } else if (other is JSSyntaxRegExp) { 63 } else if (other is JSSyntaxRegExp) {
58 return other.hasMatch(receiver.substring(startIndex)); 64 return other.hasMatch(receiver.substring(startIndex));
59 } else { 65 } else {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 stringSplitUnchecked(receiver, pattern) { 118 stringSplitUnchecked(receiver, pattern) {
113 if (pattern is String) { 119 if (pattern is String) {
114 return JS('List', @'#.split(#)', receiver, pattern); 120 return JS('List', @'#.split(#)', receiver, pattern);
115 } else if (pattern is JSSyntaxRegExp) { 121 } else if (pattern is JSSyntaxRegExp) {
116 var re = regExpGetNative(pattern); 122 var re = regExpGetNative(pattern);
117 return JS('List', @'#.split(#)', receiver, re); 123 return JS('List', @'#.split(#)', receiver, re);
118 } else { 124 } else {
119 throw "StringImplementation.split(Pattern) UNIMPLEMENTED"; 125 throw "StringImplementation.split(Pattern) UNIMPLEMENTED";
120 } 126 }
121 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698