Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operators for UInt8 comparisons to unicode scalars #2329

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

johnno1962
Copy link
Contributor

@johnno1962 johnno1962 commented Feb 20, 2024

Hi Apple,

After a long deliberation on swift-evolution I'd like to propose these operators and initialisers be added to the standard library to improve the ergonomics of working with the integer representation of character values. This has already be explored and benchmarked extensively on apple/swift-syntax#2439 to the swift-syntax project which was merged some weeks ago. I've tried to pair it down to the absolute minimum so there shouldn't be anything too contentious in what remains. In summary you can compare a UInt8 value to a double quoted single unicode code point string literal for equality, make this comparison in a switch. There is also a new initialiser for all integer types from a unicode scalar and finally a new Array initialiser from the unicode scalars in a String.

These operators use the existing language to improve the ergonomics of parser code without having to press into service single quotes and make changes to the compiler as has been previously proposed.

Resolves #SR-9032, PR with implementation here

johnno1962 and others added 2 commits February 20, 2024 18:40
Co-authored-by: Guillaume Lessard <glessard@users.noreply.github.com>
Co-authored-by: James Dempsey <dempsey@tapas-software.net>
@dempseyatgithub
Copy link
Contributor

Would it be possible to provide a few before / after code examples in the proposal that show the improved ergonomics? Even if they are simple examples, I think they would make the value of the proposal instantly clear.

@johnno1962
Copy link
Contributor Author

Sure thing. I've added a couple of use cases, in a switch and in an an if.

@rjmccall rjmccall added the LSG Contains topics under the domain of the Language Steering Group label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LSG Contains topics under the domain of the Language Steering Group
Projects
None yet
4 participants