Swiftpack.co - Ponyboy47/ConfigParser as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Ponyboy47.
Ponyboy47/ConfigParser 0.4.0
A pure-Swift INI Config parser
⭐️ 5
🕓 4 years ago
.package(url: "https://github.com/Ponyboy47/ConfigParser.git", from: "0.4.0")

ConfigParser

A pure-Swift implementation of the INI config parser

Installation

Swift Package Manager

.package(url: "https://github.com/Ponyboy47/ConfigParser.git", from: "0.4.0")

Usage

import ConfigParser

let confString = """
[section1]
key1 = value1
key2 = 1, 2, 3, 4

[section2]
key1 = test
key2 = 1234
"""

let config = try ConfigParser.parse(confString)

// Use subscripts to get the value you want in the type you want
let key1s1: String? = config[section: "section1", key: "key1"] // Optional<String>(value1)
let key2s1 = config[section: "section2", key: "key1", default: [4, 3, 2, 1]] // [1, 2, 3, 4]

Supported Types:

  • String
  • Bool
  • Int (8,16,32,64 and all the UInt variants)
  • Double
  • Float and Float80
  • Arrays of any of the above types

TODO

  • ☐ Section/Key name validation (must start with an alphabet character)
  • ☑ Retrieve values as specified type
    • ☑ Bool
    • ☑ String (default)
    • ☑ Double/Float
    • ☑ Int
    • ☑ Array
  • ☑ Write config to file
  • ☐ Escape sequences (bug fix)
  • ☐ Multi-line values
  • ☑ Read from string
  • ☐ Customizable options
    • ☐ Delimeter (ie: ':' instead of '=')
    • ☐ Don't trim whitespace
    • ☐ Nested sections
      • ☐ Dotted section titles
      • ☐ Indented sections
    • ☐ Duplicate key behavior
      • ☐ Keep first
      • ☐ Overwrite
      • ☐ Error

License

MIT

GitHub

link
Stars: 5
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics