I want to use Foundation's AttributedString as a backing store for syntax-highlighted (LaTeX) source code in my editor app.
There's basically two categories of code dealing with LaTeX source in my app:
- Code that's only interested in the raw string content (the character data). This code compares, searches (also case-insensitive), slices, or modifies the source string.
- Code that stores or retrieves syntax highlighting information in the attributes (for integration with
NSTextStorage/NSTextView).
Previously, syntax highlighting was implemented by copying the source into a separate NSMutableAttributedString, and applying the attributes there. This is of course ugly and undesirable, because the source is now stored twice.
I would like to replace the two separate strings with one AttributedString that can cater to both use cases.
I think porting the existing syntax highlighting should be pretty straightforward, but I am not sure how to best approach category 1, the code that operates on the raw string content.
For example, I can't find API for case-insensitive comparison. StringProtocol has compare(_:options:range:locale:), but I can't find anything like that on AttributedStringProtocol.
Would I need to operate on AttributedString's characters view instead? Or can I get a StringProtocol-like view on an AttributedString somehow?