Fix lua-objc mapping to handle high/low surrogate pairs in hs.styledtext - #3356
Merged
Conversation
stickler-ci
reviewed
Jan 13, 2023
Member
|
@asmagill I'm not going to pretend to understand all the unicode stuff - are you happy for this to merge? |
Member
Author
|
I left in a debugging function that I originally had commented out... it's undocumented, but might be helpful if someone does find a specific case where this fails, so I'm inclined to leave it as is. If you don't mind the undocumented function being left in, then yes, I think this is ready to be merged -- it hasn't broken anything on my setup and passed every test I've thought to come up with at it... Though to be fair, I don't think a set of comprehensive unicode tests that covers absolutely all use cases exists... sometimes I feel like they make it up as they go! 😁 |
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.
Addresses issues in #3219
Completely rewrites lua-objc index mapping to properly handle UTF16 High/Low surrogate pairs
UTF8 (which Lua uses) can have Unicode characters of 1-4 bytes
UTF16 (which Objective-C/Swift use) are always 2 bytes, but for Unicode characters above U+10000 inclusive, 2 UTF16 characters (i.e. 4 bytes) are used.
This code assumes that no 1-byte UTF8 character can be a surrogate member... as far as I can tell this is a safe assumption, but I haven't found an explicit statement to that effect, so if anyone knows otherwise, please chime in.