2018-12-20 16:46:26 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-06-17 14:56:46 +00:00
|
|
|
// Copyright © 2018-2021 WireGuard LLC. All Rights Reserved.
|
2018-12-20 16:46:26 +00:00
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
extension String {
|
2018-12-21 22:34:56 +00:00
|
|
|
|
2018-12-20 16:46:26 +00:00
|
|
|
func splitToArray(separator: Character = ",", trimmingCharacters: CharacterSet? = nil) -> [String] {
|
|
|
|
return split(separator: separator)
|
|
|
|
.map {
|
|
|
|
if let charSet = trimmingCharacters {
|
|
|
|
return $0.trimmingCharacters(in: charSet)
|
|
|
|
} else {
|
|
|
|
return String($0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-21 22:34:56 +00:00
|
|
|
|
2018-12-20 16:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Optional where Wrapped == String {
|
2018-12-21 22:34:56 +00:00
|
|
|
|
2018-12-20 16:46:26 +00:00
|
|
|
func splitToArray(separator: Character = ",", trimmingCharacters: CharacterSet? = nil) -> [String] {
|
|
|
|
switch self {
|
|
|
|
case .none:
|
|
|
|
return []
|
|
|
|
case .some(let wrapped):
|
|
|
|
return wrapped.splitToArray(separator: separator, trimmingCharacters: trimmingCharacters)
|
|
|
|
}
|
|
|
|
}
|
2018-12-21 22:34:56 +00:00
|
|
|
|
2018-12-20 16:46:26 +00:00
|
|
|
}
|