Skip to content

Commit

Permalink
style: 去除命名前缀下划线
Browse files Browse the repository at this point in the history
  • Loading branch information
Pircate committed May 27, 2019
1 parent 53fbbd1 commit 7f850a4
Show file tree
Hide file tree
Showing 16 changed files with 286 additions and 280 deletions.
6 changes: 3 additions & 3 deletions CleanJSON/Classes/CleanJSONDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
open class CleanJSONDecoder: JSONDecoder {

/// Options set on the top-level encoder to pass down the decoding hierarchy.
struct _Options {
struct Options {
let dateDecodingStrategy: DateDecodingStrategy
let dataDecodingStrategy: DataDecodingStrategy
let nonConformingFloatDecodingStrategy: NonConformingFloatDecodingStrategy
Expand All @@ -24,8 +24,8 @@ open class CleanJSONDecoder: JSONDecoder {
}

/// The options set on the top-level decoder.
var options: _Options {
return _Options(dateDecodingStrategy: dateDecodingStrategy,
var options: Options {
return Options(dateDecodingStrategy: dateDecodingStrategy,
dataDecodingStrategy: dataDecodingStrategy,
nonConformingFloatDecodingStrategy: nonConformingFloatDecodingStrategy,
keyDecodingStrategy: keyDecodingStrategy,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// _CleanJSONDecodingStorage.swift
// CleanJSONDecodingStorage.swift
// CleanJSON
//
// Created by Pircate([email protected]) on 2018/10/10
Expand All @@ -8,7 +8,7 @@

import Foundation

struct _CleanJSONDecodingStorage {
struct CleanJSONDecodingStorage {

/// The container stack.
/// Elements may be any one of the JSON types (NSNull, NSNumber, String, Array, [String : Any]).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// _CleanJSONKey.swift
// CleanJSONKey.swift
// CleanJSON
//
// Created by Pircate([email protected]) on 2018/10/11
Expand All @@ -8,7 +8,7 @@

import Foundation

struct _CleanJSONKey : CodingKey {
struct CleanJSONKey : CodingKey {

public var stringValue: String

Expand All @@ -34,5 +34,5 @@ struct _CleanJSONKey : CodingKey {
self.intValue = index
}

static let `super` = _CleanJSONKey(stringValue: "super")!
static let `super` = CleanJSONKey(stringValue: "super")!
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// _CleanJSONKeyedDecodingContainer.swift
// CleanJSONKeyedDecodingContainer.swift
// CleanJSON
//
// Created by Pircate([email protected]) on 2018/10/10
Expand All @@ -8,7 +8,7 @@

import Foundation

struct _CleanJSONKeyedDecodingContainer<K : CodingKey>: KeyedDecodingContainerProtocol {
struct CleanJSONKeyedDecodingContainer<K : CodingKey>: KeyedDecodingContainerProtocol {

typealias Key = K

Expand Down Expand Up @@ -39,7 +39,7 @@ struct _CleanJSONKeyedDecodingContainer<K : CodingKey>: KeyedDecodingContainerPr
}, uniquingKeysWith: { (first, _) in first })
case .custom(let converter):
self.container = Dictionary(container.map {
key, value in (converter(decoder.codingPath + [_CleanJSONKey(stringValue: key, intValue: nil)]).stringValue, value)
key, value in (converter(decoder.codingPath + [CleanJSONKey(stringValue: key, intValue: nil)]).stringValue, value)
}, uniquingKeysWith: { (first, _) in first })
@unknown default:
self.container = container
Expand Down Expand Up @@ -486,7 +486,7 @@ struct _CleanJSONKeyedDecodingContainer<K : CodingKey>: KeyedDecodingContainerPr

private func nestedContainer<NestedKey>(wrapping dictionary: [String: Any] = [:])
-> KeyedDecodingContainer<NestedKey> {
let container = _CleanJSONKeyedDecodingContainer<NestedKey>(
let container = CleanJSONKeyedDecodingContainer<NestedKey>(
referencing: decoder,
wrapping: dictionary)
return KeyedDecodingContainer(container)
Expand All @@ -501,7 +501,7 @@ struct _CleanJSONKeyedDecodingContainer<K : CodingKey>: KeyedDecodingContainerPr
case .throw:
throw DecodingError.Nested.keyNotFound(key, codingPath: codingPath, isUnkeyed: true)
case .useEmptyContainer:
return _CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: [])
return CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: [])
}
}

Expand All @@ -512,11 +512,11 @@ struct _CleanJSONKeyedDecodingContainer<K : CodingKey>: KeyedDecodingContainerPr
at: self.codingPath,
expectation: [Any].self, reality: value)
case .useEmptyContainer:
return _CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: [])
return CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: [])
}
}

return _CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: array)
return CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: array)
}

private func _superDecoder(forKey key: CodingKey) throws -> Decoder {
Expand All @@ -528,7 +528,7 @@ struct _CleanJSONKeyedDecodingContainer<K : CodingKey>: KeyedDecodingContainerPr
}

public func superDecoder() throws -> Decoder {
return try _superDecoder(forKey: _CleanJSONKey.super)
return try _superDecoder(forKey: CleanJSONKey.super)
}

public func superDecoder(forKey key: Key) throws -> Decoder {
Expand Down Expand Up @@ -584,7 +584,7 @@ private extension CleanJSONDecoder.KeyDecodingStrategy {
}
}

private extension _CleanJSONKeyedDecodingContainer {
private extension CleanJSONKeyedDecodingContainer {

func decodeIfKeyNotFound<T>(_ key: Key) throws -> T where T: Decodable, T: Defaultable {
switch decoder.options.keyNotFoundDecodingStrategy {
Expand Down Expand Up @@ -630,7 +630,7 @@ extension _CleanJSONDecoder {
}
}

extension _CleanJSONKeyedDecodingContainer {
extension CleanJSONKeyedDecodingContainer {

func decodeIfPresent(_ type: Bool.Type, forKey key: K) throws -> Bool? {
guard contains(key), let entry = container[key.stringValue] else { return nil }
Expand Down Expand Up @@ -859,7 +859,7 @@ extension _CleanJSONKeyedDecodingContainer {
}
}

private extension _CleanJSONKeyedDecodingContainer {
private extension CleanJSONKeyedDecodingContainer {

func decodeIfPresent(_ value: Any, as type: Date.Type, forKey key: K) throws -> Date? {
if let date = try decoder.unbox(value, as: type) { return date }
Expand Down Expand Up @@ -916,7 +916,7 @@ private extension _CleanJSONKeyedDecodingContainer {

private extension String {

func decode<T: Decodable>(to type: T.Type, options: CleanJSONDecoder._Options) -> T? {
func decode<T: Decodable>(to type: T.Type, options: CleanJSONDecoder.Options) -> T? {
guard hasPrefix("{") || hasPrefix("[") else { return nil }

guard let data = data(using: .utf8),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// _CleanJSONUnkeyedDecodingContainer.swift
// CleanJSONUnkeyedDecodingContainer.swift
// CleanJSON
//
// Created by Pircate([email protected]) on 2018/10/11
Expand All @@ -8,7 +8,7 @@

import Foundation

struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
struct CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
// MARK: Properties

/// A reference to the decoder we're reading from.
Expand Down Expand Up @@ -45,7 +45,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {

public mutating func decodeNil() throws -> Bool {
guard !self.isAtEnd else {
throw DecodingError.valueNotFound(Any?.self, DecodingError.Context(codingPath: self.decoder.codingPath + [_CleanJSONKey(index: self.currentIndex)], debugDescription: "Unkeyed container is at end."))
throw DecodingError.valueNotFound(Any?.self, DecodingError.Context(codingPath: self.decoder.codingPath + [CleanJSONKey(index: self.currentIndex)], debugDescription: "Unkeyed container is at end."))
}

if self.container[self.currentIndex] is NSNull {
Expand All @@ -61,7 +61,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return try decode(isAtEnd: true)
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: Bool.self) else {
Expand Down Expand Up @@ -94,7 +94,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return try decode(isAtEnd: true)
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: Int.self) else {
Expand Down Expand Up @@ -127,7 +127,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return Int8.defaultValue
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: Int8.self) else {
Expand All @@ -143,7 +143,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return Int16.defaultValue
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: Int16.self) else {
Expand All @@ -159,7 +159,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return Int32.defaultValue
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: Int32.self) else {
Expand All @@ -175,7 +175,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return Int64.defaultValue
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: Int64.self) else {
Expand All @@ -191,7 +191,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return try decode(isAtEnd: true)
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: UInt.self) else {
Expand Down Expand Up @@ -224,7 +224,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return UInt8.defaultValue
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: UInt8.self) else {
Expand All @@ -240,7 +240,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return UInt16.defaultValue
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: UInt16.self) else {
Expand All @@ -256,7 +256,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return UInt32.defaultValue
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: UInt32.self) else {
Expand All @@ -272,7 +272,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return UInt64.defaultValue
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: UInt64.self) else {
Expand All @@ -288,7 +288,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return try decode(isAtEnd: true)
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: Float.self) else {
Expand Down Expand Up @@ -321,7 +321,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return try decode(isAtEnd: true)
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: Double.self) else {
Expand Down Expand Up @@ -354,7 +354,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
return try decode(isAtEnd: true)
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: String.self) else {
Expand Down Expand Up @@ -384,22 +384,22 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {

public mutating func decode<T : Decodable>(_ type: T.Type) throws -> T {
guard !self.isAtEnd else {
throw DecodingError.valueNotFound(type, DecodingError.Context(codingPath: self.decoder.codingPath + [_CleanJSONKey(index: self.currentIndex)], debugDescription: "Unkeyed container is at end."))
throw DecodingError.valueNotFound(type, DecodingError.Context(codingPath: self.decoder.codingPath + [CleanJSONKey(index: self.currentIndex)], debugDescription: "Unkeyed container is at end."))
}

self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: type) else {
throw DecodingError.valueNotFound(type, DecodingError.Context(codingPath: self.decoder.codingPath + [_CleanJSONKey(index: self.currentIndex)], debugDescription: "Expected \(type) but found null instead."))
throw DecodingError.valueNotFound(type, DecodingError.Context(codingPath: self.decoder.codingPath + [CleanJSONKey(index: self.currentIndex)], debugDescription: "Expected \(type) but found null instead."))
}

self.currentIndex += 1
return decoded
}

public mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey> {
self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard !self.isAtEnd else {
Expand Down Expand Up @@ -437,12 +437,12 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
}

private func nestedContainer<NestedKey>(wrapping dictionary: [String: Any] = [:]) -> KeyedDecodingContainer<NestedKey> {
let container = _CleanJSONKeyedDecodingContainer<NestedKey>(referencing: self.decoder, wrapping: dictionary)
let container = CleanJSONKeyedDecodingContainer<NestedKey>(referencing: self.decoder, wrapping: dictionary)
return KeyedDecodingContainer(container)
}

public mutating func nestedUnkeyedContainer() throws -> UnkeyedDecodingContainer {
self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard !self.isAtEnd else {
Expand All @@ -461,7 +461,7 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
debugDescription: "Cannot get keyed decoding container -- found null value instead.")
case .useEmptyContainer:
self.currentIndex += 1
return _CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: [])
return CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: [])
}
}

Expand All @@ -471,16 +471,16 @@ struct _CleanJSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: [Any].self, reality: value)
case .useEmptyContainer:
self.currentIndex += 1
return _CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: [])
return CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: [])
}
}

self.currentIndex += 1
return _CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: array)
return CleanJSONUnkeyedDecodingContainer(referencing: self.decoder, wrapping: array)
}

public mutating func superDecoder() throws -> Decoder {
self.decoder.codingPath.append(_CleanJSONKey(index: self.currentIndex))
self.decoder.codingPath.append(CleanJSONKey(index: self.currentIndex))
defer { self.decoder.codingPath.removeLast() }

guard !self.isAtEnd else {
Expand Down
2 changes: 1 addition & 1 deletion CleanJSON/Classes/DecodingError+CleanJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extension DecodingError {
return DecodingError.valueNotFound(
type,
DecodingError.Context(
codingPath: codingPath + [_CleanJSONKey(index: currentIndex)],
codingPath: codingPath + [CleanJSONKey(index: currentIndex)],
debugDescription: debugDescription))
}
}
Expand Down
Loading

0 comments on commit 7f850a4

Please sign in to comment.