add different match types to search

This commit is contained in:
2024-11-15 23:59:56 +11:00
parent 7e403d64e0
commit 1b6883c9df
5 changed files with 137 additions and 19 deletions

View File

@ -0,0 +1,29 @@
/*
* 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 {
print("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
}
}