User
public struct User : URLMatchable
Type that matches a URL based on comparison with the URL’s user 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 a User with an empty string: User(""). The much more common no user can be matched with User.missing.
See also
-
A value that matches a
URLwith auserproperty ofnil.RFC 1738 (and this package) makes a distinction between empty (
"") users and no (nil) users:Note that an empty user name or password is different than no user name or password.
As such, this value only matches against no (
nil) users. In practice this is a pretty meaningless distinction because please-god-don’t-put-auth-info-in-your-URLs. But if there is occation to match an empty user, one can useUser("")to achieve that purpose.Usage:
let user = URL(string: "http://user:pass@example.com")! let emptyUser = URL(string: "http://@example.com")! let noUser = URL(string: "http://example.com")! User.missing.matches(url: user) //> false User.missing.matches(url: emptyUser) //> false User.missing.matches(url: noUser) //> trueDeclaration
Swift
public static let missing: URLMatchable -
Wraps the given string to create a new
Uservalue. It matchesURLs based on theiruserproperty.See also
Declaration
Swift
public init(_ user: String)Parameters
userThe user name to match. It will be compared for equality against
URL’suserproperty. -
Predicate that determines whether a
Usermatches a givenURL.Declaration
Swift
public func matches(url: URL) -> BoolParameters
urlThe
URLto be matched.Return Value
trueif the wrapped user name is equivalent tourl.user. Otherwise,false.
View on GitHub
Install in Dash
User Structure Reference