| 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 part of _js_helper; | 5 part of _js_helper; |
| 6 | 6 |
| 7 class StringMatch implements Match { | 7 class StringMatch implements Match { |
| 8 const StringMatch(int this.start, | 8 const StringMatch(int this.start, |
| 9 String this.str, | 9 String this.str, |
| 10 String this.pattern); | 10 String this.pattern); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 138 |
| 139 stringReplaceAllEmptyFuncUnchecked(receiver, onMatch, onNonMatch) { | 139 stringReplaceAllEmptyFuncUnchecked(receiver, onMatch, onNonMatch) { |
| 140 // Pattern is the empty string. | 140 // Pattern is the empty string. |
| 141 StringBuffer buffer = new StringBuffer(); | 141 StringBuffer buffer = new StringBuffer(); |
| 142 int length = receiver.length; | 142 int length = receiver.length; |
| 143 int i = 0; | 143 int i = 0; |
| 144 buffer.add(onNonMatch("")); | 144 buffer.add(onNonMatch("")); |
| 145 while (i < length) { | 145 while (i < length) { |
| 146 buffer.add(onMatch(new StringMatch(i, receiver, ""))); | 146 buffer.add(onMatch(new StringMatch(i, receiver, ""))); |
| 147 // Special case to avoid splitting a surrogate pair. | 147 // Special case to avoid splitting a surrogate pair. |
| 148 int code = receiver.charCodeAt(i); | 148 int code = receiver.codeUnitAt(i); |
| 149 if ((code & ~0x3FF) == 0xD800 && length > i + 1) { | 149 if ((code & ~0x3FF) == 0xD800 && length > i + 1) { |
| 150 // Leading surrogate; | 150 // Leading surrogate; |
| 151 code = receiver.charCodeAt(i + 1); | 151 code = receiver.codeUnitAt(i + 1); |
| 152 if ((code & ~0x3FF) == 0xDC00) { | 152 if ((code & ~0x3FF) == 0xDC00) { |
| 153 // Matching trailing surrogate. | 153 // Matching trailing surrogate. |
| 154 buffer.add(onNonMatch(receiver.substring(i, i + 2))); | 154 buffer.add(onNonMatch(receiver.substring(i, i + 2))); |
| 155 i += 2; | 155 i += 2; |
| 156 continue; | 156 continue; |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 buffer.add(onNonMatch(receiver[i])); | 159 buffer.add(onNonMatch(receiver[i])); |
| 160 i++; | 160 i++; |
| 161 } | 161 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } else { | 195 } else { |
| 196 checkNull(from); | 196 checkNull(from); |
| 197 // TODO(floitsch): implement generic String.replace (with patterns). | 197 // TODO(floitsch): implement generic String.replace (with patterns). |
| 198 throw "String.replace(Pattern) UNIMPLEMENTED"; | 198 throw "String.replace(Pattern) UNIMPLEMENTED"; |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 stringJoinUnchecked(array, separator) { | 202 stringJoinUnchecked(array, separator) { |
| 203 return JS('String', r'#.join(#)', array, separator); | 203 return JS('String', r'#.join(#)', array, separator); |
| 204 } | 204 } |
| OLD | NEW |