mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-03 13:31:32 +00:00
30 lines
668 B
Swift
30 lines
668 B
Swift
/*
|
|
* darwin-apk © 2024 Gay Pizza Specifications
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import Foundation
|
|
import ArgumentParser
|
|
|
|
struct RegexMatcher: PatternMatcher {
|
|
private let _patterns: [Regex<_StringProcessing.AnyRegexOutput>]
|
|
|
|
init(patterns: [String], ignoreCase: Bool) throws(ExitCode) {
|
|
do {
|
|
self._patterns = try patterns.map(Regex.init)
|
|
} catch {
|
|
eprint("Bad pattern \(error.localizedDescription)")
|
|
throw .validationFailure
|
|
}
|
|
}
|
|
|
|
func match(_ field: String) -> Bool {
|
|
for pattern in self._patterns {
|
|
if (try? pattern.firstMatch(in: field)) != nil {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
}
|