.../cutbox_command/Sources/CutBoxCLICore/CutBoxCoreCLIHelpers.swift
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // CutBoxCoreCLIHelpers.swift |
3 | | // |
4 | | // Created by jason on 1/9/23. |
5 | | // |
6 | | |
7 | | import Foundation |
8 | | |
9 | 402 | public func regexpMatch(_ string: String, _ pattern: String, caseSensitive: Bool = true) -> Bool { |
10 | 402 | let range = NSRange(location: 0, length: string.utf16.count) |
11 | 402 | if caseSensitive { |
12 | 9 | if let regex = try? NSRegularExpression(pattern: pattern) { |
13 | 5 | return regex.firstMatch(in: string, options: [], range: range) != nil |
14 | 5 | } |
15 | 397 | } else { |
16 | 393 | let regexOptions: NSRegularExpression.Options = [.caseInsensitive] |
17 | 393 | if let regex = try? NSRegularExpression(pattern: pattern, options: regexOptions) { |
18 | 393 | return regex.firstMatch(in: string, options: [], range: range) != nil |
19 | 393 | } |
20 | 4 | } |
21 | 4 | return false |
22 | 397 | } |
23 | | |
24 | 18 | public func iso8601() -> DateFormatter { |
25 | 18 | let dateFormatter = DateFormatter() |
26 | 18 | dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" |
27 | 18 | return dateFormatter |
28 | 18 | } |
29 | | |
30 | 2 | public func loadPlist(path: String) -> [String: Any] { |
31 | 2 | guard let data = FileManager.default.contents(atPath: path), |
32 | 2 | let plist = try? PropertyListSerialization.propertyList( |
33 | 2 | from: data, |
34 | 2 | options: [], |
35 | 2 | format: nil) as? [String: Any] else { |
36 | 1 | fatalError("Cannot read file at \(path)") |
37 | 2 | } |
38 | 2 | return plist |
39 | 2 | } |