Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

updating URI model #45

Merged
merged 1 commit into from
Jun 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions Sources/URI.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
/*
https://tools.ietf.org/html/rfc3986#section-1

3. Syntax Components

The generic URI syntax consists of a hierarchical sequence of
components referred to as the scheme, authority, path, query, and
fragment.

URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

hier-part = "//" authority path-abempty
/ path-absolute
/ path-rootless
/ path-empty

The scheme and path components are required, though the path may be
empty (no characters). When authority is present, the path must
either be empty or begin with a slash ("/") character. When
authority is not present, the path cannot begin with two slash
characters ("//"). These restrictions result in five different ABNF
rules for a path (Section 3.3), only one of which will match any
given URI reference.

The following are two example URIs and their component parts:

foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
| _____________________|__
/ \ / \
urn:example:animal:ferret:nose
*/
public struct URI {
public struct UserInfo {
public var username: String
Expand All @@ -14,10 +48,16 @@ public struct URI {
public var host: String?
public var port: Int?
public var path: String?
public var query: [String: [String?]]
public var query: String?
public var fragment: String?

public init(scheme: String? = nil, userInfo: UserInfo? = nil, host: String? = nil, port: Int? = nil, path: String? = nil, query: [String: [String?]] = [:], fragment: String? = nil) {
public init(scheme: String? = nil,
userInfo: UserInfo? = nil,
host: String? = nil,
port: Int? = nil,
path: String? = nil,
query: String? = nil,
fragment: String? = nil) {
self.scheme = scheme
self.userInfo = userInfo
self.host = host
Expand Down