.../Source/App/Services/History/HistoryLimitNumberFormatter.swift
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // HistoryLimitNumberFormatter.swift |
3 | | // CutBox |
4 | | // |
5 | | // Created by Jason Milkins on 15/4/18. |
6 | | // Copyright © 2018-2023 ocodo. All rights reserved. |
7 | | // |
8 | | |
9 | | import Foundation |
10 | | |
11 | | class HistoryLimitNumberFormatter: NumberFormatter { |
12 | | |
13 | | override var isPartialStringValidationEnabled: Bool { |
14 | 1 | get { |
15 | 1 | return true |
16 | 1 | } |
17 | | // swiftlint:disable unused_setter_value |
18 | 1 | set { fatalError("HistoryLimitNumberFormatter().isPartialStringValidationEnabled is not settable") } |
19 | | // swiftlint:enable unused_setter_value |
20 | | } |
21 | | |
22 | 4 | var intOnlyRegex: NSRegularExpression? { |
23 | 4 | do { |
24 | 4 | return try NSRegularExpression(pattern: "^[0-9]*$", |
25 | 4 | options: NSRegularExpression.Options.caseInsensitive) |
26 | 4 | } catch { fatalError("invalid regexp in intOnlyRegex") } |
27 | 0 | } |
28 | | |
29 | | override func isPartialStringValid(_ partialString: String, |
30 | | newEditingString newString: AutoreleasingUnsafeMutablePointer<NSString?>?, |
31 | | errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) |
32 | 3 | -> Bool { |
33 | 3 | return intOnlyRegex?.matches(in: partialString, |
34 | 3 | options: .anchored, |
35 | 3 | range: NSRange(partialString.startIndex..., |
36 | 3 | in: partialString)).count == 1 |
37 | 3 | } |
38 | | } |