| 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 class StringImplementation implements String native "String" { | 5 class StringImplementation implements String native "String" { |
| 6 factory StringImplementation.fromValues(List<int> values) { | 6 factory StringImplementation.fromValues(List<int> values) { |
| 7 return _newFromValues(values); | 7 return _newFromValues(values); |
| 8 } | 8 } |
| 9 | 9 |
| 10 String operator[](int index) { | 10 String operator[](int index) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool endsWith(String other) { | 42 bool endsWith(String other) { |
| 43 return substringMatches(length - other.length, other); | 43 return substringMatches(length - other.length, other); |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool startsWith(String other) { | 46 bool startsWith(String other) { |
| 47 return substringMatches(0, other); | 47 return substringMatches(0, other); |
| 48 } | 48 } |
| 49 | 49 |
| 50 int indexOf(String other, int startIndex) native; | 50 int indexOf(String other, [int start = 0]) { |
| 51 int lastIndexOf(String other, int fromIndex) native; | 51 return _nativeIndexOf(other, start); |
| 52 } |
| 53 |
| 54 int lastIndexOf(String other, [int start = null]) { |
| 55 if (start === null) start = length - 1; |
| 56 return _nativeLastIndexOf(other, start); |
| 57 } |
| 58 |
| 59 int _nativeIndexOf(String other, int start) native; |
| 60 int _nativeLastIndexOf(String other, int start) native; |
| 52 | 61 |
| 53 bool isEmpty() { | 62 bool isEmpty() { |
| 54 return length == 0; | 63 return length == 0; |
| 55 } | 64 } |
| 56 | 65 |
| 57 String concat(String other) native; | 66 String concat(String other) native; |
| 58 | 67 |
| 59 String operator +(Object obj) { | 68 String operator +(Object obj) { |
| 60 return this.concat(obj.toString()); | 69 return this.concat(obj.toString()); |
| 61 } | 70 } |
| 62 | 71 |
| 63 String substring(int startIndex, [int endIndex = null]) { | 72 String substring(int startIndex, [int endIndex = null]) { |
| 64 if (endIndex == null) endIndex = this.length; | 73 if (endIndex == null) endIndex = this.length; |
| 65 | 74 |
| 66 if ((startIndex < 0) || (startIndex > this.length)) { | 75 if ((startIndex < 0) || (startIndex > this.length)) { |
| 67 throw new IndexOutOfRangeException(startIndex); | 76 throw new IndexOutOfRangeException(startIndex); |
| 68 } | 77 } |
| 69 if ((endIndex < 0) || (endIndex > this.length)) { | 78 if ((endIndex < 0) || (endIndex > this.length)) { |
| 70 throw new IndexOutOfRangeException(endIndex); | 79 throw new IndexOutOfRangeException(endIndex); |
| 71 } | 80 } |
| 72 if (startIndex > endIndex) { | 81 if (startIndex > endIndex) { |
| 73 throw new IndexOutOfRangeException(startIndex); | 82 throw new IndexOutOfRangeException(startIndex); |
| 74 } | 83 } |
| 75 return _substringUnchecked(startIndex, endIndex); | 84 return _substringUnchecked(startIndex, endIndex); |
| 76 } | 85 } |
| 77 | 86 |
| 78 String trim() native; | 87 String trim() native; |
| 79 | 88 |
| 80 bool contains(Pattern pattern, int startIndex) { | 89 bool contains(Pattern pattern, [int startIndex = 0]) { |
| 81 if (startIndex == null) startIndex = 0; | |
| 82 if (startIndex < 0 || startIndex > length) { | 90 if (startIndex < 0 || startIndex > length) { |
| 83 throw new IndexOutOfRangeException(startIndex); | 91 throw new IndexOutOfRangeException(startIndex); |
| 84 } | 92 } |
| 85 if (pattern is String) { | 93 if (pattern is String) { |
| 86 return this.indexOf(pattern, startIndex) != -1; | 94 return this.indexOf(pattern, startIndex) != -1; |
| 87 } else if (pattern is JSSyntaxRegExp) { | 95 } else if (pattern is JSSyntaxRegExp) { |
| 88 JSSyntaxRegExp regExp = pattern; | 96 JSSyntaxRegExp regExp = pattern; |
| 89 return regExp.hasMatch(_substringUnchecked(startIndex, length)); | 97 return regExp.hasMatch(_substringUnchecked(startIndex, length)); |
| 90 } else { | 98 } else { |
| 91 String substr = _substringUnchecked(startIndex, length); | 99 String substr = _substringUnchecked(startIndex, length); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 for (int g in groups) { | 226 for (int g in groups) { |
| 219 result.add(group(g)); | 227 result.add(group(g)); |
| 220 } | 228 } |
| 221 return result; | 229 return result; |
| 222 } | 230 } |
| 223 | 231 |
| 224 final int _start; | 232 final int _start; |
| 225 final String str; | 233 final String str; |
| 226 final String pattern; | 234 final String pattern; |
| 227 } | 235 } |
| OLD | NEW |