string-in-chain icon indicating copy to clipboard operation
string-in-chain copied to clipboard

Suggest change to to make stringToMatch optional, then match() matches the whole string.

Open dhoerl opened this issue 9 years ago • 1 comments

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)
}

dhoerl avatar Oct 08 '15 12:10 dhoerl

Looks nice. Please make Pull Request

lsolniczek avatar Oct 08 '15 17:10 lsolniczek