string-in-chain
string-in-chain copied to clipboard
Suggest change to to make stringToMatch optional, then match() matches the whole string.
I made the 3 changes below to my fork - now I can use for example:
string.match().withFont(CSLeftColumnCell.nameFont).attrString
Since its fairly easy to append one attributed string to another, I build up my final string a bit at a time, using the above on each segment.
In any case" Brilliant Piece of Work!
init(string: String, stringToMatch: String?) { // DFH: String -> String?
self.baseText = string
self.stringToMatch = stringToMatch
self.attrString = NSMutableAttributedString(string: string)
}
func setRange() -> NSRange {
if let stringToMatch = stringToMatch { // DFH: was "stringToMatch as String?"
return baseText.rangeOfString(stringToMatch)
}
return baseText.rangeOfString(baseText as String)
}
public func match(string: String? = nil) -> StringInChain { // DFH: added "? = nil"
return StringInChain(string: self, stringToMatch: string)
}
Looks nice. Please make Pull Request