Multiple() implementation
As I did on JS implementation, I recreate the issue there to discuss about "multiple" function.
Some implementation return the given value with "+", other give "{2,}"
To my side, for Go, I developped a method that have this implementation:
multiple(string value, int min, int max)
where:
- min is the minimum number of occurence to get
- maw is the maximum number of occurence to get
both argument are, IMHO, not required, default should be considered as doing "value?"
This is how I did:
// get "foo" at least one time
v.Multiple("foo")
v.Multiple("foo", 1)
// get "foo" 0 or more times
v.Multiple("foo", 0)
//get "foo" 0 or 1 times
v.Multiple("foo", 0, 1)
// get "foo" 0 to 10 times
v.Multiple("foo",0 ,10)
//get "foo" at least 10 times
v.Multiple("foo", 10)
//get "foo" exactly 10 times
v.Multiple("foo", 10, 10)
//get "foo" from 1 to 10 times
v.Multiple("foo", 1, 10)
Discussion is opened
Good idea. But the default by calling v.Multiple("foo") I think should maybe be "0 or more times" or "1 or more times". It's in the name, multiple should be multiple times, otherwise one could use v.Then("foo") ? What do you think?
Absolutly right :) Le 10 août 2013 22:13, "Peder Søholt" [email protected] a écrit :
Good idea. But the default by calling v.Multiple("foo") I think should maybe be "0 or more times" or "1 or more times". It's in the name, multiple should be multiple times, otherwise one could use v.Then("foo") ? What do you think?
— Reply to this email directly or view it on GitHubhttps://github.com/VerbalExpressions/implementation/issues/2#issuecomment-22446495 .
I have to think about it. Let me some minutes Le 10 août 2013 22:13, "Peder Søholt" [email protected] a écrit :
Good idea. But the default by calling v.Multiple("foo") I think should maybe be "0 or more times" or "1 or more times". It's in the name, multiple should be multiple times, otherwise one could use v.Then("foo") ? What do you think?
— Reply to this email directly or view it on GitHubhttps://github.com/VerbalExpressions/implementation/issues/2#issuecomment-22446495 .
Ok, I have thought about. I really think Multiply("foo") is "1 or more time"
It is normal that some methods can be the same as Something, Any, Find... because in regexp basics, this exists.
(foo)? == (foo){0,1}
(foo)* == (foo){0,}
(foo)+ == (foo){1,}
"Multiply" method is a "common" method that can be parametric... Instead of testing wich verb to use, a developper can use "Multiply" to set a "variable" minimal number of occurence to fetch.
Without any "min" value, "Multiply" is (IMHO) at least 1 time, so (again IMHO):
Multiple("foo") == Multiple("foo", 1)
Am I wrong ?
:+1: I agree :)
Ok, I did all the work on Go implementation + unittest that covers 100%. But, as I said, my "multiple" method implements what I exposed on this discussion...
Please, others managers, can you vote and tell if you agree with this, and can you implement this ?
I added some tests on the PHP & JS implementations for verifying the output of regex->startOfLine()->range(0, 9, 'a', 'z', 'A', 'Z')->multiple('')
The JS implementation spits out '/^[0-9a-zA-Z](?:)*/gm', the PHP implementation spits out '/^[0-9a-zA-Z]+/m'
Without any min value, if we're assuming Multiple('foo') == Multiple('foo', 1), wouldn't the most correct test be the PHP version ?