Skip to content

Commit b48f09e

Browse files
committed
squash me: cleanup
1 parent c2b93ab commit b48f09e

File tree

3 files changed

+41
-43
lines changed

3 files changed

+41
-43
lines changed

Sources/_StringProcessing/Engine/MEBuiltins.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,25 @@ extension String {
223223
else { return nil }
224224
return next
225225
}
226+
227+
internal func matchRegexDot(
228+
at currentPosition: Index,
229+
limitedBy end: Index,
230+
anyMatchesNewline: Bool,
231+
isScalarSemantics: Bool
232+
) -> Index? {
233+
guard currentPosition < end else { return nil }
234+
235+
if anyMatchesNewline {
236+
return index(
237+
after: currentPosition, isScalarSemantics: isScalarSemantics)
238+
}
239+
240+
return matchAnyNonNewline(
241+
at: currentPosition,
242+
limitedBy: end,
243+
isScalarSemantics: isScalarSemantics)
244+
}
226245
}
227246

228247
// MARK: - Built-in character class matching

Sources/_StringProcessing/Engine/MEQuantify.swift

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
11
private typealias ASCIIBitset = DSLTree.CustomCharacterClass.AsciiBitset
22

33
extension Processor {
4-
func _doASCIIBitsetMatch(
5-
_: AsciiBitsetRegister
6-
) -> Input.Index? {
7-
fatalError()
8-
}
9-
}
10-
11-
12-
extension String {
13-
func index(after idx: Index, isScalarSemantics: Bool) -> Index {
14-
if isScalarSemantics {
15-
return unicodeScalars.index(after: idx)
16-
} else {
17-
return index(after: idx)
18-
}
19-
}
20-
}
21-
22-
23-
extension Processor {
24-
254
internal mutating func runQuantify(_ payload: QuantifyPayload) -> Bool {
265
let matched: Bool
276
switch (payload.quantKind, payload.minTrips, payload.maxExtraTrips) {
@@ -61,8 +40,6 @@ extension Processor {
6140
boundaryCheck: !isScalarSemantics,
6241
isCaseInsensitive: false)
6342
case .builtin:
64-
guard currentPosition < end else { return nil }
65-
6643
// We only emit .quantify if it consumes a single character
6744
return input.matchBuiltinCC(
6845
payload.builtin,
@@ -72,16 +49,10 @@ extension Processor {
7249
isStrictASCII: payload.builtinIsStrict,
7350
isScalarSemantics: isScalarSemantics)
7451
case .any:
75-
guard currentPosition < end else { return nil }
76-
77-
if payload.anyMatchesNewline {
78-
return input.index(
79-
after: currentPosition, isScalarSemantics: isScalarSemantics)
80-
}
81-
82-
return input.matchAnyNonNewline(
52+
return input.matchRegexDot(
8353
at: currentPosition,
8454
limitedBy: end,
55+
anyMatchesNewline: payload.anyMatchesNewline,
8556
isScalarSemantics: isScalarSemantics)
8657
}
8758
}
@@ -217,20 +188,16 @@ extension Processor {
217188
assert(currentPosition > rangeEnd)
218189
}
219190
case .any:
191+
let anyMatchesNewline = payload.anyMatchesNewline
220192
while true {
221-
guard currentPosition < end else { break }
222-
let next: String.Index?
223-
if payload.anyMatchesNewline {
224-
next = input.index(
225-
after: currentPosition, isScalarSemantics: isScalarSemantics)
226-
} else {
227-
next = input.matchAnyNonNewline(
228-
at: currentPosition,
229-
limitedBy: end,
230-
isScalarSemantics: isScalarSemantics)
193+
guard let next = input.matchRegexDot(
194+
at: currentPosition,
195+
limitedBy: end,
196+
anyMatchesNewline: anyMatchesNewline,
197+
isScalarSemantics: isScalarSemantics)
198+
else {
199+
break
231200
}
232-
233-
guard let next else { break }
234201
matchedOnce = true
235202
rangeEnd = currentPosition
236203
currentPosition = next

Sources/_StringProcessing/Utility/Misc.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,15 @@ enum QuickResult<R> {
6565
case unknown
6666
}
6767

68+
extension String {
69+
/// Index after in either grapheme or scalar view
70+
func index(after idx: Index, isScalarSemantics: Bool) -> Index {
71+
if isScalarSemantics {
72+
return unicodeScalars.index(after: idx)
73+
} else {
74+
return index(after: idx)
75+
}
76+
}
77+
}
78+
79+

0 commit comments

Comments
 (0)