-
Notifications
You must be signed in to change notification settings - Fork 190
Move off of RegexBuilder for URL.Template #1273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,6 @@ | |
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#if FOUNDATION_FRAMEWORK | ||
internal import RegexBuilder | ||
#endif | ||
|
||
#if canImport(CollectionsInternal) | ||
internal import CollectionsInternal | ||
#elseif canImport(OrderedCollections) | ||
|
@@ -82,7 +78,6 @@ extension URL.Template.Expression.Element: CustomStringConvertible { | |
} | ||
} | ||
|
||
#if FOUNDATION_FRAMEWORK | ||
extension URL.Template.Expression { | ||
init(_ input: String) throws { | ||
var remainder = input[...] | ||
|
@@ -108,7 +103,7 @@ extension URL.Template.Expression { | |
let explode: Bool | ||
if let max = match.output.3 { | ||
guard | ||
let m = max.map({ Int($0) }) | ||
let m = Int(max) | ||
else { throw URL.Template.InvalidExpression(text: "Invalid maximum length '\(input[match.range])'") } | ||
maximumLength = m | ||
explode = false | ||
|
@@ -152,61 +147,26 @@ extension URL.Template { | |
|
||
let operatorRegex: Regex<(Substring, Substring?)> | ||
let separatorRegex: Regex<(Substring)> | ||
let elementRegex: Regex<(Substring, Substring, Substring?, Substring??)> | ||
let uriTemplateRegex: Regex<Regex<(Substring, Regex<OneOrMore<Substring>.RegexOutput>.RegexOutput)>.RegexOutput> | ||
let elementRegex: Regex<(Substring, Substring, Substring?, Substring?)> | ||
let uriTemplateRegex: Regex<(Substring, Substring)> | ||
|
||
private init() { | ||
self.operatorRegex = Regex { | ||
Optionally { | ||
Capture { | ||
One(.anyOf("+#./;?&")) | ||
} | ||
} | ||
} | ||
self.operatorRegex = try! Regex(#"([\+#.\/;\?&])?"#) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know if it makes a difference whether you create a Regex this way or the other one that specifies the output type? init(
_ pattern: String,
as outputType: Output.Type = Output.self
) throws For example would it help the performance since we can bypass parsing the result from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea if that makes any difference. Happy to change it, if that helps. These are only every created once, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ok with this as-is for now. We can always come back if we find this useful later. |
||
.asciiOnlyWordCharacters() | ||
.asciiOnlyDigits() | ||
.asciiOnlyCharacterClasses() | ||
self.separatorRegex = Regex { | ||
"," | ||
} | ||
self.separatorRegex = try! Regex(#","#) | ||
.asciiOnlyWordCharacters() | ||
.asciiOnlyDigits() | ||
.asciiOnlyCharacterClasses() | ||
self.elementRegex = Regex { | ||
Capture { | ||
One(("a"..."z").union("A"..."Z")) | ||
ZeroOrMore(("a"..."z").union("A"..."Z").union("0"..."9").union(.anyOf("_"))) | ||
} | ||
Optionally { | ||
Capture { | ||
ChoiceOf { | ||
Regex { | ||
":" | ||
Capture { | ||
ZeroOrMore(.digit) | ||
} | ||
} | ||
"*" | ||
} | ||
} | ||
} | ||
} | ||
self.elementRegex = try! Regex(#"([a-zA-Z][a-zA-Z0-9_]*)(:([0-9]*)|\*)?"#) | ||
.asciiOnlyWordCharacters() | ||
.asciiOnlyDigits() | ||
.asciiOnlyCharacterClasses() | ||
self.uriTemplateRegex = Regex { | ||
"{" | ||
Capture { | ||
OneOrMore { | ||
CharacterClass.any.subtracting(.anyOf("}")) | ||
} | ||
} | ||
"}" | ||
} | ||
self.uriTemplateRegex = try! Regex(#"{([^}]+)}"#) | ||
} | ||
} | ||
} | ||
#endif | ||
|
||
// .------------------------------------------------------------------. | ||
// | NUL + . / ; ? & # | | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this annotation is needed since
URL.Template.Element
is an internal type, but otherwise LGTM!