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 /** | |
6 * Extend the String prototype with members expected in dart. | |
7 */ | |
8 | |
9 String.$instanceOf = function(obj) { | |
10 return typeof obj == 'string' || obj instanceof String; | |
11 }; | |
12 | |
13 function native_StringImplementation__indexOperator(index) { | 5 function native_StringImplementation__indexOperator(index) { |
14 return this[index]; | 6 return this[index]; |
15 } | 7 } |
16 | 8 |
17 function native_StringImplementation__charCodeAt(index) { | 9 function native_StringImplementation__charCodeAt(index) { |
18 return this.charCodeAt(index); | 10 return this.charCodeAt(index); |
19 } | 11 } |
20 | 12 |
21 function native_StringImplementation_get$length() { | 13 function native_StringImplementation_get$length() { |
22 return this.length; | 14 return this.length; |
(...skipping 28 matching lines...) Expand all Loading... |
51 function native_StringImplementation__substringUnchecked(startIndex, endIndex) { | 43 function native_StringImplementation__substringUnchecked(startIndex, endIndex) { |
52 return this.substring(startIndex, endIndex); | 44 return this.substring(startIndex, endIndex); |
53 } | 45 } |
54 | 46 |
55 function native_StringImplementation_trim() { | 47 function native_StringImplementation_trim() { |
56 if (this.trim) return this.trim(); | 48 if (this.trim) return this.trim(); |
57 return this.replace(new RegExp("^[\s]+|[\s]+$", "g"), ""); | 49 return this.replace(new RegExp("^[\s]+|[\s]+$", "g"), ""); |
58 } | 50 } |
59 | 51 |
60 function native_StringImplementation__replace(from, to) { | 52 function native_StringImplementation__replace(from, to) { |
61 if (String.$instanceOf(from)) { | 53 if ($isString(from)) { |
62 return this.replace(from, to); | 54 return this.replace(from, to); |
63 } else { | 55 } else { |
64 return this.replace($DartRegExpToJSRegExp(from), to); | 56 return this.replace($DartRegExpToJSRegExp(from), to); |
65 } | 57 } |
66 } | 58 } |
67 | 59 |
68 function native_StringImplementation__replaceAll(from, to) { | 60 function native_StringImplementation__replaceAll(from, to) { |
69 if (String.$instanceOf(from)) { | 61 if ($isString(from)) { |
70 var regexp = new RegExp( | 62 var regexp = new RegExp( |
71 from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g'); | 63 from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g'); |
72 return this.replace(regexp, to); | 64 return this.replace(regexp, to); |
73 } else { | 65 } else { |
74 var regexp = $DartRegExpToJSRegExp(from); | 66 var regexp = $DartRegExpToJSRegExp(from); |
75 return this.replace(regexp, to); | 67 return this.replace(regexp, to); |
76 } | 68 } |
77 } | 69 } |
78 | 70 |
79 function native_StringImplementation__split(pattern) { | 71 function native_StringImplementation__split(pattern) { |
80 if (String.$instanceOf(pattern)) { | 72 if ($isString(pattern)) { |
81 return this.split(pattern); | 73 return this.split(pattern); |
82 } else { | 74 } else { |
83 return this.split($DartRegExpToJSRegExp(pattern)); | 75 return this.split($DartRegExpToJSRegExp(pattern)); |
84 } | 76 } |
85 } | 77 } |
86 | 78 |
87 function native_StringImplementation_toLowerCase() { | 79 function native_StringImplementation_toLowerCase() { |
88 return this.toLowerCase(); | 80 return this.toLowerCase(); |
89 } | 81 } |
90 | 82 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 124 } |
133 array = tmp; | 125 array = tmp; |
134 } | 126 } |
135 return String.fromCharCode.apply(this, array); | 127 return String.fromCharCode.apply(this, array); |
136 } | 128 } |
137 | 129 |
138 // Deprecated old name of new String.fromValues(..). | 130 // Deprecated old name of new String.fromValues(..). |
139 function native_StringBase_createFromCharCodes(array) { | 131 function native_StringBase_createFromCharCodes(array) { |
140 return native_StringImplementation__newFromValues(array); | 132 return native_StringImplementation__newFromValues(array); |
141 } | 133 } |
OLD | NEW |