lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb in sugarcube-3.0.6 vs lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb in sugarcube-3.0.7
- old
+ new
@@ -109,9 +109,31 @@
string = NSMutableAttributedString.alloc.initWithAttributedString(self)
string.appendAttributedString(attributedstring.nsattributedstring)
string
end
+ def empty?
+ self.length == 0
+ end
+
+ def strip
+ # Trim leading whitespace and newlines.
+ charSet = NSCharacterSet.whitespaceAndNewlineCharacterSet
+ range = self.string.rangeOfCharacterFromSet(charSet)
+ while (range.length != 0 && range.location == 0)
+ self.replaceCharactersInRange(range, withString:"")
+ range = self.string.rangeOfCharacterFromSet(charSet)
+ end
+
+ # Trim trailing whitespace and newlines.
+ range = self.string.rangeOfCharacterFromSet(charSet, options:NSBackwardsSearch)
+ while (range.length != 0 && NSMaxRange(range) == self.length)
+ self.replaceCharactersInRange(range, withString:"")
+ range = self.string.rangeOfCharacterFromSet(charSet, options:NSBackwardsSearch)
+ end
+ self
+ end
+
end
class NSMutableAttributedString