isBlank + tests
isOnlyEmptySpacesAndNewLineCharacters() is now deprecated
This commit is contained in:
parent
90257e9dcd
commit
a715e2cb07
|
@ -71,6 +71,8 @@ class EZSwiftExtensionsTestsString: XCTestCase {
|
|||
let emptyString = " \n "
|
||||
XCTAssertFalse(string.isOnlyEmptySpacesAndNewLineCharacters())
|
||||
XCTAssertTrue(emptyString.isOnlyEmptySpacesAndNewLineCharacters())
|
||||
XCTAssertFalse(string.isBlank)
|
||||
XCTAssertTrue(emptyString.isBlank)
|
||||
}
|
||||
|
||||
func testTrim() {
|
||||
|
|
|
@ -225,8 +225,10 @@ Easily check if string is empty and trim it:
|
|||
var myString = "\n eZSwiftExtensions is awesome! \n \n "
|
||||
let emptyStr = " \n \n \n"
|
||||
|
||||
print(myString.isOnlyEmptySpacesAndNewLineCharacters()) // false
|
||||
print(emptyStr.isOnlyEmptySpacesAndNewLineCharacters()) // true
|
||||
print(myString.isOnlyEmptySpacesAndNewLineCharacters()) // false //v. 1.5 and earlier
|
||||
print(emptyStr.isOnlyEmptySpacesAndNewLineCharacters()) // true //v. 1.5 and earlier
|
||||
print(myString.isBlank) // false
|
||||
print(emptyStr.isBlank) // true
|
||||
|
||||
myString.trim()
|
||||
print(myString) // eZSwiftExtensions is awesome!
|
||||
|
|
|
@ -126,11 +126,20 @@ extension String {
|
|||
|
||||
|
||||
/// EZSE: Counts whitespace & new lines
|
||||
@available(*, deprecated=1.6, renamed="isBlank")
|
||||
public func isOnlyEmptySpacesAndNewLineCharacters() -> Bool {
|
||||
let characterSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()
|
||||
let newText = self.stringByTrimmingCharactersInSet(characterSet)
|
||||
return newText.isEmpty
|
||||
}
|
||||
|
||||
/// EZSE: Checks if string is empty or consists only of whitespace and newline characters
|
||||
public var isBlank: Bool {
|
||||
get {
|
||||
let trimmed = stringByTrimmingCharactersInSet(.whitespaceAndNewlineCharacterSet())
|
||||
return trimmed.isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
/// EZSE: Trims white space and new line characters
|
||||
public mutating func trim() {
|
||||
|
|
Loading…
Reference in New Issue