| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 function native_StringImplementation__indexOperator(index) { | |
| 6 "use strict"; | |
| 7 return this[index]; | |
| 8 } | |
| 9 | |
| 10 function native_StringImplementation__charCodeAt(index) { | |
| 11 "use strict"; | |
| 12 return this.charCodeAt(index); | |
| 13 } | |
| 14 | |
| 15 function native_StringImplementation_get$length() { | |
| 16 "use strict"; | |
| 17 return this.length; | |
| 18 } | |
| 19 | |
| 20 function native_StringImplementation_EQ(other) { | |
| 21 // TODO(kasperl): We should really try to avoid having wrapped | |
| 22 // strings floating around. The usually stem from referencing [this] | |
| 23 // in Dart methods patched onto the String.prototype object. | |
| 24 | |
| 25 // Because of the checks in EQ$operator, we know [this] is a string | |
| 26 // wrapper, but we have to make sure that [other] is either a | |
| 27 // wrapper or a proper string before we can use == to compare the | |
| 28 // contents. | |
| 29 return (typeof(other) == 'string' || other.constructor === String) | |
| 30 ? this == other | |
| 31 : false; | |
| 32 } | |
| 33 | |
| 34 function native_StringImplementation__nativeIndexOf(other, startIndex) { | |
| 35 "use strict"; | |
| 36 return this.indexOf(other, startIndex); | |
| 37 } | |
| 38 | |
| 39 function native_StringImplementation__nativeLastIndexOf(other, fromIndex) { | |
| 40 "use strict"; | |
| 41 if (other == "") { | |
| 42 return Math.min(this.length, fromIndex); | |
| 43 } | |
| 44 return this.lastIndexOf(other, fromIndex); | |
| 45 } | |
| 46 | |
| 47 function native_StringImplementation_concat(other) { | |
| 48 "use strict"; | |
| 49 return this.concat(other); | |
| 50 } | |
| 51 | |
| 52 function native_StringImplementation__substringUnchecked(startIndex, endIndex) { | |
| 53 "use strict"; | |
| 54 return this.substring(startIndex, endIndex); | |
| 55 } | |
| 56 | |
| 57 function native_StringImplementation_trim() { | |
| 58 "use strict"; | |
| 59 if (this.trim) return this.trim(); | |
| 60 return this.replace(new RegExp("^[\s]+|[\s]+$", "g"), ""); | |
| 61 } | |
| 62 | |
| 63 function native_StringImplementation__replace(from, to) { | |
| 64 "use strict"; | |
| 65 if ($isString(from)) { | |
| 66 return this.replace(from, to); | |
| 67 } else { | |
| 68 return this.replace($DartRegExpToJSRegExp(from), to); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 function native_StringImplementation__replaceAll(from, to) { | |
| 73 "use strict"; | |
| 74 if ($isString(from)) { | |
| 75 var regexp = new RegExp( | |
| 76 from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g'); | |
| 77 return this.replace(regexp, to); | |
| 78 } else { | |
| 79 var regexp = $DartRegExpToJSRegExp(from); | |
| 80 return this.replace(regexp, to); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 function native_StringImplementation__split(pattern) { | |
| 85 "use strict"; | |
| 86 if ($isString(pattern)) { | |
| 87 return this.split(pattern); | |
| 88 } else { | |
| 89 return this.split($DartRegExpToJSRegExp(pattern)); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 function native_StringImplementation_toLowerCase() { | |
| 94 "use strict"; | |
| 95 return this.toLowerCase(); | |
| 96 } | |
| 97 | |
| 98 function native_StringImplementation_toUpperCase() { | |
| 99 "use strict"; | |
| 100 return this.toUpperCase(); | |
| 101 } | |
| 102 | |
| 103 // Inherited from Hashable. | |
| 104 function native_StringImplementation_hashCode() { | |
| 105 "use strict"; | |
| 106 var hash = 0; | |
| 107 for (var i = 0; i < this.length; i++) { | |
| 108 var ch = this.charCodeAt(i); | |
| 109 hash += ch; | |
| 110 hash += hash << 10; | |
| 111 hash ^= hash >> 6; | |
| 112 } | |
| 113 | |
| 114 hash += hash << 3; | |
| 115 hash ^= hash >> 11; | |
| 116 hash += hash << 15; | |
| 117 hash = hash & ((1 << 29) - 1); | |
| 118 | |
| 119 return hash; | |
| 120 } | |
| 121 | |
| 122 function native_StringImplementation_toString() { | |
| 123 "use strict"; | |
| 124 // Return the primitive string of this String object. | |
| 125 return String(this); | |
| 126 } | |
| 127 | |
| 128 // TODO(floitsch): If we allow comparison operators on the String class we | |
| 129 // should move this function into dart world. | |
| 130 function native_StringImplementation_compareTo(other) { | |
| 131 "use strict"; | |
| 132 if (this == other) return 0; | |
| 133 if (this < other) return -1; | |
| 134 return 1; | |
| 135 } | |
| 136 | |
| 137 function native_StringImplementation__newFromValues(array) { | |
| 138 "use strict"; | |
| 139 if (!(array instanceof Array)) { | |
| 140 var length = native__ListJsUtil__listLength(array); | |
| 141 var tmp = new Array(length); | |
| 142 for (var i = 0; i < length; i++) { | |
| 143 tmp[i] = INDEX$operator(array, i); | |
| 144 } | |
| 145 array = tmp; | |
| 146 } | |
| 147 return String.fromCharCode.apply(this, array); | |
| 148 } | |
| 149 | |
| 150 // Deprecated old name of new String.fromValues(..). | |
| 151 function native_StringBase_createFromCharCodes(array) { | |
| 152 return native_StringImplementation__newFromValues(array); | |
| 153 } | |
| OLD | NEW |