Skip to content

Add new iterators: core::str::{chars_uppercase,chars_lowercase} #58

Closed
@markokr

Description

@markokr

Proposal

Problem statement

There is no way to itererate over lowercase/uppercase chars of a &str without creating full copy of it with str::to_lowercase
or str::to_uppercase.

But there exists a bad way: str::chars with char::to_lowercase. The problem is that the latter API cannot match output of str::to_lowercase or str::to_uppercase as some Unicode conversions require context and that API cannot provide it.

Motivation, use-cases

Reason for avoiding call to str::to_lowercase() and str::to_uppercase:

  • no_std
  • performance
  • lazy operation - only few chars are needed.

Reasons to avoid char::to_uppercase and char::to_lowercase:

  • corretctness.

Solution sketches

Solution A:

  • str::chars_lowercase() -> CharsLowercase
  • str::chars_uppercase() -> CharsUppercase

Solution B:

  • char::to_lowercase_with_context(&str, usize) -> ToLowercase
  • char::to_uppercase_with_context(&str, usize) -> ToUppercase

Links and related work

PR for solution A: rust-lang/rust#98490

Metadata

Metadata

Assignees

No one assigned

    Labels

    ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions