From cc5fea4547121298fa8e69cf4ddb30fd2023dea1 Mon Sep 17 00:00:00 2001 From: RockfordWei Date: Tue, 16 Jan 2018 13:50:34 -0500 Subject: [PATCH] Improving blanks and trimming. --- README.md | 4 ++-- Sources/PerfectINI/PerfectINI.swift | 9 +++------ Tests/PerfectINITests/PerfectINITests.swift | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4c9b722..b915785 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ struct Configuration: Codable { let rocky = Person(name: "rocky", age: 21) let hongkong = Place(location: "china", history: 1000) -let conf = Configuration(id: 101, tag: "mynotes", person: rocky, place: hongkong) +let conf = Configuration(id: 101, tag: "my notes", person: rocky, place: hongkong) let encoder = INIEncoder() let data = try encoder.encode(conf) ``` @@ -79,7 +79,7 @@ The outcome of encoder is a standard Swift `Data` object, and the content should ``` ini id = 101 -tag = mynotes +tag = my notes [person] name = rocky diff --git a/Sources/PerfectINI/PerfectINI.swift b/Sources/PerfectINI/PerfectINI.swift index 2d76159..1479733 100644 --- a/Sources/PerfectINI/PerfectINI.swift +++ b/Sources/PerfectINI/PerfectINI.swift @@ -201,11 +201,6 @@ fileprivate class INIParser { var variable: String? = nil for c in line { switch c { - case " ", "\t": - if state == .singleQuotation || state == .doubleQuotation { - cache.append(c) - } - break case "[": if state == .variable { cache = "" @@ -268,7 +263,9 @@ fileprivate class INIParser { guard state == .value, let v = variable else { throw INICodingError.unsupported } - return ContentType.assignment(v, cache) + return ContentType.assignment( + v.trimmingCharacters(in: [" ", "\t", "\n", "\r"]), + cache.trimmingCharacters(in: [" ", "\t", "\n", "\r"])) } public init(_ data: Data) throws { diff --git a/Tests/PerfectINITests/PerfectINITests.swift b/Tests/PerfectINITests/PerfectINITests.swift index 17958c4..f14b430 100644 --- a/Tests/PerfectINITests/PerfectINITests.swift +++ b/Tests/PerfectINITests/PerfectINITests.swift @@ -35,7 +35,7 @@ class PerfectINITests: XCTestCase { let rocky = Person(name: "rocky", age: 21) let hongkong = Place(location: "china", history: 1000) - let conf = Configuration(id: 101, tag: "mynotes", person: rocky, place: hongkong) + let conf = Configuration(id: 101, tag: "my notes", person: rocky, place: hongkong) let encoder = INIEncoder() do { let data = try encoder.encode(conf)