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

NSAttributedString support? #38

Open
sharplet opened this issue Mar 2, 2016 · 1 comment
Open

NSAttributedString support? #38

sharplet opened this issue Mar 2, 2016 · 1 comment

Comments

@sharplet
Copy link
Owner

sharplet commented Mar 2, 2016

Accessing the underlying matched NSRange for use with NSAttributedString has come up in both #26 and #37.

At this point I still consider the Foundation types implementation details. There are gotchas related the use of UTF-16, and I'd prefer to err on the side of safety where it's not possible to make that kind of mistake.

There are probably two main considerations stopping me from adding NSAttributedString support at the moment:

  • So far I've endeavoured to only expose types in the standard library in the public API. NSAttributedString isn't bridged, so I've avoided supporting it. If there was a first-class attributed string value type in the standard library, I think I'd be willing to support it.
  • At this point I'm still interested in reserving the right to replace the regular expression engine with something else, like PCRE.

In a world where Foundation is fully supported and cross-platform (and NSRegularExpression is implemented—it wasn't last time I checked), these reasons will start to hold less water.

Update: Moving away from NSRegularExpression at this stage is unlikely. So the main issue here seems like an API design one.

@sharplet
Copy link
Owner Author

sharplet commented Mar 2, 2016

Something I've considered is exposing a new property on MatchResult:

var utf16Range: Range<String.UTF16Index> { get }

Here's how you'd convert that to an NSRange for use with NSMutableAttributedString:

let range = NSRange(
  location: string.utf16.startIndex.distanceTo(result.utf16Range.startIndex),
  length: result.utf16Range.count)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant