-
Notifications
You must be signed in to change notification settings - Fork 165
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
Implement AttributedString UTF8 and UTF16 views #1066
Conversation
60ed61e
to
115ac2d
Compare
@swift-ci please test |
_range = range | ||
} | ||
|
||
public init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentionally public
? It wasn't included in the proposal. I don't think you can init
a String.UTF16View
either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, this was copied from the CharacterView
and UnicodeScalarView
code, but I didn't include it in the proposal since there's no need to ever create this yourself especially since it's immutable - I'll remove this from the implementation
|
||
public func index(before i: AttributedString.Index) -> AttributedString.Index { | ||
precondition(i >= startIndex && i <= endIndex, "AttributedString index out of bounds") | ||
let j = Index(_guts.string.utf8.index(before: i._value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this throw if i == startIndex
? I believe calling string.utf8.index(before: string.utf8.startIndex)
throws the index out of bound error. If so, should we just enforce this at the precondition above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still do hit a precondition from swift-collections:
_RopeModule/BigString+Contents.swift:292: Precondition failed: Can't advance below start index
But we might as well account for this here, good call - I'll update the above >=
to be >
@swift-ci please test |
This adds a new UTF-8 and UTF-16 view to
AttributedString
, vending APIs similar to the underlyingBigString
's UTF-8 and UTF-16 view