Skip to content

Remove str::is_whitespace and str::is_alphanumeric #49657

Closed

Description

@dtolnay

These methods were added as stable in #49381 (currently in beta for 1.27.0) but we would prefer not to add them as discussed in #49381 (comment).

Activity

  1. withoutboats commented on Apr 4, 2018

    @withoutboats
    Contributor

    Strongly prefer to have this method (unsurprisngly). I assumed it was an oversight that it was missing; I've probably tried s.is_whitespace() a half dozen times and then been surprised it was nightly only.

  2. oli-obk commented on Apr 5, 2018

    @oli-obk
    Contributor

    We could add a system to be able to add suggestions to missing method errors. Thus the use of is_whitespace would suggest .chars().all(char::is_whitespace)

    Deleting these methods should of course not be blocked on such a system being in place

  3. LukasKalbertodt commented on Apr 5, 2018

    @LukasKalbertodt
    Contributor

    @oli-obk I like this idea a lot! (independently from this discussion)


    About is_alphanumeric: I think I prefer to remove str::is_alphanumeric as it might lead to subtle Unicode bugs. Example:

    println!("{}", "böb".chars().all(char::is_alphanumeric));    // true
    println!("{}", "böb".chars().all(char::is_alphanumeric));    // false

    The second string uses a Combining Diaeresis with an o instead of an ö. Sure, the explicit variant chars().all(...) also has this problem, but being explicit makes the bug a bit less subtle. Having is_alphanumeric on a string might suggest that the method "does the right thing" (whatever that is) instead of looking at characters individually.


    I think str::is_whitespace doesn't have a problem with subtle Unicode bugs, but I don't quite like the name: is_whitespace sounds singular to me and thus doesn't translate perfectly to a string.

    If you are interested, I did a bit of research how .chars().all(char::is_whitespace) is called in other languages (sometimes with libraries):

    Maybe str::is_blank is a better name for Rust?

  4. added this to the 1.26 milestone on Apr 5, 2018
  5. added a commit that references this issue on Apr 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-api[DEPRECATED; DO NOT USE]regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions