Skip to content

Multiple() implementation #2

Open

Description

@metal3d

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

Activity

  1. psoholt commented on Aug 10, 2013

    @psoholt
    Member

    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?

  2. metal3d commented on Aug 10, 2013

    @metal3d
    MemberAuthor

    Absolutly right :)
    Le 10 août 2013 22:13, "Peder Søholt" notifications@github.com 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//issues/2#issuecomment-22446495
    .

  3. metal3d commented on Aug 10, 2013

    @metal3d
    MemberAuthor

    I have to think about it. Let me some minutes
    Le 10 août 2013 22:13, "Peder Søholt" notifications@github.com 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//issues/2#issuecomment-22446495
    .

  4. metal3d commented on Aug 10, 2013

    @metal3d
    MemberAuthor

    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 ?

  5. psoholt commented on Aug 11, 2013

    @psoholt
    Member

    👍 I agree :)

  6. metal3d commented on Aug 12, 2013

    @metal3d
    MemberAuthor

    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 ?

  7. SignpostMarv commented on Jan 16, 2016

    @SignpostMarv

    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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions