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: sdk/lib/_internal/compiler/implementation/lib/js_string.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 24 matching lines...) Expand all
35 int otherLength = other.length; 35 int otherLength = other.length;
36 if (otherLength > length) return false; 36 if (otherLength > length) return false;
37 return other == substring(length - otherLength); 37 return other == substring(length - otherLength);
38 } 38 }
39 39
40 String replaceAll(Pattern from, String to) { 40 String replaceAll(Pattern from, String to) {
41 checkString(to); 41 checkString(to);
42 return stringReplaceAllUnchecked(this, from, to); 42 return stringReplaceAllUnchecked(this, from, to);
43 } 43 }
44 44
45 String replaceAllMapped(Pattern from, String convert(Match match)) {
46 return this.splitMapJoin(from, onMatch: convert);
47 }
48
49 String splitMapJoin(Pattern from,
50 {String onMatch(Match match),
51 String onNonMatch(String nonMatch)}) {
52 return stringReplaceAllFuncUnchecked(this, from, onMatch, onNonMatch);
53 }
54
45 String replaceFirst(Pattern from, String to) { 55 String replaceFirst(Pattern from, String to) {
46 checkString(to); 56 checkString(to);
47 return stringReplaceFirstUnchecked(this, from, to); 57 return stringReplaceFirstUnchecked(this, from, to);
48 } 58 }
49 59
50 List<String> split(Pattern pattern) { 60 List<String> split(Pattern pattern) {
51 checkNull(pattern); 61 checkNull(pattern);
52 if (pattern is String) { 62 if (pattern is String) {
53 return JS('=List', r'#.split(#)', this, pattern); 63 return JS('=List', r'#.split(#)', this, pattern);
54 } else if (pattern is JSSyntaxRegExp) { 64 } else if (pattern is JSSyntaxRegExp) {
(...skipping 19 matching lines...) Expand all
74 String substring(int startIndex, [int endIndex]) { 84 String substring(int startIndex, [int endIndex]) {
75 checkNum(startIndex); 85 checkNum(startIndex);
76 if (endIndex == null) endIndex = length; 86 if (endIndex == null) endIndex = length;
77 checkNum(endIndex); 87 checkNum(endIndex);
78 if (startIndex < 0 ) throw new RangeError.value(startIndex); 88 if (startIndex < 0 ) throw new RangeError.value(startIndex);
79 if (startIndex > endIndex) throw new RangeError.value(startIndex); 89 if (startIndex > endIndex) throw new RangeError.value(startIndex);
80 if (endIndex > length) throw new RangeError.value(endIndex); 90 if (endIndex > length) throw new RangeError.value(endIndex);
81 return JS('String', r'#.substring(#, #)', this, startIndex, endIndex); 91 return JS('String', r'#.substring(#, #)', this, startIndex, endIndex);
82 } 92 }
83 93
94 String slice([int startIndex, int endIndex]) {
95 int start, end;
96 if (startIndex == null) {
97 start = 0;
98 } else if (startIndex is! int) {
99 throw new ArgumentError("startIndex is not int");
100 } else if (startIndex >= 0) {
101 start = startIndex;
102 } else {
103 start = this.length + startIndex;
104 }
105 if (start < 0 || start > this.length) {
106 throw new RangeError(
107 "startIndex out of range: $startIndex (length: $length)");
108 }
109 if (endIndex == null) {
110 end = this.length;
111 } else if (endIndex is! int) {
112 throw new ArgumentError("endIndex is not int");
113 } else if (endIndex >= 0) {
114 end = endIndex;
115 } else {
116 end = this.length + endIndex;
117 }
118 if (end < 0 || end > this.length) {
119 throw new RangeError(
120 "endIndex out of range: $endIndex (length: $length)");
121 }
122 if (end < start) {
123 throw new ArgumentError(
124 "End before start: $endIndex < $startIndex (length: $length)");
125 }
126 return JS('String', '#.substring(#, #)', this, start, end);
127 }
128
129
84 String toLowerCase() { 130 String toLowerCase() {
85 return JS('String', r'#.toLowerCase()', this); 131 return JS('String', r'#.toLowerCase()', this);
86 } 132 }
87 133
88 String toUpperCase() { 134 String toUpperCase() {
89 return JS('String', r'#.toUpperCase()', this); 135 return JS('String', r'#.toUpperCase()', this);
90 } 136 }
91 137
92 String trim() { 138 String trim() {
93 return JS('String', r'#.trim()', this); 139 return JS('String', r'#.trim()', this);
94 } 140 }
95 141
96 List<int> get charCodes { 142 List<int> get charCodes {
97 List<int> result = new List<int>(length); 143 List<int> result = new List<int>.fixedLength(length);
98 for (int i = 0; i < length; i++) { 144 for (int i = 0; i < length; i++) {
99 result[i] = JS('int', '#.charCodeAt(#)', this, i); 145 result[i] = JS('int', '#.charCodeAt(#)', this, i);
100 } 146 }
101 return result; 147 return result;
102 } 148 }
103 149
104 int indexOf(String other, [int start = 0]) { 150 int indexOf(String other, [int start = 0]) {
105 checkNull(other); 151 checkNull(other);
106 if (start is !int) throw new ArgumentError(start); 152 if (start is !int) throw new ArgumentError(start);
107 if (other is !String) throw new ArgumentError(other); 153 if (other is !String) throw new ArgumentError(other);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 Type get runtimeType => String; 209 Type get runtimeType => String;
164 210
165 int get length => JS('int', r'#.length', this); 211 int get length => JS('int', r'#.length', this);
166 212
167 String operator [](int index) { 213 String operator [](int index) {
168 if (index is !int) throw new ArgumentError(index); 214 if (index is !int) throw new ArgumentError(index);
169 if (index >= length || index < 0) throw new RangeError.value(index); 215 if (index >= length || index < 0) throw new RangeError.value(index);
170 return JS('String', '#[#]', this, index); 216 return JS('String', '#[#]', this, index);
171 } 217 }
172 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698