Fix UTF-16 indexing for emoji characters in code storage - #140
Merged
Conversation
Contributor
Author
|
oops! I accidentally deleted the branch, which closed the PR 🙈 |
Owner
|
Great catch! Thanks a lot and happy to hear that the library is helpful 😀 (Just curious: what kind of app are you building if you don't mind me asking?) |
|
Can you please tag this? I think this fixes a crash that occurs when adding a newline close to the end of the editor. As for me, I'm using this to present an editor for ABNF, and show syntax errors and shadowed rule names and the like. |
Owner
|
@awwright Yes, you are right. I was pushing this out for too long. I just released 0.16.0.
Nice! |
This file contains hidden or 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
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.
Pressing Enter at the end of a document containing emoji characters (e.g., "flag: 🏁 fumble") causes a crash with "String index is out of bounds" in tokenCompletion(for:at:).
The index parameter is a UTF-16 offset (from NSRange), but the code was treating it as a Character offset: string.utf16[string.index(string.startIndex, offsetBy: index)]
Emojis like 🏁 are 1 Character but 2 UTF-16 code units, causing the index to exceed the string's character count.
I ran into this while building an app with your amazing library, thanks for your work!