2016-09-11 15:28:56 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
class PrefUtils {
|
|
|
|
|
|
|
|
private static let whitespaceCharSet = NSCharacterSet.whitespaceCharacterSet()
|
|
|
|
|
|
|
|
static func ignorePatterns(fromString str: String) -> Set<FileItemIgnorePattern> {
|
|
|
|
if str.stringByTrimmingCharactersInSet(self.whitespaceCharSet).characters.count == 0 {
|
|
|
|
return Set()
|
|
|
|
}
|
|
|
|
|
|
|
|
let patterns: [FileItemIgnorePattern] = str
|
|
|
|
.componentsSeparatedByString(",")
|
|
|
|
.flatMap {
|
|
|
|
let trimmed = $0.stringByTrimmingCharactersInSet(self.whitespaceCharSet)
|
|
|
|
if trimmed.characters.count == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return FileItemIgnorePattern(pattern: trimmed)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Set(patterns)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func ignorePatternString(fromSet set: Set<FileItemIgnorePattern>) -> String {
|
2016-09-11 16:22:56 +03:00
|
|
|
return Array(set)
|
2016-09-11 15:28:56 +03:00
|
|
|
.map { $0.pattern }
|
2016-09-11 16:22:56 +03:00
|
|
|
.sort()
|
2016-09-11 15:28:56 +03:00
|
|
|
.joinWithSeparator(", ")
|
|
|
|
}
|
|
|
|
}
|