1
1
import Foundation
2
2
3
3
extension String {
4
- private func captureGroup( with pattern: String ) -> [ String ] {
5
- do {
6
- let regex = try NSRegularExpression ( pattern: pattern, options: [ . caseInsensitive] )
4
+ private static let captureGroups : [ any CaptureGroup . Type ] = [
5
+ AnalyzeCaptureGroup . self,
6
+ BuildTargetCaptureGroup . self,
7
+ AggregateTargetCaptureGroup . self,
8
+ AnalyzeTargetCaptureGroup . self,
9
+ CheckDependenciesCaptureGroup . self,
10
+ ShellCommandCaptureGroup . self,
11
+ CleanRemoveCaptureGroup . self,
12
+ CleanTargetCaptureGroup . self,
13
+ CodesignCaptureGroup . self,
14
+ CodesignFrameworkCaptureGroup . self,
15
+ CompileCaptureGroup . self,
16
+ CompileCommandCaptureGroup . self,
17
+ CompileXibCaptureGroup . self,
18
+ CompileStoryboardCaptureGroup . self,
19
+ CopyHeaderCaptureGroup . self,
20
+ CopyPlistCaptureGroup . self,
21
+ CopyStringsCaptureGroup . self,
22
+ CpresourceCaptureGroup . self,
23
+ ExecutedWithoutSkippedCaptureGroup . self,
24
+ ExecutedWithSkippedCaptureGroup . self,
25
+ FailingTestCaptureGroup . self,
26
+ UIFailingTestCaptureGroup . self,
27
+ RestartingTestCaptureGroup . self,
28
+ GenerateCoverageDataCaptureGroup . self,
29
+ GeneratedCoverageReportCaptureGroup . self,
30
+ GenerateDSYMCaptureGroup . self,
31
+ LibtoolCaptureGroup . self,
32
+ LinkingCaptureGroup . self,
33
+ TestCasePassedCaptureGroup . self,
34
+ TestCaseStartedCaptureGroup . self,
35
+ TestCasePendingCaptureGroup . self,
36
+ TestCaseMeasuredCaptureGroup . self,
37
+ ParallelTestCasePassedCaptureGroup . self,
38
+ ParallelTestCaseAppKitPassedCaptureGroup . self,
39
+ ParallelTestCaseFailedCaptureGroup . self,
40
+ ParallelTestingStartedCaptureGroup . self,
41
+ ParallelTestingPassedCaptureGroup . self,
42
+ ParallelTestingFailedCaptureGroup . self,
43
+ ParallelTestSuiteStartedCaptureGroup . self,
44
+ PhaseSuccessCaptureGroup . self,
45
+ PhaseScriptExecutionCaptureGroup . self,
46
+ ProcessPchCaptureGroup . self,
47
+ ProcessPchCommandCaptureGroup . self,
48
+ PreprocessCaptureGroup . self,
49
+ PbxcpCaptureGroup . self,
50
+ ProcessInfoPlistCaptureGroup . self,
51
+ TestsRunCompletionCaptureGroup . self,
52
+ TestSuiteStartedCaptureGroup . self,
53
+ TestSuiteStartCaptureGroup . self,
54
+ TestSuiteAllTestsPassedCaptureGroup . self,
55
+ TestSuiteAllTestsFailedCaptureGroup . self,
56
+ TIFFutilCaptureGroup . self,
57
+ TouchCaptureGroup . self,
58
+ WriteFileCaptureGroup . self,
59
+ WriteAuxiliaryFilesCaptureGroup . self,
60
+ CompileWarningCaptureGroup . self,
61
+ LDWarningCaptureGroup . self,
62
+ GenericWarningCaptureGroup . self,
63
+ WillNotBeCodeSignedCaptureGroup . self,
64
+ DuplicateLocalizedStringKeyCaptureGroup . self,
65
+ ClangErrorCaptureGroup . self,
66
+ CheckDependenciesErrorsCaptureGroup . self,
67
+ ProvisioningProfileRequiredCaptureGroup . self,
68
+ NoCertificateCaptureGroup . self,
69
+ CompileErrorCaptureGroup . self,
70
+ CursorCaptureGroup . self,
71
+ FatalErrorCaptureGroup . self,
72
+ FileMissingErrorCaptureGroup . self,
73
+ LDErrorCaptureGroup . self,
74
+ LinkerDuplicateSymbolsLocationCaptureGroup . self,
75
+ LinkerDuplicateSymbolsCaptureGroup . self,
76
+ LinkerUndefinedSymbolLocationCaptureGroup . self,
77
+ LinkerUndefinedSymbolsCaptureGroup . self,
78
+ PodsErrorCaptureGroup . self,
79
+ SymbolReferencedFromCaptureGroup . self,
80
+ ModuleIncludesErrorCaptureGroup . self,
81
+ UndefinedSymbolLocationCaptureGroup . self,
82
+ PackageFetchingCaptureGroup . self,
83
+ PackageUpdatingCaptureGroup . self,
84
+ PackageCheckingOutCaptureGroup . self,
85
+ PackageGraphResolvingStartCaptureGroup . self,
86
+ PackageGraphResolvingEndedCaptureGroup . self,
87
+ PackageGraphResolvedItemCaptureGroup . self,
88
+ XcodebuildErrorCaptureGroup . self,
89
+ ]
7
90
8
- let matches = regex. matches ( in: self , range: NSRange ( location: 0 , length: utf16. count) )
9
- guard let match = matches. first else { return [ ] }
10
-
11
- let lastRangeIndex = match. numberOfRanges - 1
12
- guard lastRangeIndex >= 1 else { return [ ] }
13
-
14
- return ( 1 ... lastRangeIndex) . compactMap { index in
15
- let capturedGroupIndex = match. range ( at: index)
16
- return substring ( with: capturedGroupIndex)
17
- }
18
- } catch {
19
- assertionFailure ( error. localizedDescription)
20
- return [ ]
21
- }
22
- }
23
- }
24
-
25
- extension String {
26
91
func captureGroup( with pattern: String ) -> CaptureGroup ? {
27
- let results : [ String ] = captureGroup ( with: pattern)
28
-
29
- let captureGroups : [ any CaptureGroup . Type ] = [
30
- AnalyzeCaptureGroup . self,
31
- BuildTargetCaptureGroup . self,
32
- AggregateTargetCaptureGroup . self,
33
- AnalyzeTargetCaptureGroup . self,
34
- CheckDependenciesCaptureGroup . self,
35
- ShellCommandCaptureGroup . self,
36
- CleanRemoveCaptureGroup . self,
37
- CleanTargetCaptureGroup . self,
38
- CodesignCaptureGroup . self,
39
- CodesignFrameworkCaptureGroup . self,
40
- CompileCaptureGroup . self,
41
- CompileCommandCaptureGroup . self,
42
- CompileXibCaptureGroup . self,
43
- CompileStoryboardCaptureGroup . self,
44
- CopyHeaderCaptureGroup . self,
45
- CopyPlistCaptureGroup . self,
46
- CopyStringsCaptureGroup . self,
47
- CpresourceCaptureGroup . self,
48
- ExecutedWithoutSkippedCaptureGroup . self,
49
- ExecutedWithSkippedCaptureGroup . self,
50
- FailingTestCaptureGroup . self,
51
- UIFailingTestCaptureGroup . self,
52
- RestartingTestCaptureGroup . self,
53
- GenerateCoverageDataCaptureGroup . self,
54
- GeneratedCoverageReportCaptureGroup . self,
55
- GenerateDSYMCaptureGroup . self,
56
- LibtoolCaptureGroup . self,
57
- LinkingCaptureGroup . self,
58
- TestCasePassedCaptureGroup . self,
59
- TestCaseStartedCaptureGroup . self,
60
- TestCasePendingCaptureGroup . self,
61
- TestCaseMeasuredCaptureGroup . self,
62
- ParallelTestCasePassedCaptureGroup . self,
63
- ParallelTestCaseAppKitPassedCaptureGroup . self,
64
- ParallelTestCaseFailedCaptureGroup . self,
65
- ParallelTestingStartedCaptureGroup . self,
66
- ParallelTestingPassedCaptureGroup . self,
67
- ParallelTestingFailedCaptureGroup . self,
68
- ParallelTestSuiteStartedCaptureGroup . self,
69
- PhaseSuccessCaptureGroup . self,
70
- PhaseScriptExecutionCaptureGroup . self,
71
- ProcessPchCaptureGroup . self,
72
- ProcessPchCommandCaptureGroup . self,
73
- PreprocessCaptureGroup . self,
74
- PbxcpCaptureGroup . self,
75
- ProcessInfoPlistCaptureGroup . self,
76
- TestsRunCompletionCaptureGroup . self,
77
- TestSuiteStartedCaptureGroup . self,
78
- TestSuiteStartCaptureGroup . self,
79
- TestSuiteAllTestsPassedCaptureGroup . self,
80
- TestSuiteAllTestsFailedCaptureGroup . self,
81
- TIFFutilCaptureGroup . self,
82
- TouchCaptureGroup . self,
83
- WriteFileCaptureGroup . self,
84
- WriteAuxiliaryFilesCaptureGroup . self,
85
- CompileWarningCaptureGroup . self,
86
- LDWarningCaptureGroup . self,
87
- GenericWarningCaptureGroup . self,
88
- WillNotBeCodeSignedCaptureGroup . self,
89
- DuplicateLocalizedStringKeyCaptureGroup . self,
90
- ClangErrorCaptureGroup . self,
91
- CheckDependenciesErrorsCaptureGroup . self,
92
- ProvisioningProfileRequiredCaptureGroup . self,
93
- NoCertificateCaptureGroup . self,
94
- CompileErrorCaptureGroup . self,
95
- CursorCaptureGroup . self,
96
- FatalErrorCaptureGroup . self,
97
- FileMissingErrorCaptureGroup . self,
98
- LDErrorCaptureGroup . self,
99
- LinkerDuplicateSymbolsLocationCaptureGroup . self,
100
- LinkerDuplicateSymbolsCaptureGroup . self,
101
- LinkerUndefinedSymbolLocationCaptureGroup . self,
102
- LinkerUndefinedSymbolsCaptureGroup . self,
103
- PodsErrorCaptureGroup . self,
104
- SymbolReferencedFromCaptureGroup . self,
105
- ModuleIncludesErrorCaptureGroup . self,
106
- UndefinedSymbolLocationCaptureGroup . self,
107
- PackageFetchingCaptureGroup . self,
108
- PackageUpdatingCaptureGroup . self,
109
- PackageCheckingOutCaptureGroup . self,
110
- PackageGraphResolvingStartCaptureGroup . self,
111
- PackageGraphResolvingEndedCaptureGroup . self,
112
- PackageGraphResolvedItemCaptureGroup . self,
113
- XcodebuildErrorCaptureGroup . self,
114
- ]
115
-
116
- let captureGroupType : CaptureGroup . Type ? = captureGroups. first { captureGroup in
92
+ let captureGroupType : CaptureGroup . Type ? = Self . captureGroups. first { captureGroup in
117
93
captureGroup. pattern == pattern
118
94
}
119
95
@@ -122,7 +98,9 @@ extension String {
122
98
return nil
123
99
}
124
100
125
- let captureGroup = captureGroupType. init ( groups: results)
101
+ let groups : [ String ] = captureGroupType. regex. captureGroups ( for: self )
102
+
103
+ let captureGroup = captureGroupType. init ( groups: groups)
126
104
assert ( captureGroup != nil )
127
105
return captureGroup
128
106
}
0 commit comments