Skip to content

Commit a487e94

Browse files
authored
Add SwiftStdlib 5.7 availability (#276)
Add availability to public, SPI, and test symbols.
1 parent 63ab0a9 commit a487e94

File tree

18 files changed

+79
-9
lines changed

18 files changed

+79
-9
lines changed

Package.swift

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
import PackageDescription
55

6+
let availabilityDefinition = PackageDescription.SwiftSetting.unsafeFlags([
7+
"-Xfrontend",
8+
"-define-availability",
9+
"-Xfrontend",
10+
#""SwiftStdlib 5.7:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999""#
11+
])
12+
613
let package = Package(
714
name: "swift-experimental-string-processing",
815
products: [
@@ -30,12 +37,14 @@ let package = Package(
3037
name: "_RegexParser",
3138
dependencies: [],
3239
swiftSettings: [
33-
.unsafeFlags(["-enable-library-evolution"])
40+
.unsafeFlags(["-enable-library-evolution"]),
41+
availabilityDefinition
3442
]),
3543
.testTarget(
3644
name: "MatchingEngineTests",
3745
dependencies: [
38-
"_RegexParser", "_StringProcessing"]),
46+
"_RegexParser", "_StringProcessing"
47+
]),
3948
.target(
4049
name: "_CUnicode",
4150
dependencies: []),
@@ -44,26 +53,31 @@ let package = Package(
4453
dependencies: ["_RegexParser", "_CUnicode"],
4554
swiftSettings: [
4655
.unsafeFlags(["-enable-library-evolution"]),
56+
availabilityDefinition
4757
]),
4858
.target(
4959
name: "RegexBuilder",
5060
dependencies: ["_StringProcessing", "_RegexParser"],
5161
swiftSettings: [
5262
.unsafeFlags(["-enable-library-evolution"]),
53-
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
63+
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
64+
availabilityDefinition
5465
]),
5566
.testTarget(
5667
name: "RegexTests",
57-
dependencies: ["_StringProcessing"]),
68+
dependencies: ["_StringProcessing"],
69+
swiftSettings: [availabilityDefinition]),
5870
.testTarget(
5971
name: "RegexBuilderTests",
6072
dependencies: ["_StringProcessing", "RegexBuilder"],
6173
swiftSettings: [
62-
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
74+
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
75+
availabilityDefinition
6376
]),
6477
.target(
6578
name: "Prototypes",
66-
dependencies: ["_RegexParser", "_StringProcessing"]),
79+
dependencies: ["_RegexParser", "_StringProcessing"],
80+
swiftSettings: [availabilityDefinition]),
6781

6882
// MARK: Scripts
6983
.executableTarget(
@@ -84,11 +98,12 @@ let package = Package(
8498
name: "Exercises",
8599
dependencies: ["_RegexParser", "Prototypes", "_StringProcessing", "RegexBuilder"],
86100
swiftSettings: [
87-
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
101+
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
102+
availabilityDefinition
88103
]),
89104
.testTarget(
90105
name: "ExercisesTests",
91-
dependencies: ["Exercises"]),
106+
dependencies: ["Exercises"],
107+
swiftSettings: [availabilityDefinition]),
92108
]
93109
)
94-

Sources/RegexBuilder/Anchor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import _RegexParser
1313
@_spi(RegexBuilder) import _StringProcessing
1414

15+
@available(SwiftStdlib 5.7, *)
1516
public struct Anchor {
1617
internal enum Kind {
1718
case startOfSubject
@@ -107,6 +108,7 @@ extension Anchor {
107108
}
108109
}
109110

111+
@available(SwiftStdlib 5.7, *)
110112
public struct Lookahead<Output>: _BuiltinRegexComponent {
111113
public var regex: Regex<Output>
112114

Sources/RegexBuilder/Builder.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
@_spi(RegexBuilder) import _StringProcessing
1313

14+
@available(SwiftStdlib 5.7, *)
1415
@resultBuilder
1516
public enum RegexComponentBuilder {
1617
public static func buildBlock() -> Regex<Substring> {

Sources/RegexBuilder/CharacterClass.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import _RegexParser
1313
@_spi(RegexBuilder) import _StringProcessing
1414

15+
@available(SwiftStdlib 5.7, *)
1516
public struct CharacterClass {
1617
internal var ccc: DSLTree.CustomCharacterClass
1718

@@ -122,6 +123,7 @@ extension CharacterClass {
122123
}
123124

124125
/// Range syntax for characters in `CharacterClass`es.
126+
@available(SwiftStdlib 5.7, *)
125127
public func ...(lhs: Character, rhs: Character) -> CharacterClass {
126128
let range: DSLTree.CustomCharacterClass.Member = .range(.char(lhs), .char(rhs))
127129
let ccc = DSLTree.CustomCharacterClass(members: [range], isInverted: false)
@@ -130,6 +132,7 @@ public func ...(lhs: Character, rhs: Character) -> CharacterClass {
130132

131133
/// Range syntax for unicode scalars in `CharacterClass`es.
132134
@_disfavoredOverload
135+
@available(SwiftStdlib 5.7, *)
133136
public func ...(lhs: UnicodeScalar, rhs: UnicodeScalar) -> CharacterClass {
134137
let range: DSLTree.CustomCharacterClass.Member = .range(.scalar(lhs), .scalar(rhs))
135138
let ccc = DSLTree.CustomCharacterClass(members: [range], isInverted: false)

Sources/RegexBuilder/DSL.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extension _BuiltinRegexComponent {
5454
// Note: Quantifiers are currently gyb'd.
5555

5656
/// Specifies how much to attempt to match when using a quantifier.
57+
@available(SwiftStdlib 5.7, *)
5758
public struct QuantificationBehavior {
5859
internal enum Kind {
5960
case eagerly
@@ -121,6 +122,7 @@ extension QuantificationBehavior {
121122
}
122123
}
123124

125+
@available(SwiftStdlib 5.7, *)
124126
public struct OneOrMore<Output>: _BuiltinRegexComponent {
125127
public var regex: Regex<Output>
126128

@@ -132,6 +134,7 @@ public struct OneOrMore<Output>: _BuiltinRegexComponent {
132134
// Variadics.swift.
133135
}
134136

137+
@available(SwiftStdlib 5.7, *)
135138
public struct ZeroOrMore<Output>: _BuiltinRegexComponent {
136139
public var regex: Regex<Output>
137140

@@ -143,6 +146,7 @@ public struct ZeroOrMore<Output>: _BuiltinRegexComponent {
143146
// Variadics.swift.
144147
}
145148

149+
@available(SwiftStdlib 5.7, *)
146150
public struct Optionally<Output>: _BuiltinRegexComponent {
147151
public var regex: Regex<Output>
148152

@@ -154,6 +158,7 @@ public struct Optionally<Output>: _BuiltinRegexComponent {
154158
// Variadics.swift.
155159
}
156160

161+
@available(SwiftStdlib 5.7, *)
157162
public struct Repeat<Output>: _BuiltinRegexComponent {
158163
public var regex: Regex<Output>
159164

@@ -179,6 +184,7 @@ public struct Repeat<Output>: _BuiltinRegexComponent {
179184
// ) -> R where R.Match == (W, C...)
180185
// }
181186

187+
@available(SwiftStdlib 5.7, *)
182188
@resultBuilder
183189
public struct AlternationBuilder {
184190
@_disfavoredOverload
@@ -201,6 +207,7 @@ public struct AlternationBuilder {
201207
}
202208
}
203209

210+
@available(SwiftStdlib 5.7, *)
204211
public struct ChoiceOf<Output>: _BuiltinRegexComponent {
205212
public var regex: Regex<Output>
206213

@@ -215,6 +222,7 @@ public struct ChoiceOf<Output>: _BuiltinRegexComponent {
215222

216223
// MARK: - Capture
217224

225+
@available(SwiftStdlib 5.7, *)
218226
public struct Capture<Output>: _BuiltinRegexComponent {
219227
public var regex: Regex<Output>
220228

@@ -225,6 +233,7 @@ public struct Capture<Output>: _BuiltinRegexComponent {
225233
// Note: Public initializers are currently gyb'd. See Variadics.swift.
226234
}
227235

236+
@available(SwiftStdlib 5.7, *)
228237
public struct TryCapture<Output>: _BuiltinRegexComponent {
229238
public var regex: Regex<Output>
230239

@@ -239,6 +248,7 @@ public struct TryCapture<Output>: _BuiltinRegexComponent {
239248

240249
/// An atomic group, i.e. opens a local backtracking scope which, upon successful exit,
241250
/// discards any remaining backtracking points from within the scope
251+
@available(SwiftStdlib 5.7, *)
242252
public struct Local<Output>: _BuiltinRegexComponent {
243253
public var regex: Regex<Output>
244254

@@ -249,6 +259,7 @@ public struct Local<Output>: _BuiltinRegexComponent {
249259

250260
// MARK: - Backreference
251261

262+
@available(SwiftStdlib 5.7, *)
252263
public struct Reference<Capture>: RegexComponent {
253264
let id = ReferenceID()
254265

Sources/RegexBuilder/Match.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
import _StringProcessing
1313

1414
extension String {
15+
@available(SwiftStdlib 5.7, *)
1516
public func wholeMatch<R: RegexComponent>(
1617
@RegexComponentBuilder of content: () -> R
1718
) -> Regex<R.Output>.Match? {
1819
wholeMatch(of: content())
1920
}
2021

22+
@available(SwiftStdlib 5.7, *)
2123
public func prefixMatch<R: RegexComponent>(
2224
@RegexComponentBuilder of content: () -> R
2325
) -> Regex<R.Output>.Match? {
@@ -26,12 +28,14 @@ extension String {
2628
}
2729

2830
extension Substring {
31+
@available(SwiftStdlib 5.7, *)
2932
public func wholeMatch<R: RegexComponent>(
3033
@RegexComponentBuilder of content: () -> R
3134
) -> Regex<R.Output>.Match? {
3235
wholeMatch(of: content())
3336
}
3437

38+
@available(SwiftStdlib 5.7, *)
3539
public func prefixMatch<R: RegexComponent>(
3640
@RegexComponentBuilder of content: () -> R
3741
) -> Regex<R.Output>.Match? {

Sources/_StringProcessing/Algorithms/Algorithms/Contains.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extension Collection where Element: Equatable {
2727
/// - Parameter other: A sequence to search for within this collection.
2828
/// - Returns: `true` if the collection contains the specified sequence,
2929
/// otherwise `false`.
30+
@available(SwiftStdlib 5.7, *)
3031
public func contains<S: Sequence>(_ other: S) -> Bool
3132
where S.Element == Element
3233
{
@@ -50,6 +51,7 @@ extension BidirectionalCollection where SubSequence == Substring {
5051
/// - Parameter regex: A regex to search for within this collection.
5152
/// - Returns: `true` if the regex was found in the collection, otherwise
5253
/// `false`.
54+
@available(SwiftStdlib 5.7, *)
5355
public func contains<R: RegexComponent>(_ regex: R) -> Bool {
5456
contains(RegexConsumer(regex))
5557
}

Sources/_StringProcessing/Algorithms/Algorithms/FirstRange.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extension Collection where Element: Equatable {
3737
/// - Parameter sequence: The sequence to search for.
3838
/// - Returns: A range in the collection of the first occurrence of `sequence`.
3939
/// Returns nil if `sequence` is not found.
40+
@available(SwiftStdlib 5.7, *)
4041
public func firstRange<S: Sequence>(
4142
of sequence: S
4243
) -> Range<Index>? where S.Element == Element {
@@ -52,6 +53,7 @@ extension BidirectionalCollection where Element: Comparable {
5253
/// - Parameter other: The sequence to search for.
5354
/// - Returns: A range in the collection of the first occurrence of `sequence`.
5455
/// Returns `nil` if `sequence` is not found.
56+
@available(SwiftStdlib 5.7, *)
5557
public func firstRange<S: Sequence>(
5658
of other: S
5759
) -> Range<Index>? where S.Element == Element {
@@ -71,6 +73,7 @@ extension BidirectionalCollection where SubSequence == Substring {
7173
/// - Parameter regex: The regex to search for.
7274
/// - Returns: A range in the collection of the first occurrence of `regex`.
7375
/// Returns `nil` if `regex` is not found.
76+
@available(SwiftStdlib 5.7, *)
7477
public func firstRange<R: RegexComponent>(of regex: R) -> Range<Index>? {
7578
firstRange(of: RegexConsumer(regex))
7679
}

Sources/_StringProcessing/Algorithms/Algorithms/Replace.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ extension RangeReplaceableCollection where Element: Equatable {
7777
/// to replace. Default is `Int.max`.
7878
/// - Returns: A new collection in which all occurrences of `other` in
7979
/// `subrange` of the collection are replaced by `replacement`.
80+
@available(SwiftStdlib 5.7, *)
8081
public func replacing<S: Sequence, Replacement: Collection>(
8182
_ other: S,
8283
with replacement: Replacement,
@@ -99,6 +100,7 @@ extension RangeReplaceableCollection where Element: Equatable {
99100
/// to replace. Default is `Int.max`.
100101
/// - Returns: A new collection in which all occurrences of `other` in
101102
/// `subrange` of the collection are replaced by `replacement`.
103+
@available(SwiftStdlib 5.7, *)
102104
public func replacing<S: Sequence, Replacement: Collection>(
103105
_ other: S,
104106
with replacement: Replacement,
@@ -117,6 +119,7 @@ extension RangeReplaceableCollection where Element: Equatable {
117119
/// - replacement: The new elements to add to the collection.
118120
/// - maxReplacements: A number specifying how many occurrences of `other`
119121
/// to replace. Default is `Int.max`.
122+
@available(SwiftStdlib 5.7, *)
120123
public mutating func replace<S: Sequence, Replacement: Collection>(
121124
_ other: S,
122125
with replacement: Replacement,
@@ -184,6 +187,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
184187
/// sequence matching `regex` to replace. Default is `Int.max`.
185188
/// - Returns: A new collection in which all occurrences of subsequence
186189
/// matching `regex` in `subrange` are replaced by `replacement`.
190+
@available(SwiftStdlib 5.7, *)
187191
public func replacing<R: RegexComponent, Replacement: Collection>(
188192
_ regex: R,
189193
with replacement: Replacement,
@@ -206,6 +210,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
206210
/// sequence matching `regex` to replace. Default is `Int.max`.
207211
/// - Returns: A new collection in which all occurrences of subsequence
208212
/// matching `regex` are replaced by `replacement`.
213+
@available(SwiftStdlib 5.7, *)
209214
public func replacing<R: RegexComponent, Replacement: Collection>(
210215
_ regex: R,
211216
with replacement: Replacement,
@@ -225,6 +230,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
225230
/// - replacement: The new elements to add to the collection.
226231
/// - maxReplacements: A number specifying how many occurrences of the
227232
/// sequence matching `regex` to replace. Default is `Int.max`.
233+
@available(SwiftStdlib 5.7, *)
228234
public mutating func replace<R: RegexComponent, Replacement: Collection>(
229235
_ regex: R,
230236
with replacement: Replacement,

Sources/_StringProcessing/Algorithms/Algorithms/StartsWith.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extension BidirectionalCollection where SubSequence == Substring {
5353
/// - Parameter regex: A regex to compare to this sequence.
5454
/// - Returns: `true` if the initial elements of the sequence matches the
5555
/// beginning of `regex`; otherwise, `false`.
56+
@available(SwiftStdlib 5.7, *)
5657
public func starts<R: RegexComponent>(with regex: R) -> Bool {
5758
starts(with: RegexConsumer(regex))
5859
}

0 commit comments

Comments
 (0)