Re: Case insensitive String startsWith, contains, endsWith, replaceAll method

2013-02-18 Thread Biju
On 18 February 2013 01:24, Norbert Lindenberg
ecmascr...@lindenbergsoftware.com wrote:
 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.

Biju: I could accept that argumnet


 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.


Biju: Then let me redefine my request. Instead of Ignore case, match
text by what ever satisfying i flag for RegExp  defined in ECMA
script/the browser/user agent. Dont tell me now there is nothing
defined for i flag.

Also nothing above is stopping standardization of mozilla non-standard
flags parameter for String.replace as standard.
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace#Syntax

Cheers
Biju
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Case insensitive String startsWith, contains, endsWith, replaceAll method

2013-02-18 Thread Claude Pache

Le 18 févr. 2013 à 00:56, Biju bijumaill...@gmail.com a écrit :

 On 16 February 2013 20:26, David Bruant bruan...@gmail.com wrote:
 Le 17/02/2013 00:58, Biju a écrit :
 
 Also, it doesn't seem that hard to implement:
String.prototype.startsWithI = function(s){
this.match(new RegExp('^'+s, 'i'));
}
 
 you also made the common error any developer make
 (I am ignoring you have missed the return keyword)
 If people at es-discuss can make error,
 how can you expect an average IT developer get it right.
 
 test this
 
 s=fddfd(ghgg
 new RegExp('^'+s, 'i')
 
 Error!!!
 

Indeed (and I am surprised that David made such an error). The following 
implementation is more robust:

String.prototype.startsWithI = function(s) {
this.toLowerCase().startsWith(s.toLowerCase())
}

This approach will work for many, but not all, string functions.


 
 And sometimes, case-sensitive is what you want.
 i agree, that is why I mentioned to add matchCase parameter.
 or have startsWithI, containsI, endsWithI instead
 
 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.
 
 Again you are missing the point that the first parameter of replace
 at many times have to be a variable with a value which was taken from
 user input.

If there were a RegExp.escape function that escapes all characters in a string 
that have significance in a regular expression, you could write:

str.replace(new RegExp(RegExp.escape(searchString), 'ig'), replacement)

But sadly, such a function does not exist in EcmaScript, unless I missed it. 
Perhaps the following convenience function could be added:

RegExp.escape = function(string) {
return string.replace(/([(){}\[\].+*?|\\])/g, '\\$1')
}

(or: String.prototype.regExpEscape ?) 

—Claude

 
 
 We you cant agree on replaceAll can we atleast bring mozilla
 non-standard flags parameter for String.replace as standard.
 https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace#Syntax
 
 You can see a lot of people asking for replace all occurrences
 https://www.google.com/search?q=javascript+replace+all+occurrences
 
 cheers
 Biju
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Case insensitive String startsWith, contains, endsWith, replaceAll method

2013-02-17 Thread Biju
On 16 February 2013 20:26, David Bruant bruan...@gmail.com wrote:
 Le 17/02/2013 00:58, Biju a écrit :

 Also, it doesn't seem that hard to implement:
 String.prototype.startsWithI = function(s){
 this.match(new RegExp('^'+s, 'i'));
 }

you also made the common error any developer make
(I am ignoring you have missed the return keyword)
If people at es-discuss can make error,
how can you expect an average IT developer get it right.

test this

s=fddfd(ghgg
new RegExp('^'+s, 'i')

Error!!!


 And sometimes, case-sensitive is what you want.
i agree, that is why I mentioned to add matchCase parameter.
or have startsWithI, containsI, endsWithI instead

 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.

Again you are missing the point that the first parameter of replace
at many times have to be a variable with a value which was taken from
user input.


We you cant agree on replaceAll can we atleast bring mozilla
non-standard flags parameter for String.replace as standard.
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace#Syntax

You can see a lot of people asking for replace all occurrences
https://www.google.com/search?q=javascript+replace+all+occurrences

cheers
Biju
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Case insensitive String startsWith, contains, endsWith, replaceAll method

2013-02-17 Thread Norbert Lindenberg
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.

Norbert


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
 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.
 (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
 expression.
 
 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)
 
 Cheers
 Biju
 
 
 http://wiki.ecmascript.org/doku.php?id=harmony:string_extras
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Case insensitive String startsWith, contains, endsWith, replaceAll method

2013-02-16 Thread David Bruant

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.

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.


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.


David
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Case insensitive String startsWith, contains, endsWith, replaceAll method

2013-02-16 Thread Rick Waldron
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-discusshttps://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss