Skip to content

Commit 03f19fe

Browse files
authored
Merge pull request #152 from rxwei/substring-conform-to-protocol
Conform `Substring` to `RegexProtocol`
2 parents 12b4b4a + 60303e1 commit 03f19fe

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/_StringProcessing/RegexDSL/DSL.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ extension String: RegexProtocol {
2222
}
2323
}
2424

25+
extension Substring: RegexProtocol {
26+
public typealias Match = Substring
27+
28+
public var regex: Regex<Match> {
29+
let atoms = self.map { atom(.char($0)) }
30+
return .init(ast: concat(atoms))
31+
}
32+
}
33+
2534
extension Character: RegexProtocol {
2635
public typealias Match = Substring
2736

0 commit comments

Comments
 (0)