Skip to content

proposal: strings: provide ContainsOnly function #46385

Closed

Description

strings package has ContainsAny. I have seen many package implement thier ContainsOnly. Although it takes just a few line of code, it would be nice to have it in strings package.

Activity

  1. added this to the Proposal milestone on May 26, 2021
  2. mvdan commented on May 26, 2021

    @mvdan
    Member

    This proposal lacks detail. What is a ContainsOnly? Can you share links to those "many packages" that implement their own? How does it compare to ContainsAny?

  3. added
    WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
    on May 26, 2021
  4. removed
    WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
    on May 26, 2021
  5. changed the title [-]Proposal: strings: provide ContainsOnly function[/-] [+]proposal: strings: provide ContainsOnly function[/+] on May 26, 2021
  6. ianlancetaylor commented on May 26, 2021

    @ianlancetaylor
    Contributor

    I think this could be written as strings.Trim(s, chars) == "".

    Does this really come up often enough to deserve its own function? Can you point to some existing code that would be simpler if this function were available? Thanks.

  7. rsc commented on Jun 9, 2021

    @rsc
    Contributor

    This proposal has been added to the active column of the proposals project
    and will now be reviewed at the weekly proposal review meetings.
    — rsc for the proposal review group

  8. earthboundkid commented on Jun 9, 2021

    @earthboundkid
    Contributor

    This comes up, e.g., to test that all characters in an email address are valid, but I think that doing an O(n m) loop is wrong when you can use a lookup map instead.

  9. icholy commented on Jun 9, 2021

    @icholy
    Contributor

    @carlmjohnson for small char strings, the O(n m) version might be faster.

  10. rsc commented on Jun 16, 2021

    @rsc
    Contributor

    The downside of using ContainsOnly for testing a character set is that the character set is very large. Passing "abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789" and making the function figure out how to do that seems much worse (and less efficient) than just writing 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c && c <= '9'. It's also much harder to read. Did you notice the missing I in the string?

    It's even worse if Unicode is involved.

    It doesn't seem like we have a compelling use case here.

  11. rsc commented on Jul 14, 2021

    @rsc
    Contributor

    Based on the discussion above, this proposal seems like a likely decline.
    — rsc for the proposal review group

  12. rsc commented on Jul 21, 2021

    @rsc
    Contributor

    No change in consensus, so declined.
    — rsc for the proposal review group

  13. locked and limited conversation to collaborators on Jul 21, 2022
  14. moved this to Declined in Proposalson Aug 10, 2022
  15. removed this from Proposalson Oct 19, 2022
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions