dduan / tomldecoder Goto Github PK
View Code? Open in Web Editor NEWFrom TOML to Swift Codable types.
License: MIT License
From TOML to Swift Codable types.
License: MIT License
let toml = """
[players]
[players.'tom']
id = '33968bc5c8a95'
health = 80
joinDate = 2019-03-10 17:40:00-07:00
[players.'steve']
id = '33968bc5c8a95'
health = 80
joinDate = 2019-03-10 17:40:00-07:00
"""
struct Team: Codable {
struct Player: Codable {
let id: String
let health: Int
let joinDate: Date
}
let players: [Player]
}
let team = try! TOMLDecoder().decode(Team.self, from: toml)
print(team)
Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.valueNotFound(Swift.UnkeyedDecodingContainer, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "players", intValue: nil)], debugDescription: "Cannot get unkeyed decoding container -- found null value instead."
Hello, I tried building this to use to use it in a project building for macOS 10.15 and I got the following error.
github "dduan/TOMLDecoder"
carthage update --platform macOS
/Users/xx/src/Swift/Rust/Carthage/Checkouts/TOMLDecoder/Sources/TOMLDecoder/TOMLDecoder.swift:2:8: error: no such module 'NetTime'
import NetTime
The function normalFloat(_ input: inout Substring) does not correctly parse floats. After parsing the decimal, it calls decIntTextUTF8(_ utf8: inout Substring.UTF8View) again. This function checks to make sure the first digit is not zero. However, with the fractional component of floats this is allowed.
The result of this bug is that floats parsed that fit this condition (ex: 12.02
, -325.0021
) will return without the digits following the first 0, and those remaining digits will be left on input
causing a parsing error.
Create a separate function to be called after the decimal which does not perform this first-digit zero-check.
Unit tests won't pass on Windows with Swift 5.5.3. Possibly related to path finding logic for fixture files.
A trivial TOML file like this:
foo = 'bar'
is parsed incorrectly in release builds (but correctly in debug builds). The problem doesn’t occur with basic/double-quoted strings.
import Foundation
import TOMLDecoder
let toml = """
foo = 'bar'
"""
struct Decoded: Codable, Equatable {
let foo: String
}
let decoded = try! TOMLDecoder().decode(Decoded.self, from: toml)
switch decoded {
case Decoded(foo: "bar"):
print("Correct")
case Decoded(foo: "'bar"):
print(#"Observed error: "\#(decoded.foo)""#)
default:
print(#"Other error: "\#(decoded.foo)""#)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.