Case insensitive String startsWith, contains, endsWith, replaceAll method
ecmascript at lindenbergsoftware.com
Sun Feb 17 21:24:01 PST 2013
Actually, it's not just case that users want to ignore. In many use cases, users search for something "similar" to their search string, and the definition of "similar" can vary substantially. For example, an English speaker typically wants "San Jose" to also match "San José", especially when he doesn't know how to type accented characters. For a French speaker, on the other hand, "ne" and "né" are distinct words. Japanese speakers sometimes want to treat all of "あ", "ぁ", "ア", "ｱ", and "ｧ" as similar, or even better, have "たなか" match "田中" based on pronunciation. And in pretty much all cases you want to apply Unicode normalization.
For use cases where you want to select a subset of a list of strings based on similarity, Collator objects from the ECMAScript Internationalization API can be used, with the usage option set to "search". But for the use cases you're primarily concerned about, new API will be needed. Since this is all language and context sensitive, the ECMAScript Language Specification is probably not the right place to define this API.
On Feb 16, 2013, at 15:58 , Biju wrote:
> 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?
> And to make it case sensitive we should add a third flag parameter matchCase
> 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.
> (Again with insensitive search by default.)
> String.replace is not helping, as it default to case sensitive and a
> one time operation, if the first parameter is not a regular
> We could also add String.replaceFirst and String.replaceLast method.
> If we dont want change behavior of String.startsWith, String.contains,
> String.endsWith to case insensitive.
> Can we have another set methods probably named
> String.startsWithI, String.containsI, String.endsWithI
> (where "I" stands for ignore/insensitive case)
> es-discuss mailing list
> es-discuss at mozilla.org
More information about the es-discuss