-
Notifications
You must be signed in to change notification settings - Fork 159
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
Incorrect or inconsistent behavior with sπ‘ πβ method #208
Comments
joeskeen
changed the title
Incorrect or inconsistent behavior with sπ’ πβ method
Incorrect or inconsistent behavior with sπ‘ πβ method
Nov 27, 2022
joeskeen
added a commit
to joeskeen/emojicode
that referenced
this issue
Nov 27, 2022
sπ‘ πβ now returns grapheme index instead of UTF-8 index
I agree, this is very inconsistent and should be corrected. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider the following unit tests:
All these tests should pass, but this is the output:
From this message, it is apparent that the sπ‘ πβ method is returning the index in terms of UTF-8 bytes, not grapheme index. This is inconsistent with the sπ‘ πͺβmethod, which is using grapheme index (as shown in the tests).
This inconsistency makes the sπ‘ πβmethod confusing at best and useless at the worst case when strings are outside of the ASCII range.
Ideally the workaround for this issue would be to first convert the string into a list via sπ‘ πΆβ, then find the index with sπ¨ πβ, but unfortunately that does not exist. I intend to submit a pull request for that method shortly.Edit: you can't implement πβ on sπ¨πβͺπ since you can't compare two βͺs with π or anything else, and you can't cast the βͺ to protocol π since it's generic π’. Looks like the only way to do this is fix the sπ‘πβ method.
The text was updated successfully, but these errors were encountered: