Skip to content

Commit 66ab297

Browse files
committed
Merge pull request swiftlang#575 from Azoy/various-tidbits
Rename various APIs
1 parent 65178f9 commit 66ab297

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

Sources/RegexBuilder/Anchor.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ extension Anchor {
104104
///
105105
/// This anchor is equivalent to `^` in regex syntax when the `m` option
106106
/// has been enabled or `anchorsMatchLineEndings(true)` has been called.
107+
///
108+
/// For example, the following regexes are all equivalent:
109+
///
110+
/// - `Regex { Anchor.startOfLine }`
111+
/// - `/(?m)^/` or `/(?m:^)/`
112+
/// - `/^/.anchorsMatchLineEndings(true)`
107113
public static var startOfLine: Anchor {
108114
Anchor(kind: .startOfLine)
109115
}
@@ -113,6 +119,12 @@ extension Anchor {
113119
///
114120
/// This anchor is equivalent to `$` in regex syntax when the `m` option
115121
/// has been enabled or `anchorsMatchLineEndings(true)` has been called.
122+
///
123+
/// For example, the following regexes are all equivalent:
124+
///
125+
/// - `Regex { Anchor.endOfLine }`
126+
/// - `/(?m)$/` or `/(?m:$)/`
127+
/// - `/$/.anchorsMatchLineEndings(true)`
116128
public static var endOfLine: Anchor {
117129
Anchor(kind: .endOfLine)
118130
}

Sources/_StringProcessing/Regex/Options.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extension RegexComponent {
6565
/// - Parameter wordBoundaryKind: The algorithm to use for determining word boundaries.
6666
/// - Returns: The modified regular expression.
6767
public func wordBoundaryKind(_ wordBoundaryKind: RegexWordBoundaryKind) -> Regex<RegexOutput> {
68-
wrapInOption(.unicodeWordBoundaries, addingIf: wordBoundaryKind == .unicodeLevel2)
68+
wrapInOption(.unicodeWordBoundaries, addingIf: wordBoundaryKind == .default)
6969
}
7070

7171
/// Returns a regular expression where the start and end of input
@@ -83,8 +83,8 @@ extension RegexComponent {
8383
///
8484
/// This method corresponds to applying the `m` option in regex syntax. For
8585
/// this behavior in the `RegexBuilder` syntax, see
86-
/// ``Anchor.startOfLine``, ``Anchor.endOfLine``, ``Anchor.startOfInput``,
87-
/// and ``Anchor.endOfInput``.
86+
/// ``Anchor.startOfLine``, ``Anchor.endOfLine``, ``Anchor.startOfSubject``,
87+
/// and ``Anchor.endOfSubject``.
8888
///
8989
/// - Parameter matchLineEndings: A Boolean value indicating whether `^` and
9090
/// `$` should match the start and end of lines, respectively.
@@ -205,7 +205,7 @@ public struct RegexWordBoundaryKind: Hashable {
205205
/// that match `/\w\W/` or `/\W\w/`, or between the start or end of the input
206206
/// and a `\w` character. Word boundaries therefore depend on the option-
207207
/// defined behavior of `\w`.
208-
public static var unicodeLevel1: Self {
208+
public static var simple: Self {
209209
.init(base: .unicodeLevel1)
210210
}
211211

@@ -215,7 +215,7 @@ public struct RegexWordBoundaryKind: Hashable {
215215
/// Default word boundaries use a Unicode algorithm that handles some cases
216216
/// better than simple word boundaries, such as words with internal
217217
/// punctuation, changes in script, and Emoji.
218-
public static var unicodeLevel2: Self {
218+
public static var `default`: Self {
219219
.init(base: .unicodeLevel2)
220220
}
221221
}

Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class RegexDSLTests: XCTestCase {
307307
OneOrMore(.word)
308308
Anchor.wordBoundary
309309
}
310-
.wordBoundaryKind(.unicodeLevel1)
310+
.wordBoundaryKind(.simple)
311311
OneOrMore(.any, .reluctant)
312312
"stop"
313313
}

Tests/RegexTests/UTS18Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ extension UTS18Tests {
222222
// - Nonspacing marks are never divided from their base characters, and
223223
// otherwise ignored in locating boundaries.
224224
func testSimpleWordBoundaries() {
225-
let simpleWordRegex = regex(#".+?\b"#).wordBoundaryKind(.unicodeLevel1)
225+
let simpleWordRegex = regex(#".+?\b"#).wordBoundaryKind(.simple)
226226
expectFirstMatch(input, simpleWordRegex, input[pos: ..<11])
227227
expectFirstMatch("don't", simpleWordRegex, "don")
228228
expectFirstMatch("Cafe\u{301}", simpleWordRegex, "Café")

0 commit comments

Comments
 (0)