Structures
The following structures are available globally.
-
Type that matches a
URL
based on evaluation of its wrappedURLMatchable
s, logically AND’d together.Usage:
See morelet url = URL(string: "https://example.com/foo")! And(Scheme.https, Host("example.com")).matches(url) //> true And(Scheme.https, Path("/foo")).matches(url) //> true And(Scheme.https, Path("/not-here")).matches(url) //> false
Declaration
Swift
public struct And : URLMatchable
-
Type that matches a
URL
based on comparison with theURL
’shost
propery.Usage:
let url = URL(string: "https://example.com")! Host("example.com").matches(url) //> true Host(".com").matches(url) //> false
See also
HostSuffix
Declaration
Swift
public struct Host : URLMatchable
-
Type that matches a
URL
based on the suffix of theURL
’shost
propery.Usage:
let url = URL(string: "https://example.com")! HostSuffix(["example", "com"]).matches(url) //> true HostSuffix(["com"]).matches(url) //> true
See also
Host
Declaration
Swift
public struct HostSuffix : URLMatchable
-
A wrapper for a
URLMatchable
that matches a URL whenever its wrapped value does not.Usage:
See morelet url = URL(string: "http://example.com")! Not(Host("example.com")).matches(url) //> false Not(Scheme.mailto).matches(url) //> true
Declaration
Swift
public struct Not : URLMatchable
-
Type that matchies a
URL
based on evaluation of its wrappedURLMatchable
s, logically OR’d together.Usage:
See morelet url = URL(string: "https://example.com/foo")! Or(Path("/foo"), Path("/bar")).matches(url) //> true Or(Scheme.http, Scheme.https).matches(url) //> true Or(Host("none.test"), Path("/foo")).matches(url) //> true Or(Scheme.http, Path("/not-here")).matches(url) //> false
Declaration
Swift
public struct Or : URLMatchable
-
Type that matches a
URL
based on comparison with theURL
’spassword
propery.Usage:
let url = URL(string: "https://user:pass@example.com")! Password("pass").matches(url) //> true
Note
RFC 1738 makes a distinction between empty (
""
) passwords and no (nil
) passwords. In the uncommon case you need to match a URL with an empty password (i.e. “http://foo:@example.com”), create aPassword
with an empty string:Password("")
. The much more common no password can be matched withPassword.missing
.See also
Declaration
Swift
public struct Password : URLMatchable
-
Type that matches a
URL
based on comparison with either theURL
’spath
orpathComponetns
propery, depending on the initializer used.Usage:
let url = URL(string: "http://example.com/foo/bar")! Path("/foo/bar").matches(url) //> true Path("/foo").matches(url) //> false
See also
PathPrefix
Declaration
Swift
public struct Path : URLMatchable
-
Type that matches a
URL
based on the prefix of theURL
’spathComponents
property.Usage:
let url = URL(string: "http://example.com/foo/bar")! PathPrefix(["/", "foo", "bar"]).matches(url) //> true PathPrefix(["/", .wildcard, "bar"]).matches(url) //> true PathPrefix(["/", "foo"]).matches(url) //> true
See also
Path
Declaration
Swift
public struct PathPrefix : URLMatchable
-
Type that matches a
URL
based on comparison with theURL
’sport
propery.Usage:
See morelet url = URL(string: "https://example.com:8080")! Port(8080).matches(url) //> true
Declaration
Swift
public struct Port : URLMatchable
-
Type that wraps a validated URL scheme, as per RFC 3986, §3.1.
The
See morevalue
property of aScheme
should be considered safe for use in contexts which require a valid scheme name, as any invalid scheme formulations would be rejected by the contructor.Declaration
Swift
public struct Scheme : Equatable
-
Type that matches a
URL
based on comparison with theURL
’suser
propery.Usage:
let url = URL(string: "https://user:pass@example.com")! User("user").matches(url) //> true
Note
RFC 1738 makes a distinction between empty (
""
) users and no (nil
) users. In the uncommon case you need to match a URL with an empty user name (i.e. “http://@example.com”), create aUser
with an empty string:User("")
. The much more common no user can be matched withUser.missing
.See also
Declaration
Swift
public struct User : URLMatchable