Giter Site home page Giter Site logo

tomldecoder's Introduction

TOMLDecoder

Amazon Linux 2
CentOS 7
macOS
Ubuntu Bionic
Ubuntu Focal
Windows

TOML parser for your Swift Codables.

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: tomlData)

TOMLDecoder has a relatively simple set of APIs. Learn more in the introduction.

Installation

With SwiftPM

.package(url: "https://github.com/dduan/TOMLDecoder", from: "0.2.2")

License

MIT. See LICENSE.md.

tomldecoder's People

Contributors

dduan avatar giginet avatar guseducampos avatar solidsilver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tomldecoder's Issues

How do subtables work?

       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."

In release builds, literal strings incorrectly include opening `'`

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)""#)
}

Float parsing skips frac parsing if 0 is first digit after decimal

Issue

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.

Suggested solution:

Create a separate function to be called after the decimal which does not perform this first-digit zero-check.

Error building with carthage: No such import as NetTime

Hello, I tried building this to use to use it in a project building for macOS 10.15 and I got the following error.

Cartfile

github "dduan/TOMLDecoder"

Output

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

Tests fail on Windows

Unit tests won't pass on Windows with Swift 5.5.3. Possibly related to path finding logic for fixture files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.