Skip to content

Commit 49e211e

Browse files
committed
Improve _literalPattern documentation
Add an example of a pattern that is different from, but equivalent to, the original regex.
1 parent 5b81cd2 commit 49e211e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Sources/_StringProcessing/LiteralPrinter.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,20 @@ extension Regex {
1717
///
1818
/// This is non-`nil` when used on a regex that can be represented as a
1919
/// string. The literal pattern may be different from the literal or string
20-
/// that was used to create the regex. If this regex includes components
21-
/// that cannot be represented in a regex literal, such as a capture transform
22-
/// or a custom parser that conforms to the `CustomConsumingRegexComponent`
23-
/// protocol, this property is `nil`.
20+
/// that was used to create the regex, though parsing the `_literalPattern`
21+
/// always generates the same internal representation as the original regex.
22+
///
23+
/// // The literal pattern for some regexes is identical to the original:
24+
/// let regex1 = /(\d+):(\d+)/
25+
/// // regex1._literalPattern == #"(\d+):(\d+)"#
26+
///
27+
/// // The literal pattern for others is different, but equivalent:
28+
/// let regex2 = /\p{isName=BEE}/
29+
/// // regex2._literalPattern == #"\N{BEE}"#
30+
///
31+
/// If this regex includes components that cannot be represented in a regex
32+
/// literal, such as a capture transform or a custom parser that conforms to
33+
/// the `CustomConsumingRegexComponent` protocol, this property is `nil`.
2434
///
2535
/// The value of this property may change between different releases of Swift.
2636
public var _literalPattern: String? {

0 commit comments

Comments
 (0)