0001 // MediaType.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 public struct MediaType: CustomStringConvertible { 0026 public let type
MediaType.swift:62 extension MediaType: Hashable {MediaType.swift:68 public func ==(lhs: MediaType, rhs: MediaType) -> Bool {MediaType.swift:68 public func ==(lhs: MediaType, rhs: MediaType) -> Bool {MediaType.swift:72 let JSONMediaType = MediaType(type: "application/json", parameters: ["charset": "utf-8"])MediaType.swift:73 let XMLMediaType = MediaType(type: "application/xml", parameters: ["charset": "utf-8"])MediaType.swift:74 let URLEncodedFormMediaType = MediaType(type: "application/x-www-form-urlencoded"): String 0027 public let parameters
MediaType.swift:30 self.type = typeMediaType.swift:35 return "\(type);" + parameters.reduce("") { $0 + " \($1.0)=\($1.1)" }MediaType.swift:57 self.type = mediaType.lowercaseStringMediaType.swift:69 return lhs.type == rhs.typeMediaType.swift:69 return lhs.type == rhs.type: [String: String] 0028 0029 public init
MediaType.swift:31 self.parameters = parametersMediaType.swift:35 return "\(type);" + parameters.reduce("") { $0 + " \($1.0)=\($1.1)" }MediaType.swift:58 self.parameters = parameters(type: String, parameters: [String: String] = [:]) { 0030 self.type = type 0031 self.parameters = parameters 0032 } 0033 0034 public var description
MediaType.swift:72 let JSONMediaType = MediaType(type: "application/json", parameters: ["charset": "utf-8"])MediaType.swift:73 let XMLMediaType = MediaType(type: "application/xml", parameters: ["charset": "utf-8"])MediaType.swift:74 let URLEncodedFormMediaType = MediaType(type: "application/x-www-form-urlencoded"): String { 0035 return "\(type);" + parameters.reduce("") { $0 + " \($1.0)=\($1.1)" } 0036 } 0037 0038 public init(string: String) { 0039 let mediaTypeTokens = string.splitBy(";") 0040 let mediaType = mediaTypeTokens.first! 0041 var parameters: [String: String] = [:] 0042 0043 if mediaTypeTokens.count == 2 { 0044 let parametersTokens = mediaTypeTokens[1].trim().splitBy(" ") 0045 0046 for parametersToken in parametersTokens { 0047 let parameterTokens = parametersToken.splitBy("=") 0048 0049 if parameterTokens.count == 2 { 0050 let key = parameterTokens[0] 0051 let value = parameterTokens[1] 0052 parameters[key] = value 0053 } 0054 } 0055 } 0056 0057 self.type = mediaType.lowercaseString 0058 self.parameters = parameters 0059 } 0060 } 0061 0062 extension MediaType: Hashable { 0063 public var hashValue: Int { 0064 return description.hashValue 0065 } 0066 } 0067 0068 public func ==(lhs: MediaType, rhs: MediaType) -> Bool { 0069 return lhs.type == rhs.type 0070 } 0071 0072 let JSONMediaType = MediaType(type: "application/json", parameters: ["charset": "utf-8"]) 0073 let XMLMediaType = MediaType(type: "application/xml", parameters: ["charset": "utf-8"]) 0074 let URLEncodedFormMediaType = MediaType(type: "application/x-www-form-urlencoded")
MediaType.swift:64 return description.hashValue