On Saturday, February 16, 2013, David Bruant wrote: > Le 17/02/2013 00:58, Biju a écrit : > >> In most time when user want to search something in a text, he/she >> wants to do a case insensitive search. >> For example to filter items displayed in list on a page. >> Also on other applications, say any word processor, or in page search >> in Firefox, IE, Chrome etc. >> >> So can we make the default behavior of new methods String.startsWith, >> String.contains, String.endsWith case insensitive? >> > I think all current methods are case-sensitive. If these methods were to > be made case-insensitive, someone else would come on the list demanding > consistency.
Here I am, demanding consistency. The default should match the behavior of the language's comparison algorithms. > Also, it doesn't seem that hard to implement: > String.prototype.startsWithI = function(s){ > this.match(new RegExp('^'+s, 'i')); > } > > And sometimes, case-sensitive is what you want. Arguably most of the time. If I want case-insensitive, I will do the extra work for it. > And to make it case sensitive we should add a third flag parameter >> matchCase >> like... >> >> var startsWith = str.startsWith(searchString [, position [, matchCase] ] >> ); >> var contained = str.contains(searchString [, position [, matchCase] ] ); >> var endsWith = str.endsWith(searchString [, position [, matchCase] ] ); >> >> >> Additionally we should have a String.replaceAll method right now web >> developers are using complex logic to achieve the same. >> > "aA".replace(/a/ig, 'b'); // 'bb' > I feel the "i" and "g" flag or regexps aren't that complex. One just needs > to know about them. +1 I'd go so far as saying that none of these are necessary additions in the first place—conveniences at best. Rick > > David > ______________________________**_________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss> >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss