Skip to content

Commit 203c480

Browse files
committed
Move off of RegexBuilder
1 parent e885e96 commit 203c480

File tree

2 files changed

+7
-44
lines changed

2 files changed

+7
-44
lines changed

Sources/FoundationEssentials/URL/URLTemplate_Expression.swift

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
internal import RegexBuilder
1413
#if canImport(CollectionsInternal)
1514
internal import CollectionsInternal
1615
#elseif canImport(OrderedCollections)
@@ -104,7 +103,7 @@ extension URL.Template.Expression {
104103
let explode: Bool
105104
if let max = match.output.3 {
106105
guard
107-
let m = max.map({ Int($0) })
106+
let m = Int(max)
108107
else { throw URL.Template.InvalidExpression(text: "Invalid maximum length '\(input[match.range])'") }
109108
maximumLength = m
110109
explode = false
@@ -148,57 +147,23 @@ extension URL.Template {
148147

149148
let operatorRegex: Regex<(Substring, Substring?)>
150149
let separatorRegex: Regex<(Substring)>
151-
let elementRegex: Regex<(Substring, Substring, Substring?, Substring??)>
152-
let uriTemplateRegex: Regex<Regex<(Substring, Regex<OneOrMore<Substring>.RegexOutput>.RegexOutput)>.RegexOutput>
150+
let elementRegex: Regex<(Substring, Substring, Substring?, Substring?)>
151+
let uriTemplateRegex: Regex<(Substring, Substring)>
153152

154153
private init() {
155-
self.operatorRegex = Regex {
156-
Optionally {
157-
Capture {
158-
One(.anyOf("+#./;?&"))
159-
}
160-
}
161-
}
154+
self.operatorRegex = try! Regex(#"([\+#.\/;\?&])?"#)
162155
.asciiOnlyWordCharacters()
163156
.asciiOnlyDigits()
164157
.asciiOnlyCharacterClasses()
165-
self.separatorRegex = Regex {
166-
","
167-
}
158+
self.separatorRegex = try! Regex(#","#)
168159
.asciiOnlyWordCharacters()
169160
.asciiOnlyDigits()
170161
.asciiOnlyCharacterClasses()
171-
self.elementRegex = Regex {
172-
Capture {
173-
One(("a"..."z").union("A"..."Z"))
174-
ZeroOrMore(("a"..."z").union("A"..."Z").union("0"..."9").union(.anyOf("_")))
175-
}
176-
Optionally {
177-
Capture {
178-
ChoiceOf {
179-
Regex {
180-
":"
181-
Capture {
182-
ZeroOrMore(.digit)
183-
}
184-
}
185-
"*"
186-
}
187-
}
188-
}
189-
}
162+
self.elementRegex = try! Regex(#"([a-zA-Z][a-zA-Z0-9_]*)(:([0-9]*)|\*)?"#)
190163
.asciiOnlyWordCharacters()
191164
.asciiOnlyDigits()
192165
.asciiOnlyCharacterClasses()
193-
self.uriTemplateRegex = Regex {
194-
"{"
195-
Capture {
196-
OneOrMore {
197-
CharacterClass.any.subtracting(.anyOf("}"))
198-
}
199-
}
200-
"}"
201-
}
166+
self.uriTemplateRegex = try! Regex(#"{([^}]+)}"#)
202167
}
203168
}
204169
}

Sources/FoundationEssentials/URL/URLTemplate_PercentEncoding.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
internal import RegexBuilder
14-
1513
extension String {
1614
/// Convert to NFC and percent-escape.
1715
func normalizedAddingPercentEncoding(

0 commit comments

Comments
 (0)