Skip to content

Commit aae128f

Browse files
committed
squash me: cleanups and one missing function
1 parent 2fa9464 commit aae128f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

Sources/RegexBuilder/DSL.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,14 @@ extension _BuiltinRegexComponent {
4141
extension String: RegexComponent {
4242
public typealias Output = Substring
4343

44-
public var regex: Regex<Output> {
45-
.init(node: .quotedLiteral(self))
46-
}
44+
public var regex: Regex<Output> { .init(verbatim: self) }
4745
}
4846

4947
@available(SwiftStdlib 5.7, *)
5048
extension Substring: RegexComponent {
5149
public typealias Output = Substring
5250

53-
public var regex: Regex<Output> {
54-
.init(node: .quotedLiteral(String(self)))
55-
}
51+
public var regex: Regex<Output> { String(self).regex }
5652
}
5753

5854
@available(SwiftStdlib 5.7, *)

Sources/_StringProcessing/Regex/AnyRegexOutput.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public struct AnyRegexOutput {
6161

6262
@available(SwiftStdlib 5.7, *)
6363
extension AnyRegexOutput {
64-
/// Creates a type-erased regex output from an existing output.
64+
/// Creates a type-erased regex output from an existing match.
6565
///
6666
/// Use this initializer to fit a regex with strongly typed captures into the
6767
/// use site of a dynamic regex, like one that was created from a string.
@@ -186,10 +186,12 @@ extension Regex where Output == AnyRegexOutput {
186186

187187
@available(SwiftStdlib 5.7, *)
188188
extension Regex {
189-
/// Creates a strongly-typed regex from a dynamic regex.
189+
/// Creates a strongly-typed regex from a dynamic regex, i.e. one created
190+
/// from a string.
190191
///
191192
/// Use this initializer to create a strongly typed regex from
192-
/// one that was created from a string.
193+
/// one that was created from a string. Returns `nil` if the types
194+
/// don't match.
193195
public init?(_ dynamic: Regex<AnyRegexOutput>) {
194196
self.init(node: dynamic.root)
195197
guard self._verifyType() else {
@@ -249,3 +251,12 @@ extension AnyRegexOutput.ElementRepresentation {
249251
)
250252
}
251253
}
254+
255+
@available(SwiftStdlib 5.7, *)
256+
extension Regex {
257+
/// Produces a regex that matches `verbatim` exactly, as though every
258+
/// metacharacter in it was escaped.
259+
public init(verbatim: String) {
260+
self.init(node: .quotedLiteral(verbatim))
261+
}
262+
}

0 commit comments

Comments
 (0)