1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-22 05:01:50 +03:00
vimr/VimR/PrefUtils.swift

38 lines
903 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 {
2016-09-25 18:50:33 +03:00
fileprivate static let whitespaceCharSet = CharacterSet.whitespaces
2016-09-11 15:28:56 +03:00
static func ignorePatterns(fromString str: String) -> Set<FileItemIgnorePattern> {
2016-09-25 18:50:33 +03:00
if str.trimmingCharacters(in: self.whitespaceCharSet).characters.count == 0 {
2016-09-11 15:28:56 +03:00
return Set()
}
let patterns: [FileItemIgnorePattern] = str
2016-09-25 18:50:33 +03:00
.components(separatedBy: ",")
2016-09-11 15:28:56 +03:00
.flatMap {
2016-09-25 18:50:33 +03:00
let trimmed = $0.trimmingCharacters(in: self.whitespaceCharSet)
2016-09-11 15:28:56 +03:00
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-25 18:50:33 +03:00
.sorted()
.joined(separator: ", ")
2016-09-11 15:28:56 +03:00
}
2016-09-25 18:50:33 +03:00
}