@@ -14,40 +14,36 @@ import _RegexParser
14
14
@available ( SwiftStdlib 5 . 7 , * )
15
15
extension RegexComponent {
16
16
/// Returns a regular expression that ignores casing when matching.
17
- public func ignoringCase ( _ ignoreCase : Bool = true ) -> Regex < RegexOutput > {
18
- wrapInOption ( . caseInsensitive, addingIf: ignoreCase )
17
+ public func ignoresCase ( _ ignoresCase : Bool = true ) -> Regex < RegexOutput > {
18
+ wrapInOption ( . caseInsensitive, addingIf: ignoresCase )
19
19
}
20
20
21
21
/// Returns a regular expression that only matches ASCII characters as "word
22
22
/// characters".
23
- public func usingASCIIWordCharacters ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
24
- wrapInOption ( . asciiOnlyDigit , addingIf: useASCII)
23
+ public func asciiOnlyWordCharacters ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
24
+ wrapInOption ( . asciiOnlyWord , addingIf: useASCII)
25
25
}
26
26
27
27
/// Returns a regular expression that only matches ASCII characters as digits.
28
- public func usingASCIIDigits ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
28
+ public func asciiOnlyDigits ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
29
29
wrapInOption ( . asciiOnlyDigit, addingIf: useASCII)
30
30
}
31
31
32
32
/// Returns a regular expression that only matches ASCII characters as space
33
33
/// characters.
34
- public func usingASCIISpaces ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
34
+ public func asciiOnlyWhitespace ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
35
35
wrapInOption ( . asciiOnlySpace, addingIf: useASCII)
36
36
}
37
37
38
38
/// Returns a regular expression that only matches ASCII characters when
39
39
/// matching character classes.
40
- public func usingASCIICharacterClasses ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
40
+ public func asciiOnlyCharacterClasses ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
41
41
wrapInOption ( . asciiOnlyPOSIXProps, addingIf: useASCII)
42
42
}
43
43
44
- /// Returns a regular expression that uses the Unicode word boundary
45
- /// algorithm.
46
- ///
47
- /// This option is enabled by default; pass `false` to disable use of
48
- /// Unicode's word boundary algorithm.
49
- public func usingUnicodeWordBoundaries( _ useUnicodeWordBoundaries: Bool = true ) -> Regex < RegexOutput > {
50
- wrapInOption ( . unicodeWordBoundaries, addingIf: useUnicodeWordBoundaries)
44
+ /// Returns a regular expression that uses the specified word boundary algorithm.
45
+ public func wordBoundaryKind( _ wordBoundaryKind: RegexWordBoundaryKind ) -> Regex < RegexOutput > {
46
+ wrapInOption ( . unicodeWordBoundaries, addingIf: wordBoundaryKind == . unicodeLevel2)
51
47
}
52
48
53
49
/// Returns a regular expression where the start and end of input
@@ -133,6 +129,7 @@ extension RegexComponent {
133
129
}
134
130
135
131
@available ( SwiftStdlib 5 . 7 , * )
132
+ /// A semantic level to use during regex matching.
136
133
public struct RegexSemanticLevel : Hashable {
137
134
internal enum Representation {
138
135
case graphemeCluster
@@ -154,6 +151,38 @@ public struct RegexSemanticLevel: Hashable {
154
151
}
155
152
}
156
153
154
+ @available ( SwiftStdlib 5 . 7 , * )
155
+ /// A word boundary algorithm to use during regex matching.
156
+ public struct RegexWordBoundaryKind : Hashable {
157
+ internal enum Representation {
158
+ case unicodeLevel1
159
+ case unicodeLevel2
160
+ }
161
+
162
+ internal var base : Representation
163
+
164
+ /// A word boundary algorithm that implements the "simple word boundary"
165
+ /// Unicode recommendation.
166
+ ///
167
+ /// A simple word boundary is a position in the input between two characters
168
+ /// that match `/\w\W/` or `/\W\w/`, or between the start or end of the input
169
+ /// and a `\w` character. Word boundaries therefore depend on the option-
170
+ /// defined behavior of `\w`.
171
+ public static var unicodeLevel1 : Self {
172
+ . init( base: . unicodeLevel1)
173
+ }
174
+
175
+ /// A word boundary algorithm that implements the "default word boundary"
176
+ /// Unicode recommendation.
177
+ ///
178
+ /// Default word boundaries use a Unicode algorithm that handles some cases
179
+ /// better than simple word boundaries, such as words with internal
180
+ /// punctuation, changes in script, and Emoji.
181
+ public static var unicodeLevel2 : Self {
182
+ . init( base: . unicodeLevel2)
183
+ }
184
+ }
185
+
157
186
// MARK: - Helper method
158
187
159
188
@available ( SwiftStdlib 5 . 7 , * )
0 commit comments