Skip to content

Perfect-INIParser 5.0.0

Latest

Choose a tag to compare

@taplin taplin released this 26 Oct 15:00
115d2f8

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\n and \r all 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. INIParser is a final, Sendable class, 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 Smith gave JohnSmith in 4.0.0 and now gives John Smith. [My Section] was stored as MySection. Upgrade: look up keys and sections by the names written in the file.
  • INIParser is final and 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 single Character, so split(separator: "\n") never split a CRLF file. The file didn't throw. It came back silently wrong: a = 1\r\n[s]\r\nb = 2 gave one variable a with the value "1\r\ns\r\nb=2\r\n", and section s was lost. A lone \r did the same.
  • Inner spaces were deleted in unquoted values, keys and section names.
  • [ and ] in values were dropped: list = [1,2] gave 1,2.
  • ; or # inside quotes made the parser drop the whole line silently (password = "a;b#c"), or throw InvalidSyntax (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 String became 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

  • #5: DOS/Windows \r\n line endings (Ilia Sazonov).
  • #6: Swift 6 modernization, including #5.

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.