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

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

Issue 9689089: Improve the replaceFirst, replaceAll and split methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments 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
« no previous file with comments | « no previous file | runtime/lib/string.dart » ('j') | tests/corelib/src/StringPatternTest.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 JSRegExpMatch implements Match { 5 class JSRegExpMatch implements Match {
6 JSRegExpMatch(this.regexp, this.str, this._match); 6 JSRegExpMatch(this.regexp, this.str, this._match);
7 7
8 int start() { 8 int start() {
9 return _start(0); 9 return _start(0);
10 } 10 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 Match firstMatch(String str) { 58 Match firstMatch(String str) {
59 List match = _ExecuteMatch(str, 0); 59 List match = _ExecuteMatch(str, 0);
60 if (match === null) { 60 if (match === null) {
61 return null; 61 return null;
62 } 62 }
63 return new JSRegExpMatch(this, str, match); 63 return new JSRegExpMatch(this, str, match);
64 } 64 }
65 65
66 Iterable<Match> allMatches(String str) { 66 Iterable<Match> allMatches(String str) {
67 var jsregexMatches = new List<JSRegExpMatch>(); 67 List<Match> result = new List<Match>();
68 List match = _ExecuteMatch(str, 0); 68 int length = str.length;
69 if (match !== null) { 69 int startIndex = 0;
70 jsregexMatches.add(new JSRegExpMatch(this, str, match)); 70 while (true) {
71 while (true) { 71 List match = _ExecuteMatch(str, startIndex);
72 match = _ExecuteMatch(str, match[1]); 72 if (match == null) {
73 if (match === null) { 73 break;
74 break; 74 }
75 } 75 result.add(new JSRegExpMatch(this, str, match));
76 jsregexMatches.add(new JSRegExpMatch(this, str, match)); 76 int endIndex = match[1];
77 if (endIndex == length) {
78 break;
79 } else if (match[0] == endIndex) {
80 ++startIndex; // empty match, advance and restart
81 } else {
82 startIndex = endIndex;
77 } 83 }
78 } 84 }
79 return jsregexMatches; 85 return result;
80 } 86 }
81 87
82 bool hasMatch(String str) { 88 bool hasMatch(String str) {
83 List match = _ExecuteMatch(str, 0); 89 List match = _ExecuteMatch(str, 0);
84 return (match === null) ? false : true; 90 return (match === null) ? false : true;
85 } 91 }
86 92
87 String stringMatch(String str) { 93 String stringMatch(String str) {
88 List match = _ExecuteMatch(str, 0); 94 List match = _ExecuteMatch(str, 0);
89 if (match === null) { 95 if (match === null) {
90 return null; 96 return null;
91 } 97 }
92 return str.substringUnchecked_(match[0], match[1]); 98 return str.substringUnchecked_(match[0], match[1]);
93 } 99 }
94 100
95 String get pattern() native "JSSyntaxRegExp_getPattern"; 101 String get pattern() native "JSSyntaxRegExp_getPattern";
96 102
97 bool get multiLine() native "JSSyntaxRegExp_multiLine"; 103 bool get multiLine() native "JSSyntaxRegExp_multiLine";
98 104
99 bool get ignoreCase() native "JSSyntaxRegExp_ignoreCase"; 105 bool get ignoreCase() native "JSSyntaxRegExp_ignoreCase";
100 106
101 int get _groupCount() native "JSSyntaxRegExp_getGroupCount"; 107 int get _groupCount() native "JSSyntaxRegExp_getGroupCount";
102 108
103 List _ExecuteMatch(String str, int start_index) 109 List _ExecuteMatch(String str, int start_index)
104 native "JSSyntaxRegExp_ExecuteMatch"; 110 native "JSSyntaxRegExp_ExecuteMatch";
105 } 111 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/string.dart » ('j') | tests/corelib/src/StringPatternTest.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698