| OLD | NEW |
| 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 //String.prototype.get$length = function() { | 5 //String.prototype.get$length = function() { |
| 6 // return this.length; | 6 // return this.length; |
| 7 //} | 7 //} |
| 8 | 8 |
| 9 // TODO(jimhug): Unify with code from compiler/lib/implementation. | 9 // TODO(jimhug): Unify with code from compiler/lib/implementation. |
| 10 class StringImplementation implements String native "String" { | 10 class StringImplementation implements String native "String" { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 var lastMatchEnd = 0; | 72 var lastMatchEnd = 0; |
| 73 for (var match in from.allMatches(this)) { | 73 for (var match in from.allMatches(this)) { |
| 74 buffer.add(substring(lastMatchEnd, match.start())); | 74 buffer.add(substring(lastMatchEnd, match.start())); |
| 75 buffer.add(to); | 75 buffer.add(to); |
| 76 lastMatchEnd = match.end(); | 76 lastMatchEnd = match.end(); |
| 77 } | 77 } |
| 78 buffer.add(substring(lastMatchEnd)); | 78 buffer.add(substring(lastMatchEnd)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // TODO(jimhug): Get correct reified generic list here. | 81 // TODO(jimhug): Get correct reified generic list here. |
| 82 List<String> split(Pattern pattern) native { | 82 List<String> split(Pattern pattern) { |
| 83 return []; // tell the compiler an array is created | 83 if (pattern is String) return _split(pattern); |
| 84 if (pattern is RegExp) return _splitRegExp(pattern); |
| 85 throw "String.split(Pattern) unimplemented."; |
| 84 } | 86 } |
| 85 | 87 |
| 88 List<String> _split(String pattern) native |
| 89 "'use strict'; return this.split(pattern);"; |
| 90 |
| 91 List<String> _splitRegExp(RegExp pattern) native |
| 92 "'use strict'; return this.split(pattern.re);"; |
| 93 |
| 86 /* | 94 /* |
| 87 Iterable<Match> allMatches(String str) { | 95 Iterable<Match> allMatches(String str) { |
| 88 List<Match> result = []; | 96 List<Match> result = []; |
| 89 if (this.isEmpty()) return result; | 97 if (this.isEmpty()) return result; |
| 90 int length = this.length; | 98 int length = this.length; |
| 91 | 99 |
| 92 int ix = 0; | 100 int ix = 0; |
| 93 while (ix < str.length) { | 101 while (ix < str.length) { |
| 94 int foundIx = str.indexOf(this, ix); | 102 int foundIx = str.indexOf(this, ix); |
| 95 if (foundIx < 0) break; | 103 if (foundIx < 0) break; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 result.add(group(g)); | 172 result.add(group(g)); |
| 165 } | 173 } |
| 166 return result; | 174 return result; |
| 167 } | 175 } |
| 168 | 176 |
| 169 final int _start; | 177 final int _start; |
| 170 final String str; | 178 final String str; |
| 171 final String pattern; | 179 final String pattern; |
| 172 } | 180 } |
| 173 */ | 181 */ |
| OLD | NEW |