Skip to content

Commit d4434f8

Browse files
committed
Fix captureGroup regression
1 parent 159c089 commit d4434f8

File tree

1 file changed

+1
-23
lines changed

1 file changed

+1
-23
lines changed

Sources/XcbeautifyLib/Parser.swift

+1-23
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ package class Parser {
113113
return nil
114114
}
115115

116-
let groups: [String] = line.captureGroup(with: captureGroupType.pattern)
116+
let groups: [String] = captureGroupType.regex.captureGroups(for: line)
117117
guard let captureGroup = captureGroupType.init(groups: groups) else {
118118
assertionFailure()
119119
return nil
@@ -125,25 +125,3 @@ package class Parser {
125125
return captureGroup
126126
}
127127
}
128-
129-
private extension String {
130-
func captureGroup(with pattern: String) -> [String] {
131-
do {
132-
let regex = try NSRegularExpression(pattern: pattern, options: [.caseInsensitive])
133-
134-
let matches = regex.matches(in: self, range: NSRange(location: 0, length: utf16.count))
135-
guard let match = matches.first else { return [] }
136-
137-
let lastRangeIndex = match.numberOfRanges - 1
138-
guard lastRangeIndex >= 1 else { return [] }
139-
140-
return (1...lastRangeIndex).compactMap { index in
141-
let capturedGroupIndex = match.range(at: index)
142-
return substring(with: capturedGroupIndex)
143-
}
144-
} catch {
145-
assertionFailure(error.localizedDescription)
146-
return []
147-
}
148-
}
149-
}

0 commit comments

Comments
 (0)