added/updated isValid(range:

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-03-20 15:24:35 -05:00
parent d360ddffa1
commit 9203b6cab5

View File

@ -31,11 +31,21 @@ extension LabelAttributeModel {
}
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 {
func isValid(range: NSRange) -> Bool {
range.location >= 0 && range.length > 0 && range.location + range.length <= length
}
func createAttributeModels() -> [(any LabelAttributeModel)] {
var attributes: [any VDS.LabelAttributeModel] = []
enumerateAttributes(in: NSMakeRange(0, length)) { attributeMap, range, stop in
@ -61,6 +71,7 @@ public extension NSAttributedString {
extension NSMutableAttributedString {
public func apply(attribute: any LabelAttributeModel) {
guard isValid(range: attribute.range) else { return }
attribute.setAttribute(on: self)
}