1414@available ( SwiftStdlib 5 . 7 , * )
1515extension RegexComponent {
1616 /// 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 )
1919 }
2020
2121 /// Returns a regular expression that only matches ASCII characters as "word
2222 /// 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)
2525 }
2626
2727 /// 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 > {
2929 wrapInOption ( . asciiOnlyDigit, addingIf: useASCII)
3030 }
3131
3232 /// Returns a regular expression that only matches ASCII characters as space
3333 /// characters.
34- public func usingASCIISpaces ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
34+ public func asciiOnlyWhitespace ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
3535 wrapInOption ( . asciiOnlySpace, addingIf: useASCII)
3636 }
3737
3838 /// Returns a regular expression that only matches ASCII characters when
3939 /// matching character classes.
40- public func usingASCIICharacterClasses ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
40+ public func asciiOnlyCharacterClasses ( _ useASCII: Bool = true ) -> Regex < RegexOutput > {
4141 wrapInOption ( . asciiOnlyPOSIXProps, addingIf: useASCII)
4242 }
4343
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)
5147 }
5248
5349 /// Returns a regular expression where the start and end of input
@@ -133,6 +129,7 @@ extension RegexComponent {
133129}
134130
135131@available ( SwiftStdlib 5 . 7 , * )
132+ /// A semantic level to use during regex matching.
136133public struct RegexSemanticLevel : Hashable {
137134 internal enum Representation {
138135 case graphemeCluster
@@ -154,6 +151,38 @@ public struct RegexSemanticLevel: Hashable {
154151 }
155152}
156153
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+
157186// MARK: - Helper method
158187
159188@available ( SwiftStdlib 5 . 7 , * )
0 commit comments