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
johnno1962
wants to merge
6
commits into
apple:main
Choose a base branch
from
johnno1962:character-ops
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
johnno1962
force-pushed
the
character-ops
branch
from
February 20, 2024 08:33
0f5ed97
to
9d65d6e
Compare
johnno1962
force-pushed
the
character-ops
branch
from
February 20, 2024 13:56
9d65d6e
to
ef0b101
Compare
glessard
reviewed
Feb 20, 2024
Co-authored-by: Guillaume Lessard <glessard@users.noreply.github.com>
Co-authored-by: James Dempsey <dempsey@tapas-software.net>
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. |
Sure thing. I've added a couple of use cases, in a switch and in an an if. |
johnno1962
force-pushed
the
character-ops
branch
from
February 21, 2024 02:30
4169415
to
ad705b2
Compare
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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