2018-12-20 16:46:26 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2023-02-14 15:10:32 +00:00
|
|
|
// Copyright © 2018-2023 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
|
|
|
}
|