1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-18 19:21:39 +03:00
vimr/VimR/PrefUtils.swift

37 lines
933 B
Swift
Raw Normal View History

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(", ")
}
}