added/updated isValid(range:
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
d360ddffa1
commit
9203b6cab5
@ -31,11 +31,21 @@ extension LabelAttributeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func isValidRange(on attributedString: NSMutableAttributedString) -> Bool {
|
public func isValidRange(on attributedString: NSMutableAttributedString) -> Bool {
|
||||||
range.location + range.length <= attributedString.string.count
|
attributedString.isValid(range: range)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public extension String {
|
||||||
|
func isValid(range: NSRange) -> Bool {
|
||||||
|
range.location >= 0 && range.length > 0 && range.location + range.length <= count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension NSAttributedString {
|
public extension NSAttributedString {
|
||||||
|
func isValid(range: NSRange) -> Bool {
|
||||||
|
range.location >= 0 && range.length > 0 && range.location + range.length <= length
|
||||||
|
}
|
||||||
|
|
||||||
func createAttributeModels() -> [(any LabelAttributeModel)] {
|
func createAttributeModels() -> [(any LabelAttributeModel)] {
|
||||||
var attributes: [any VDS.LabelAttributeModel] = []
|
var attributes: [any VDS.LabelAttributeModel] = []
|
||||||
enumerateAttributes(in: NSMakeRange(0, length)) { attributeMap, range, stop in
|
enumerateAttributes(in: NSMakeRange(0, length)) { attributeMap, range, stop in
|
||||||
@ -61,6 +71,7 @@ public extension NSAttributedString {
|
|||||||
|
|
||||||
extension NSMutableAttributedString {
|
extension NSMutableAttributedString {
|
||||||
public func apply(attribute: any LabelAttributeModel) {
|
public func apply(attribute: any LabelAttributeModel) {
|
||||||
|
guard isValid(range: attribute.range) else { return }
|
||||||
attribute.setAttribute(on: self)
|
attribute.setAttribute(on: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user