Skip to content

Commit

Permalink
Improving blanks and trimming.
Browse files Browse the repository at this point in the history
  • Loading branch information
RockfordWei committed Jan 16, 2018
1 parent 7dcb863 commit cc5fea4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -71,15 +71,15 @@ 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)
```
The outcome of encoder is a standard Swift `Data` object, and the content should be like this:

``` ini
id = 101
tag = mynotes
tag = my notes

[person]
name = rocky
Expand Down
9 changes: 3 additions & 6 deletions Sources/PerfectINI/PerfectINI.swift
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Tests/PerfectINITests/PerfectINITests.swift
Expand Up @@ -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)
Expand Down

0 comments on commit cc5fea4

Please sign in to comment.