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

Side by Side Diff: sdk/lib/_internal/compiler/js_lib/js_string.dart

Issue 949753005: Add String.replaceRange and use it in replaceFirst{,Mapped}. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 5 years, 10 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 part of _interceptors; 5 part of _interceptors;
6 6
7 /** 7 /**
8 * The interceptor class for [String]. The compiler recognizes this 8 * The interceptor class for [String]. The compiler recognizes this
9 * class as an interceptor, and changes references to [:this:] to 9 * class as an interceptor, and changes references to [:this:] to
10 * actually use the receiver of the method, which is generated as an extra 10 * actually use the receiver of the method, which is generated as an extra
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (pattern is String) { 90 if (pattern is String) {
91 return JS('JSExtendableArray', r'#.split(#)', this, pattern); 91 return JS('JSExtendableArray', r'#.split(#)', this, pattern);
92 } else if (pattern is JSSyntaxRegExp && regExpCaptureCount(pattern) == 0) { 92 } else if (pattern is JSSyntaxRegExp && regExpCaptureCount(pattern) == 0) {
93 var re = regExpGetNative(pattern); 93 var re = regExpGetNative(pattern);
94 return JS('JSExtendableArray', r'#.split(#)', this, re); 94 return JS('JSExtendableArray', r'#.split(#)', this, re);
95 } else { 95 } else {
96 return _defaultSplit(pattern); 96 return _defaultSplit(pattern);
97 } 97 }
98 } 98 }
99 99
100 String replaceRange(int start, int end, String replacement) {
101 checkString(replacement);
102 checkInt(start);
103 end = RangeError.checkValidRange(start, end, this.length);
104 checkInt(end);
105 return stringReplaceRangeUnchecked(this, start, end, replacement);
106 }
107
100 List<String> _defaultSplit(Pattern pattern) { 108 List<String> _defaultSplit(Pattern pattern) {
101 List<String> result = <String>[]; 109 List<String> result = <String>[];
102 // End of most recent match. That is, start of next part to add to result. 110 // End of most recent match. That is, start of next part to add to result.
103 int start = 0; 111 int start = 0;
104 // Length of most recent match. 112 // Length of most recent match.
105 // Set >0, so no match on the empty string causes the result to be [""]. 113 // Set >0, so no match on the empty string causes the result to be [""].
106 int length = 1; 114 int length = 1;
107 for (var match in pattern.allMatches(this)) { 115 for (var match in pattern.allMatches(this)) {
108 int matchStart = match.start; 116 int matchStart = match.start;
109 int matchEnd = match.end; 117 int matchEnd = match.end;
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 Type get runtimeType => String; 463 Type get runtimeType => String;
456 464
457 int get length => JS('int', r'#.length', this); 465 int get length => JS('int', r'#.length', this);
458 466
459 String operator [](int index) { 467 String operator [](int index) {
460 if (index is !int) throw new ArgumentError(index); 468 if (index is !int) throw new ArgumentError(index);
461 if (index >= length || index < 0) throw new RangeError.value(index); 469 if (index >= length || index < 0) throw new RangeError.value(index);
462 return JS('String', '#[#]', this, index); 470 return JS('String', '#[#]', this, index);
463 } 471 }
464 } 472 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/interceptors.dart ('k') | sdk/lib/_internal/compiler/js_lib/string_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698