Repository navigation
Releases
Perfect-INIParser 5.0.0
Perfect-INIParser 5.0.0 is the Swift 6 version of the INI file parser, replacing 4.0.0. The API is the same, and INIParser is now Sendable. It fixes several cases where files were read wrongly without any error, starting with Windows (\r\n) line endings, contributed by Ilia Sazonov in #5. It's a major release because some files now parse differently; see "Breaking and behaviour changes".
.package(url: "https://github.com/PerfectlySoft/Perfect-INIParser.git", from: "5.0.0"),Requirements
- Swift 6.2 or later (
swift-tools-version: 6.2, Swift 6 language mode). - macOS 12 or later, or Linux. CI covers Swift 6.2 and 6.4 on Ubuntu 24.04 and Xcode 26.0.1 and 26.6 on macOS, in debug and release, with warnings as errors.
- No package dependencies.
Highlights
- Every line ending works.
\n,\r\nand\rall split lines, and a leading UTF-8 byte order mark is skipped (#5, #6). - Values are read as written. Spaces inside values, keys and section names are kept, and only surrounding spaces and tabs are trimmed.
[,]and=can appear in a value, and;and#inside quotes are part of it. - Swift 6.
INIParseris afinal,Sendableclass, so a parsed configuration can be shared across tasks. - Documented syntax. The README now spells out comments, sections, assignments, quotes and errors, and has a migration section.
Breaking and behaviour changes
- Spaces inside values, keys and section names are kept.
name = John SmithgaveJohnSmithin 4.0.0 and now givesJohn Smith.[My Section]was stored asMySection. Upgrade: look up keys and sections by the names written in the file. INIParserisfinaland its properties are immutable. Upgrade: subclassing it no longer compiles.- The public
Stack<T>helper is gone. It was an implementation detail. Upgrade: use an array. - Some files that used to throw now parse: lines of only spaces or tabs, and quoted values containing
;or#. Upgrade: nothing.
Fixes
Each fix below was confirmed against 4.0.0 before it was made:
- Windows and classic Mac line endings (#5, Ilia Sazonov). Swift treats
"\r\n"as a singleCharacter, sosplit(separator: "\n")never split a CRLF file. The file didn't throw. It came back silently wrong:a = 1\r\n[s]\r\nb = 2gave one variableawith the value"1\r\ns\r\nb=2\r\n", and sectionswas lost. A lone\rdid the same. - Inner spaces were deleted in unquoted values, keys and section names.
[and]in values were dropped:list = [1,2]gave1,2.;or#inside quotes made the parser drop the whole line silently (password = "a;b#c"), or throwInvalidSyntax(greeting = 'it''s; fine').- A line of only spaces or tabs threw
InvalidSyntax. - A byte order mark at the start of text passed as a
Stringbecame part of the first key.
Tests
The tests moved from XCTest to Swift Testing, 16 in all: the original file, Data and String tests, and one test per fix and per error case. 9 of them fail on 4.0.0, and 5 on 4.0.0 plus #5 alone. The test fixture is now a uniquely named temporary file instead of /tmp/a.ini.
Verified: CI passed all 16 checks on #6 and all 8 jobs on main (115d2f8). Locally, swift test passed in debug and release with warnings as errors on macOS, and on Linux with swift:6.2-noble and swift:6.4-noble. A scratch consumer built the README example and got the values it shows.
Known limitations
- Quoted values keep their quote marks (
"a b"comes back with the quotes), as in 4.0.0. - No escape sequences (
\n,\"), no line continuations and no variable interpolation. - Sections with no variables don't appear in
sections. - Errors don't say which line is at fault.
- Writing INI files isn't supported.
Pull requests
Legacy
The pre-Swift-6 code (4.0.0) is on the legacy branch. Stay on 4.x if you can't move to Swift 6.2.
Swift version upgrade & more constructors
Thanks NocturnalSolutions and swift-aws for these great contributions.
Rewriting everything; Adding support for quotations.
3.0.0 Rewriting everything.
Fix Swift 4.0 compatibility issue.
1.0.2 Fix Swift 4.0 compatibility issue.
Fixing decommentation
1.0.1 Fixing decommentation