Ticket #7822: string-start-end.patch
| File string-start-end.patch, 1.2 kB (added by altblue, 1 year ago) |
|---|
-
test/unit/string.html
old new 342 342 assert('hello world'.startsWith('hello')); 343 343 assert(!'hello world'.startsWith('bye')); 344 344 assert(!''.startsWith('bye')); 345 assert(!'hell'.startsWith('hello')); 345 346 }}, 346 347 347 348 testEndsWith: function() {with(this) { … … 350 351 assert(!'hello world'.endsWith('planet')); 351 352 assert(!''.endsWith('planet')); 352 353 assert('hello world world'.endsWith(' world')); 354 assert(!'z'.endsWith('az')); 353 355 }}, 354 356 355 357 testBlank: function() { with(this) { -
src/string.js
old new 176 176 }, 177 177 178 178 startsWith: function(pattern) { 179 return this.indexOf(pattern) == 0;179 return this.indexOf(pattern) === 0; 180 180 }, 181 181 182 182 endsWith: function(pattern) { 183 return this.lastIndexOf(pattern) == (this.length - pattern.length); 183 var d = this.length - pattern.length; 184 return d >= 0 && this.lastIndexOf(pattern) === d; 184 185 }, 185 186 186 187 empty: function() {