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

Refactored WordRange string iteration #10

Merged
merged 19 commits into from
Jun 25, 2024
Merged

Conversation

DivineDominion
Copy link
Contributor

The word range lookup used NSString enumeration was a bit awkward to use. Its procedural nature to 'stop' and set captured variables outside of its context made it hard to follow.

During this refactoring, it turned out that, nlike NSString.rangeOfCharacter(...), enumerateSubstrings correctly handles Emoji. So it comes with a lot for free.

I couldn't get rangeOfCharacter for CharacterSet.whitespacesAndNewlines.inverted to not halt at Emoji. (Could be because some Emoji use 'joiners' which are detected as whitespace because the rangeOfCharacter method doesn't respect composed character sequences?)

I could get a custom character iterator to work, though.

@DivineDominion
Copy link
Contributor Author

In 05d10ed I reverted the custom loop to use enumerateSubstrings again, but limited to this 1 place, to use 1st part code that maybe contains additional optimizations.

@DivineDominion DivineDominion merged commit 64ac8c0 into main Jun 25, 2024
1 check passed
@DivineDominion DivineDominion deleted the string-iteration branch June 25, 2024 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant