Apply formatting

This commit is contained in:
Cory Benfield committed 2020-07-17 10:06:44 +01:00
1 parent 89ef2cf73d
commit 3f73125a0d
28 files changed
+198 -184

No files matched your search

@@ -30,27 +30,27 @@ struct BareInnerListDecoder<BaseData: RandomAccessCollection> where BaseData.Ele
extension BareInnerListDecoder: UnkeyedDecodingContainer {
var codingPath: [CodingKey] {
return self.decoder.codingPath
self.decoder.codingPath
}
var count: Int? {
return self.list.count
self.list.count
}
var isAtEnd: Bool {
return self.currentOffset == self.list.count
self.currentOffset == self.list.count
}
var currentIndex: Int {
return self.currentOffset
self.currentOffset
}
mutating func decodeNil() throws -> Bool {
// We never decode nil.
return false
false
}
mutating func decode<T>(_ type: T.Type) throws -> T where T : Decodable {
mutating func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
// This is a request to decode a scalar. We decode the next entry and increment the index.
guard !self.isAtEnd else {
throw StructuredHeaderError.indexOutOfRange
@@ -77,7 +77,7 @@ extension BareInnerListDecoder: UnkeyedDecodingContainer {
}
}
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey> where NestedKey : CodingKey {
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey {
// This is a request to decode a full item. We decode the next entry and increment the index.
guard !self.isAtEnd else {
throw StructuredHeaderError.indexOutOfRange
@@ -116,5 +116,4 @@ extension BareInnerListDecoder: UnkeyedDecodingContainer {
// No inheritance here folks
throw StructuredHeaderError.invalidTypeForItem
}
}
@@ -27,59 +27,59 @@ struct BareItemDecoder<BaseData: RandomAccessCollection> where BaseData.Element
extension BareItemDecoder: SingleValueDecodingContainer {
var codingPath: [CodingKey] {
return self._codingPath as [CodingKey]
self._codingPath as [CodingKey]
}
func decode(_ type: UInt8.Type) throws -> UInt8 {
return try self._decodeFixedWidthInteger(type)
try self._decodeFixedWidthInteger(type)
}
func decode(_ type: Int8.Type) throws -> Int8 {
return try self._decodeFixedWidthInteger(type)
try self._decodeFixedWidthInteger(type)
}
func decode(_ type: UInt16.Type) throws -> UInt16 {
return try self._decodeFixedWidthInteger(type)
try self._decodeFixedWidthInteger(type)
}
func decode(_ type: Int16.Type) throws -> Int16 {
return try self._decodeFixedWidthInteger(type)
try self._decodeFixedWidthInteger(type)
}
func decode(_ type: UInt32.Type) throws -> UInt32 {
return try self._decodeFixedWidthInteger(type)
try self._decodeFixedWidthInteger(type)
}
func decode(_ type: Int32.Type) throws -> Int32 {
return try self._decodeFixedWidthInteger(type)
try self._decodeFixedWidthInteger(type)
}
func decode(_ type: UInt64.Type) throws -> UInt64 {
return try self._decodeFixedWidthInteger(type)
try self._decodeFixedWidthInteger(type)
}
func decode(_ type: Int64.Type) throws -> Int64 {
return try self._decodeFixedWidthInteger(type)
try self._decodeFixedWidthInteger(type)
}
func decode(_ type: UInt.Type) throws -> UInt {
return try self._decodeFixedWidthInteger(type)
try self._decodeFixedWidthInteger(type)
}
func decode(_ type: Int.Type) throws -> Int {
return try self._decodeFixedWidthInteger(type)
try self._decodeFixedWidthInteger(type)
}
func decode(_ type: Float.Type) throws -> Float {
return try self._decodeBinaryFloatingPoint(type)
try self._decodeBinaryFloatingPoint(type)
}
func decode(_ type: Double.Type) throws -> Double {
return try self._decodeBinaryFloatingPoint(type)
try self._decodeBinaryFloatingPoint(type)
}
func decode(_ type: String.Type) throws -> String {
switch item {
func decode(_: String.Type) throws -> String {
switch self.item {
case .string(let string):
return string
case .token(let token):
@@ -89,7 +89,7 @@ extension BareItemDecoder: SingleValueDecodingContainer {
}
}
func decode(_ type: Bool.Type) throws -> Bool {
func decode(_: Bool.Type) throws -> Bool {
guard case .bool(let bool) = self.item else {
throw StructuredHeaderError.invalidTypeForItem
}
@@ -97,7 +97,7 @@ extension BareItemDecoder: SingleValueDecodingContainer {
return bool
}
func decode(_ type: Data.Type) throws -> Data {
func decode(_: Data.Type) throws -> Data {
guard case .undecodedByteSequence(let data) = self.item else {
throw StructuredHeaderError.invalidTypeForItem
}
@@ -109,7 +109,7 @@ extension BareItemDecoder: SingleValueDecodingContainer {
return decoded
}
func decode(_ type: Decimal.Type) throws -> Decimal {
func decode(_: Decimal.Type) throws -> Decimal {
guard case .decimal(let pseudoDecimal) = self.item else {
throw StructuredHeaderError.invalidTypeForItem
}
@@ -121,7 +121,7 @@ extension BareItemDecoder: SingleValueDecodingContainer {
func decodeNil() -> Bool {
// Items are never nil.
return false
false
}
func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
@@ -163,7 +163,7 @@ extension BareItemDecoder: SingleValueDecodingContainer {
}
}
private func _decodeBinaryFloatingPoint<T: BinaryFloatingPoint>(_ type: T.Type) throws -> T {
private func _decodeBinaryFloatingPoint<T: BinaryFloatingPoint>(_: T.Type) throws -> T {
guard case .decimal(let decimal) = self.item else {
throw StructuredHeaderError.invalidTypeForItem
}
@@ -172,7 +172,7 @@ extension BareItemDecoder: SingleValueDecodingContainer {
return T(Double(decimal))
}
private func _decodeFixedWidthInteger<T: FixedWidthInteger>(_ type: T.Type) throws -> T {
private func _decodeFixedWidthInteger<T: FixedWidthInteger>(_: T.Type) throws -> T {
guard case .integer(let int) = self.item else {
throw StructuredHeaderError.invalidTypeForItem
}
@@ -27,23 +27,23 @@ struct DictionaryKeyedContainer<Key: CodingKey, BaseData: RandomAccessCollection
extension DictionaryKeyedContainer: KeyedDecodingContainerProtocol {
var codingPath: [CodingKey] {
return self.decoder.codingPath
self.decoder.codingPath
}
var allKeys: [Key] {
return self.dictionary.compactMap { Key(stringValue: $0.0) }
self.dictionary.compactMap { Key(stringValue: $0.0) }
}
func contains(_ key: Key) -> Bool {
return self.dictionary.contains(where: { $0.0 == key.stringValue })
self.dictionary.contains(where: { $0.0 == key.stringValue })
}
func decodeNil(forKey key: Key) throws -> Bool {
// We will decode nil if the key is not present.
return !self.contains(key)
!self.contains(key)
}
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T : Decodable {
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
try self.decoder.push(_StructuredHeaderCodingKey(key, keyDecodingStrategy: self.decoder.keyDecodingStrategy))
defer {
self.decoder.pop()
@@ -32,20 +32,20 @@ struct KeyedInnerListDecoder<Key: CodingKey, BaseData: RandomAccessCollection> w
extension KeyedInnerListDecoder: KeyedDecodingContainerProtocol {
var codingPath: [CodingKey] {
return self.decoder.codingPath
self.decoder.codingPath
}
var allKeys: [Key] {
return keyedInnerListDecoderSupportedKeys.compactMap { Key(stringValue: $0) }
keyedInnerListDecoderSupportedKeys.compactMap { Key(stringValue: $0) }
}
func contains(_ key: Key) -> Bool {
return keyedInnerListDecoderSupportedKeys.contains(key.stringValue)
keyedInnerListDecoderSupportedKeys.contains(key.stringValue)
}
func decodeNil(forKey key: Key) throws -> Bool {
// Keys are never nil for this type.
return false
false
}
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
@@ -32,20 +32,20 @@ struct KeyedItemDecoder<Key: CodingKey, BaseData: RandomAccessCollection> where
extension KeyedItemDecoder: KeyedDecodingContainerProtocol {
var codingPath: [CodingKey] {
return self.decoder.codingPath
self.decoder.codingPath
}
var allKeys: [Key] {
return keyedItemDecoderSupportedKeys.compactMap { Key(stringValue: $0) }
keyedItemDecoderSupportedKeys.compactMap { Key(stringValue: $0) }
}
func contains(_ key: Key) -> Bool {
return keyedItemDecoderSupportedKeys.contains(key.stringValue)
keyedItemDecoderSupportedKeys.contains(key.stringValue)
}
func decodeNil(forKey key: Key) throws -> Bool {
// Keys are never nil for this type.
return false
false
}
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
@@ -27,23 +27,23 @@ struct ParametersDecoder<Key: CodingKey, BaseData: RandomAccessCollection> where
extension ParametersDecoder: KeyedDecodingContainerProtocol {
var codingPath: [CodingKey] {
return self.decoder.codingPath
self.decoder.codingPath
}
var allKeys: [Key] {
return self.parameters.compactMap { Key(stringValue: $0.0) }
self.parameters.compactMap { Key(stringValue: $0.0) }
}
func contains(_ key: Key) -> Bool {
return self.parameters.contains(where: { $0.0 == key.stringValue })
self.parameters.contains(where: { $0.0 == key.stringValue })
}
func decodeNil(forKey key: Key) throws -> Bool {
// We will decode nil if the key is not present.
return !self.contains(key)
!self.contains(key)
}
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T : Decodable {
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
try self.decoder.push(_StructuredHeaderCodingKey(key, keyDecodingStrategy: self.decoder.keyDecodingStrategy))
defer {
self.decoder.pop()
@@ -20,7 +20,7 @@ public struct StructuredFieldDecoder {
/// A strategy that should be used to map coding keys to wire format keys.
public var keyDecodingStrategy: KeyDecodingStrategy?
public init() { }
public init() {}
}
extension StructuredFieldDecoder {
@@ -129,10 +129,10 @@ class _StructuredFieldDecoder<BaseData: RandomAccessCollection> where BaseData.E
extension _StructuredFieldDecoder: Decoder {
var codingPath: [CodingKey] {
return self._codingStack.map { $0.key as CodingKey }
self._codingStack.map { $0.key as CodingKey }
}
var userInfo: [CodingUserInfoKey : Any] {
var userInfo: [CodingUserInfoKey: Any] {
[:]
}
@@ -147,7 +147,7 @@ extension _StructuredFieldDecoder: Decoder {
self._codingStack.removeLast()
}
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> where Key : CodingKey {
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> where Key: CodingKey {
if self.currentElement == nil {
// First parse. This may be a dictionary, but depending on the keys this may also be list or item.
// We can't really detect this (Key isn't caseiterable) so we just kinda have to hope. Users can tell
@@ -321,6 +321,6 @@ extension _StructuredFieldDecoder {
/// The element at the current head of the coding stack.
private var currentElement: Element? {
return self._codingStack.last.map { $0.element }
self._codingStack.last.map { $0.element }
}
}
@@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//
import StructuredHeaders
struct _StructuredHeaderCodingKey : CodingKey {
struct _StructuredHeaderCodingKey: CodingKey {
var stringValue: String
var intValue: Int?
@@ -30,27 +30,27 @@ struct TopLevelListDecoder<BaseData: RandomAccessCollection> where BaseData.Elem
extension TopLevelListDecoder: UnkeyedDecodingContainer {
var codingPath: [CodingKey] {
return self.decoder.codingPath
self.decoder.codingPath
}
var count: Int? {
return self.list.count
self.list.count
}
var isAtEnd: Bool {
return self.currentOffset == self.list.count
self.currentOffset == self.list.count
}
var currentIndex: Int {
return self.currentOffset
self.currentOffset
}
mutating func decodeNil() throws -> Bool {
// We never decode nil.
return false
false
}
mutating func decode<T>(_ type: T.Type) throws -> T where T : Decodable {
mutating func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
// This is a request to decode a scalar. We decode the next entry and increment the index.
guard !self.isAtEnd else {
throw StructuredHeaderError.indexOutOfRange
@@ -77,7 +77,7 @@ extension TopLevelListDecoder: UnkeyedDecodingContainer {
}
}
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey> where NestedKey : CodingKey {
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey {
// This is a request to decode a full item. We decode the next entry and increment the index.
guard !self.isAtEnd else {
throw StructuredHeaderError.indexOutOfRange
@@ -116,5 +116,4 @@ extension TopLevelListDecoder: UnkeyedDecodingContainer {
// No inheritance here folks
throw StructuredHeaderError.invalidTypeForItem
}
}