MacDownApp / MacDownApp/macdown
Should promise UTF-16 surrogate pairs handling
Nobody has claimed this yet.
- Dominant language
- Rich Text Format
- Stars
- 9.8k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Time to face this. After manual inspection all -characterAtIndex: calls seem to be fine, but there are at least a couple of places where string length are assumed to be equal to character count. Some examples:
- Length of a single-character string are assumed to be 1. For example,
NSMakeRange(location, 1)is used to acquire the substring range of it in a string. Should usestr.lengthinstead. -lengthis used as character count in the string. This is a problem for the word counter, for whichtrimmedDocument.lengthis used to count characters. Should use substring enumeration withNSStringEnumerationByComposedCharacterSequencesto count that manually instead.
There are likely more. Things in NSDocument can be inspected manually (not that much text processing logic there), but unit tests are needed in other classes.
Edit: NSLayoutManager’s glyph API might also be useful. I suspect that would be slower, though, since they usually generate NSGlyph instances. Maybe some benchmarking is needed?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect the text-processing logic in NSDocument and the other classes containing NSMakeRange(..., 1) or -length character-count assumptions. Add unit tests for surrogate pairs and composed character sequences, and use the tests to identify remaining incorrect counts; done means the affected cases handle UTF-16 strings correctly and the test suite passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- objective-c
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100