From 4b510b7ac0bf6443153301cdc4d78fe5b0d9ca73 Mon Sep 17 00:00:00 2001 From: Ilia Sazonov Date: Thu, 27 Nov 2025 11:02:38 -0800 Subject: [PATCH] Added support for files originating from DOS/Windows with \r\n line termination --- Sources/INIParser/INIParser.swift | 2 +- Tests/INIParserTests/INIParserTests.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/INIParser/INIParser.swift b/Sources/INIParser/INIParser.swift index 9b666d6..1cbacc8 100644 --- a/Sources/INIParser/INIParser.swift +++ b/Sources/INIParser/INIParser.swift @@ -165,7 +165,7 @@ public class INIParser { /// - throws: /// Exception public init(string: String) throws { - let lines: [String] = string.split(separator: "\n").map { String($0) } + let lines: [String] = string.components(separatedBy: .newlines).compactMap{$0.isEmpty ? nil : $0} var title: String? = nil for line in lines { if let content = try parse(line: line) { diff --git a/Tests/INIParserTests/INIParserTests.swift b/Tests/INIParserTests/INIParserTests.swift index 8156b79..ac6aa46 100644 --- a/Tests/INIParserTests/INIParserTests.swift +++ b/Tests/INIParserTests/INIParserTests.swift @@ -32,8 +32,8 @@ class INIParserTests: XCTestCase { freeVar1 = 1 freeVar2 = 2; url = http://example.com/results?limit=10 - [owner] - name = Rocky + [owner]\r + name = Rocky\r organization = PerfectlySoft ; [database]