0001 // URI.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Zewo 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 import CURIParser 0026 0027 public struct URI{ 0028 public struct UserInfo
URI.swift:65 extension URI {URI.swift:70 let string = URI.getSubstring(string, start: u.scheme_start, end: u.scheme_end)URI.swift:77 let string = URI.getSubstring(string, start: u.host_start, end: u.host_end)URI.swift:90 let string = URI.getSubstring(string, start: u.path_start, end: u.path_end)URI.swift:97 let queryString = URI.getSubstring(string, start: u.query_start, end: u.query_end)URI.swift:98 query = URI.parseQueryString(queryString)URI.swift:104 let string = URI.getSubstring(string, start: u.fragment_start, end: u.fragment_end)URI.swift:111 let userInfoString = URI.getSubstring(string, start: u.user_info_start, end: u.user_info_end)URI.swift:112 userInfo = URI.parseUserInfoString(userInfoString)URI.swift:122 @inline(__always) private static func parseUserInfoString(userInfoString: String) -> URI.UserInfo? {URI.swift:128 return URI.UserInfo(URI.swift:159 extension URI: CustomStringConvertible {URI.swift:199 extension URI: Hashable {URI.swift:205 public func ==(lhs: URI, rhs: URI) -> Bool {URI.swift:205 public func ==(lhs: URI, rhs: URI) -> Bool {URI.swift:209 public func ==(lhs: URI.UserInfo, rhs: URI.UserInfo) -> Bool {URI.swift:209 public func ==(lhs: URI.UserInfo, rhs: URI.UserInfo) -> Bool {: Hashable, CustomStringConvertible { 0029 public let username
URI.swift:47 public let userInfo: UserInfo?URI.swift:54 public init(scheme: String? = nil, userInfo: UserInfo? = nil, host: String? = nil, port: Int? = nil, path: String? = nil, query: [String: String] = [:], fragment: String? = nil) {URI.swift:122 @inline(__always) private static func parseUserInfoString(userInfoString: String) -> URI.UserInfo? {URI.swift:128 return URI.UserInfo(URI.swift:209 public func ==(lhs: URI.UserInfo, rhs: URI.UserInfo) -> Bool {URI.swift:209 public func ==(lhs: URI.UserInfo, rhs: URI.UserInfo) -> Bool {: String 0030 public let password
URI.swift:33 self.username = usernameURI.swift:42 return "\(username):\(password)": String 0031 0032 public init
URI.swift:34 self.password = passwordURI.swift:42 return "\(username):\(password)"(username: String, password: String) { 0033 self.username = username 0034 self.password = password 0035 } 0036 0037 public var hashValue
URI.swift:128 return URI.UserInfo(: Int { 0038 return description.hashValue 0039 } 0040 0041 public var description
URI.swift:210 return lhs.hashValue == rhs.hashValueURI.swift:210 return lhs.hashValue == rhs.hashValue: String { 0042 return "\(username):\(password)" 0043 } 0044 } 0045 0046 public let scheme
URI.swift:38 return description.hashValue: String? 0047 public let userInfo
URI.swift:55 self.scheme = schemeURI.swift:71 scheme = String(URLEncodedString: string)URI.swift:73 scheme = nilURI.swift:163 if let scheme = scheme {: UserInfo? 0048 public let host
URI.swift:56 self.userInfo = userInfoURI.swift:112 userInfo = URI.parseUserInfoString(userInfoString)URI.swift:114 userInfo = nilURI.swift:167 if let userInfo = userInfo {: String? 0049 public let port
URI.swift:57 self.host = hostURI.swift:78 host = String(URLEncodedString: string)URI.swift:80 host = nilURI.swift:171 if let host = host {: Int? 0050 public let path
URI.swift:58 self.port = portURI.swift:84 port = Int(u.port)URI.swift:86 port = nilURI.swift:175 if let port = port {: String? 0051 public let query
URI.swift:59 self.path = pathURI.swift:91 path = String(URLEncodedString: string)URI.swift:93 path = nilURI.swift:179 if let path = path {: [String: String] 0052 public let fragment
URI.swift:60 self.query = queryURI.swift:98 query = URI.parseQueryString(queryString)URI.swift:100 query = [:]URI.swift:183 if query.count > 0 {URI.swift:187 for (name, value) in query {: String? 0053 0054 public init(scheme: String? = nil, userInfo: UserInfo? = nil, host: String? = nil, port: Int? = nil, path: String? = nil, query: [String: String] = [:], fragment: String? = nil) { 0055 self.scheme = scheme 0056 self.userInfo = userInfo 0057 self.host = host 0058 self.port = port 0059 self.path = path 0060 self.query = query 0061 self.fragment = fragment 0062 } 0063 } 0064 0065 extension URI { 0066 public init(string: String) { 0067 let u = parse_uri(string) 0068 0069 if u.field_set & 1 != 0 { 0070 let string = URI.getSubstring(string, start: u.scheme_start, end: u.scheme_end) 0071 scheme = String(URLEncodedString: string) 0072 } else { 0073 scheme = nil 0074 } 0075 0076 if u.field_set & 2 != 0 { 0077 let string = URI.getSubstring(string, start: u.host_start, end: u.host_end) 0078 host = String(URLEncodedString: string) 0079 } else { 0080 host = nil 0081 } 0082 0083 if u.field_set & 4 != 0 { 0084 port = Int(u.port) 0085 } else { 0086 port = nil 0087 } 0088 0089 if u.field_set & 8 != 0 { 0090 let string = URI.getSubstring(string, start: u.path_start, end: u.path_end) 0091 path = String(URLEncodedString: string) 0092 } else { 0093 path = nil 0094 } 0095 0096 if u.field_set & 16 != 0 { 0097 let queryString = URI.getSubstring(string, start: u.query_start, end: u.query_end) 0098 query = URI.parseQueryString(queryString) 0099 } else { 0100 query = [:] 0101 } 0102 0103 if u.field_set & 32 != 0 { 0104 let string = URI.getSubstring(string, start: u.fragment_start, end: u.fragment_end) 0105 fragment = String(URLEncodedString: string) 0106 } else { 0107 fragment = nil 0108 } 0109 0110 if u.field_set & 64 != 0 { 0111 let userInfoString = URI.getSubstring(string, start: u.user_info_start, end: u.user_info_end) 0112 userInfo = URI.parseUserInfoString(userInfoString) 0113 } else { 0114 userInfo = nil 0115 } 0116 } 0117 0118 @inline(__always) private static func getSubstring
URI.swift:61 self.fragment = fragmentURI.swift:105 fragment = String(URLEncodedString: string)URI.swift:107 fragment = nilURI.swift:191 if let fragment = fragment {(string: String, start: UInt16, end: UInt16) -> String { 0119 return string[string.startIndex.advancedBy(Int(start)) ..< string.startIndex.advancedBy(Int(end))] 0120 } 0121 0122 @inline(__always) private static func parseUserInfoString
URI.swift:70 let string = URI.getSubstring(string, start: u.scheme_start, end: u.scheme_end)URI.swift:77 let string = URI.getSubstring(string, start: u.host_start, end: u.host_end)URI.swift:90 let string = URI.getSubstring(string, start: u.path_start, end: u.path_end)URI.swift:97 let queryString = URI.getSubstring(string, start: u.query_start, end: u.query_end)URI.swift:104 let string = URI.getSubstring(string, start: u.fragment_start, end: u.fragment_end)URI.swift:111 let userInfoString = URI.getSubstring(string, start: u.user_info_start, end: u.user_info_end)(userInfoString: String) -> URI.UserInfo? { 0123 let userInfoElements = userInfoString.splitBy(":") 0124 if userInfoElements.count == 2 { 0125 if let 0126 username = String(URLEncodedString: userInfoElements[0]), 0127 password = String(URLEncodedString: userInfoElements[1]) { 0128 return URI.UserInfo( 0129 username: username, 0130 password: password 0131 ) 0132 } 0133 } 0134 0135 return nil 0136 } 0137 0138 @inline(__always) private static func parseQueryString
URI.swift:112 userInfo = URI.parseUserInfoString(userInfoString)(queryString: String) -> [String: String] { 0139 var query: [String: String] = [:] 0140 let queryTuples = queryString.splitBy("&") 0141 for tuple in queryTuples { 0142 let queryElements = tuple.splitBy("=") 0143 if queryElements.count == 1 { 0144 if let name = String(URLEncodedString: queryElements[0]) { 0145 query[name] = "" 0146 } 0147 } else if queryElements.count == 2 { 0148 if let 0149 name = String(URLEncodedString: queryElements[0]), 0150 value = String(URLEncodedString: queryElements[1]) { 0151 query[name] = value 0152 } 0153 } 0154 } 0155 return query 0156 } 0157 } 0158 0159 extension URI: CustomStringConvertible { 0160 public var description
URI.swift:98 query = URI.parseQueryString(queryString): String { 0161 var string = "" 0162 0163 if let scheme = scheme { 0164 string += "\(scheme)://" 0165 } 0166 0167 if let userInfo = userInfo { 0168 string += "\(userInfo)@" 0169 } 0170 0171 if let host = host { 0172 string += "\(host)" 0173 } 0174 0175 if let port = port { 0176 string += ":\(port)" 0177 } 0178 0179 if let path = path { 0180 string += "\(path)" 0181 } 0182 0183 if query.count > 0 { 0184 string += "?" 0185 } 0186 0187 for (name, value) in query { 0188 string += "\(name)=\(value)" 0189 } 0190 0191 if let fragment = fragment { 0192 string += "#\(fragment)" 0193 } 0194 0195 return string 0196 } 0197 } 0198 0199 extension URI: Hashable { 0200 public var hashValue
URI.swift:201 return description.hashValue: Int { 0201 return description.hashValue 0202 } 0203 } 0204 0205 public func ==(lhs: URI, rhs: URI) -> Bool { 0206 return lhs.hashValue == rhs.hashValue 0207 } 0208 0209 public func ==(lhs: URI.UserInfo, rhs: URI.UserInfo) -> Bool { 0210 return lhs.hashValue == rhs.hashValue 0211 }
URI.swift:206 return lhs.hashValue == rhs.hashValueURI.swift:206 return lhs.hashValue == rhs.hashValue