|
10 | 10 | // |
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | | -internal import RegexBuilder |
14 | 13 | #if canImport(CollectionsInternal) |
15 | 14 | internal import CollectionsInternal |
16 | 15 | #elseif canImport(OrderedCollections) |
@@ -104,7 +103,7 @@ extension URL.Template.Expression { |
104 | 103 | let explode: Bool |
105 | 104 | if let max = match.output.3 { |
106 | 105 | guard |
107 | | - let m = max.map({ Int($0) }) |
| 106 | + let m = Int(max) |
108 | 107 | else { throw URL.Template.InvalidExpression(text: "Invalid maximum length '\(input[match.range])'") } |
109 | 108 | maximumLength = m |
110 | 109 | explode = false |
@@ -148,57 +147,23 @@ extension URL.Template { |
148 | 147 |
|
149 | 148 | let operatorRegex: Regex<(Substring, Substring?)> |
150 | 149 | 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)> |
153 | 152 |
|
154 | 153 | private init() { |
155 | | - self.operatorRegex = Regex { |
156 | | - Optionally { |
157 | | - Capture { |
158 | | - One(.anyOf("+#./;?&")) |
159 | | - } |
160 | | - } |
161 | | - } |
| 154 | + self.operatorRegex = try! Regex(#"([\+#.\/;\?&])?"#) |
162 | 155 | .asciiOnlyWordCharacters() |
163 | 156 | .asciiOnlyDigits() |
164 | 157 | .asciiOnlyCharacterClasses() |
165 | | - self.separatorRegex = Regex { |
166 | | - "," |
167 | | - } |
| 158 | + self.separatorRegex = try! Regex(#","#) |
168 | 159 | .asciiOnlyWordCharacters() |
169 | 160 | .asciiOnlyDigits() |
170 | 161 | .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]*)|\*)?"#) |
190 | 163 | .asciiOnlyWordCharacters() |
191 | 164 | .asciiOnlyDigits() |
192 | 165 | .asciiOnlyCharacterClasses() |
193 | | - self.uriTemplateRegex = Regex { |
194 | | - "{" |
195 | | - Capture { |
196 | | - OneOrMore { |
197 | | - CharacterClass.any.subtracting(.anyOf("}")) |
198 | | - } |
199 | | - } |
200 | | - "}" |
201 | | - } |
| 166 | + self.uriTemplateRegex = try! Regex(#"{([^}]+)}"#) |
202 | 167 | } |
203 | 168 | } |
204 | 169 | } |
|
0 commit comments